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:
Daniel Dudzic 2024-09-14 00:21:27 +02:00
commit 75c808216c
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
8 changed files with 250 additions and 79 deletions

View file

@ -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;