mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 14:57:26 +08:00
Merge pull request #2603 from woocommerce/PCP-3649-fastlane-backend-logic-changes
Fix Gary-flow in PCP-3380 branch (3649)
This commit is contained in:
commit
47d5874e62
4 changed files with 21 additions and 41 deletions
|
@ -17,9 +17,15 @@ const useHandlePaymentSetup = (
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! cardToken ) {
|
if ( ! cardToken ) {
|
||||||
|
let reason = 'tokenization error';
|
||||||
|
|
||||||
|
if ( ! paymentComponent ) {
|
||||||
|
reason = 'initialization error';
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: emitResponse.responseTypes.ERROR,
|
type: emitResponse.responseTypes.ERROR,
|
||||||
message: 'Could not process the payment (tokenization error)',
|
message: `Could not process the payment (${ reason })`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,11 +38,7 @@ const useHandlePaymentSetup = (
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}, [
|
}, [ card, paymentComponent, tokenizedCustomerData ] );
|
||||||
card,
|
|
||||||
paymentComponent,
|
|
||||||
tokenizedCustomerData,
|
|
||||||
] );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default useHandlePaymentSetup;
|
export default useHandlePaymentSetup;
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
import { useEffect } from '@wordpress/element';
|
|
||||||
|
|
||||||
const usePaymentSetup = ( onPaymentSetup, emitResponse, card ) => {
|
|
||||||
useEffect( () => {
|
|
||||||
const unsubscribe = onPaymentSetup( async () => {
|
|
||||||
return {
|
|
||||||
type: emitResponse.responseTypes.SUCCESS,
|
|
||||||
meta: {
|
|
||||||
paymentMethodData: {
|
|
||||||
axo_nonce: card?.id,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
} );
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
unsubscribe();
|
|
||||||
};
|
|
||||||
}, [
|
|
||||||
emitResponse.responseTypes.ERROR,
|
|
||||||
emitResponse.responseTypes.SUCCESS,
|
|
||||||
onPaymentSetup,
|
|
||||||
card,
|
|
||||||
] );
|
|
||||||
};
|
|
||||||
|
|
||||||
export default usePaymentSetup;
|
|
|
@ -1,6 +1,10 @@
|
||||||
import { useEffect, useCallback } from '@wordpress/element';
|
import { useEffect, useCallback } from '@wordpress/element';
|
||||||
|
|
||||||
const usePaymentSetupEffect = ( onPaymentSetup, handlePaymentSetup ) => {
|
const usePaymentSetupEffect = (
|
||||||
|
onPaymentSetup,
|
||||||
|
handlePaymentSetup,
|
||||||
|
setPaymentComponent
|
||||||
|
) => {
|
||||||
/**
|
/**
|
||||||
* `onPaymentSetup()` fires when we enter the "PROCESSING" state in the checkout flow.
|
* `onPaymentSetup()` fires when we enter the "PROCESSING" state in the checkout flow.
|
||||||
* It pre-processes the payment details and returns data for server-side processing.
|
* It pre-processes the payment details and returns data for server-side processing.
|
||||||
|
@ -13,10 +17,12 @@ const usePaymentSetupEffect = ( onPaymentSetup, handlePaymentSetup ) => {
|
||||||
};
|
};
|
||||||
}, [ onPaymentSetup, handlePaymentSetup ] );
|
}, [ onPaymentSetup, handlePaymentSetup ] );
|
||||||
|
|
||||||
const handlePaymentLoad = useCallback( ( component ) => {
|
const handlePaymentLoad = useCallback(
|
||||||
// We'll return this function instead of calling setPaymentComponent directly
|
( component ) => {
|
||||||
return component;
|
setPaymentComponent( component );
|
||||||
}, [] );
|
},
|
||||||
|
[ setPaymentComponent ]
|
||||||
|
);
|
||||||
|
|
||||||
return { handlePaymentLoad };
|
return { handlePaymentLoad };
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,6 @@ import useFastlaneSdk from './hooks/useFastlaneSdk';
|
||||||
import useTokenizeCustomerData from './hooks/useTokenizeCustomerData';
|
import useTokenizeCustomerData from './hooks/useTokenizeCustomerData';
|
||||||
import useCardChange from './hooks/useCardChange';
|
import useCardChange from './hooks/useCardChange';
|
||||||
import useAxoSetup from './hooks/useAxoSetup';
|
import useAxoSetup from './hooks/useAxoSetup';
|
||||||
import usePaymentSetup from './hooks/usePaymentSetup';
|
|
||||||
import useAxoCleanup from './hooks/useAxoCleanup';
|
import useAxoCleanup from './hooks/useAxoCleanup';
|
||||||
import useHandlePaymentSetup from './hooks/useHandlePaymentSetup';
|
import useHandlePaymentSetup from './hooks/useHandlePaymentSetup';
|
||||||
|
|
||||||
|
@ -47,11 +46,11 @@ const Axo = ( props ) => {
|
||||||
setShippingAddress,
|
setShippingAddress,
|
||||||
setCard
|
setCard
|
||||||
);
|
);
|
||||||
usePaymentSetup( onPaymentSetup, emitResponse, card );
|
|
||||||
|
|
||||||
const { handlePaymentLoad } = usePaymentSetupEffect(
|
const { handlePaymentLoad } = usePaymentSetupEffect(
|
||||||
onPaymentSetup,
|
onPaymentSetup,
|
||||||
handlePaymentSetup
|
handlePaymentSetup,
|
||||||
|
setPaymentComponent
|
||||||
);
|
);
|
||||||
|
|
||||||
useAxoCleanup();
|
useAxoCleanup();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue