Refactor payment method interface to remove payment status dispatcher (https://github.com/woocommerce/woocommerce-blocks/pull/2116)
* don’t expose payment method status dispatcher on payment method interface * update apple-pay-express to use new currentPaymetnStatus object shape
This commit is contained in:
parent
d637c28d62
commit
4baa99cf65
|
@ -93,7 +93,6 @@ export const usePaymentMethodInterface = () => {
|
||||||
onSubmit,
|
onSubmit,
|
||||||
} = useCheckoutContext();
|
} = useCheckoutContext();
|
||||||
const {
|
const {
|
||||||
setPaymentStatus,
|
|
||||||
currentStatus,
|
currentStatus,
|
||||||
activePaymentMethod,
|
activePaymentMethod,
|
||||||
setActivePaymentMethod,
|
setActivePaymentMethod,
|
||||||
|
@ -147,10 +146,7 @@ export const usePaymentMethodInterface = () => {
|
||||||
isIdle,
|
isIdle,
|
||||||
isProcessing,
|
isProcessing,
|
||||||
},
|
},
|
||||||
paymentStatus: {
|
paymentStatus: currentStatus,
|
||||||
currentStatus,
|
|
||||||
setPaymentStatus,
|
|
||||||
},
|
|
||||||
shippingStatus: {
|
shippingStatus: {
|
||||||
shippingErrorStatus,
|
shippingErrorStatus,
|
||||||
shippingErrorTypes,
|
shippingErrorTypes,
|
||||||
|
|
|
@ -116,10 +116,7 @@ const ApplePayExpressComponent = ( {
|
||||||
}
|
}
|
||||||
// otherwise we just update it (but only if payment processing hasn't
|
// otherwise we just update it (but only if payment processing hasn't
|
||||||
// already started).
|
// already started).
|
||||||
if (
|
if ( ! paymentStatus.isPristine && currentPaymentRequest.current ) {
|
||||||
! paymentStatus.currentStatus.isPristine &&
|
|
||||||
currentPaymentRequest.current
|
|
||||||
) {
|
|
||||||
updatePaymentRequest( {
|
updatePaymentRequest( {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
paymentRequest: currentPaymentRequest.current,
|
paymentRequest: currentPaymentRequest.current,
|
||||||
|
@ -134,7 +131,7 @@ const ApplePayExpressComponent = ( {
|
||||||
shippingData.shippingAddress.country,
|
shippingData.shippingAddress.country,
|
||||||
shippingData.needsShipping,
|
shippingData.needsShipping,
|
||||||
billing.cartTotalItems,
|
billing.cartTotalItems,
|
||||||
paymentStatus.currentStatus.isPristine,
|
paymentStatus.isPristine,
|
||||||
stripe,
|
stripe,
|
||||||
] );
|
] );
|
||||||
|
|
||||||
|
@ -185,7 +182,7 @@ const ApplePayExpressComponent = ( {
|
||||||
const handlers = eventHandlers.current;
|
const handlers = eventHandlers.current;
|
||||||
if (
|
if (
|
||||||
typeof handlers.shippingAddressChange === 'function' &&
|
typeof handlers.shippingAddressChange === 'function' &&
|
||||||
currentPaymentStatus.current.currentStatus.isProcessing
|
currentPaymentStatus.current.isProcessing
|
||||||
) {
|
) {
|
||||||
handlers.shippingAddressChange.updateWith( {
|
handlers.shippingAddressChange.updateWith( {
|
||||||
status: forSuccess ? 'success' : 'fail',
|
status: forSuccess ? 'success' : 'fail',
|
||||||
|
@ -204,7 +201,7 @@ const ApplePayExpressComponent = ( {
|
||||||
const handlers = eventHandlers.current;
|
const handlers = eventHandlers.current;
|
||||||
if (
|
if (
|
||||||
typeof handlers.shippingOptionsChange === 'function' &&
|
typeof handlers.shippingOptionsChange === 'function' &&
|
||||||
currentPaymentStatus.current.currentStatus.isProcessing
|
currentPaymentStatus.current.isProcessing
|
||||||
) {
|
) {
|
||||||
const updateObject = forSuccess
|
const updateObject = forSuccess
|
||||||
? {
|
? {
|
||||||
|
@ -227,7 +224,7 @@ const ApplePayExpressComponent = ( {
|
||||||
const handlers = eventHandlers.current;
|
const handlers = eventHandlers.current;
|
||||||
if (
|
if (
|
||||||
typeof handlers.sourceEvent === 'function' &&
|
typeof handlers.sourceEvent === 'function' &&
|
||||||
currentPaymentStatus.current.currentStatus.isSuccessful
|
currentPaymentStatus.current.isSuccessful
|
||||||
) {
|
) {
|
||||||
if ( forSuccess ) {
|
if ( forSuccess ) {
|
||||||
completePayment( handlers.sourceEvent );
|
completePayment( handlers.sourceEvent );
|
||||||
|
|
|
@ -73,19 +73,6 @@
|
||||||
* (finalizing) the order with the server.
|
* (finalizing) the order with the server.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef PaymentStatusProps
|
|
||||||
*
|
|
||||||
* @property {PaymentMethodCurrentStatus} currentStatus Various status state
|
|
||||||
* indicators for the
|
|
||||||
* payment method based
|
|
||||||
* on it's current
|
|
||||||
* status.
|
|
||||||
* @property {PaymentStatusDispatch} setPaymentStatus Used to dispatch
|
|
||||||
* various payment
|
|
||||||
* status updates.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef ShippingStatusProps
|
* @typedef ShippingStatusProps
|
||||||
*
|
*
|
||||||
|
@ -196,7 +183,7 @@
|
||||||
*
|
*
|
||||||
* @property {CheckoutStatusProps} checkoutStatus The current checkout status exposed
|
* @property {CheckoutStatusProps} checkoutStatus The current checkout status exposed
|
||||||
* as various boolean state.
|
* as various boolean state.
|
||||||
* @property {PaymentStatusProps} paymentStatus Various payment status helpers.
|
* @property {PaymentMethodCurrentStatus} paymentStatus Various payment status helpers.
|
||||||
* @property {ShippingStatusProps} shippingStatus Various shipping status helpers.
|
* @property {ShippingStatusProps} shippingStatus Various shipping status helpers.
|
||||||
* @property {ShippingDataProps} shippingData Various data related to shipping.
|
* @property {ShippingDataProps} shippingData Various data related to shipping.
|
||||||
* @property {BillingDataProps} billing Various billing data items.
|
* @property {BillingDataProps} billing Various billing data items.
|
||||||
|
|
Loading…
Reference in New Issue