mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 10:55:00 +08:00
Merge branch 'PCP-3649-fastlane-backend-logic-for-blocks' of github.com:woocommerce/woocommerce-paypal-payments into PCP-3380-prepare-fastlane-integration-on-block-checkout
This commit is contained in:
commit
75c808216c
8 changed files with 250 additions and 79 deletions
|
@ -0,0 +1,42 @@
|
|||
import { useCallback } from '@wordpress/element';
|
||||
|
||||
const useHandlePaymentSetup = (
|
||||
emitResponse,
|
||||
card,
|
||||
paymentComponent,
|
||||
tokenizedCustomerData
|
||||
) => {
|
||||
return useCallback( async () => {
|
||||
const isRyanFlow = !! card?.id;
|
||||
let cardToken = card?.id;
|
||||
|
||||
if ( ! cardToken && paymentComponent ) {
|
||||
cardToken = await paymentComponent
|
||||
.getPaymentToken( tokenizedCustomerData )
|
||||
.then( ( response ) => response.id );
|
||||
}
|
||||
|
||||
if ( ! cardToken ) {
|
||||
return {
|
||||
type: emitResponse.responseTypes.ERROR,
|
||||
message: 'Could not process the payment (tokenization error)',
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
type: emitResponse.responseTypes.SUCCESS,
|
||||
meta: {
|
||||
paymentMethodData: {
|
||||
fastlane_member: isRyanFlow,
|
||||
axo_nonce: cardToken,
|
||||
},
|
||||
},
|
||||
};
|
||||
}, [
|
||||
card,
|
||||
paymentComponent,
|
||||
tokenizedCustomerData,
|
||||
] );
|
||||
};
|
||||
|
||||
export default useHandlePaymentSetup;
|
Loading…
Add table
Add a link
Reference in a new issue