Submit axo_nonce during block checkout

Initial logic supports Ryan flow, when paying with a saved card.
This commit is contained in:
Philipp Stracker 2024-09-11 13:00:25 +02:00
parent 861034855e
commit d4c242c013
No known key found for this signature in database

View file

@ -42,12 +42,40 @@ if ( typeof window.PayPalCommerceGateway === 'undefined' ) {
const axoConfig = window.wc_ppcp_axo; const axoConfig = window.wc_ppcp_axo;
const Axo = () => { const Axo = ( props ) => {
const { eventRegistration, emitResponse } = props;
const { onPaymentSetup } = eventRegistration;
const [ paypalLoaded, setPaypalLoaded ] = useState( false ); const [ paypalLoaded, setPaypalLoaded ] = useState( false );
const [ shippingAddress, setShippingAddress ] = useState( null ); const [ shippingAddress, setShippingAddress ] = useState( null );
const [ card, setCard ] = useState( null ); const [ card, setCard ] = useState( null );
const fastlaneSdk = useAxoBlockManager( axoConfig, ppcpConfig ); const fastlaneSdk = useAxoBlockManager( axoConfig, ppcpConfig );
useEffect( () => {
const unsubscribe = onPaymentSetup( async () => {
// Validate payment options and emit response.
// Note: This response supports the Ryan flow (payment via saved card-token)
return {
type: emitResponse.responseTypes.SUCCESS,
meta: {
paymentMethodData: {
axo_nonce: card?.id,
},
},
};
} );
// Unsubscribes when this component is unmounted.
return () => {
unsubscribe();
};
}, [
emitResponse.responseTypes.ERROR,
emitResponse.responseTypes.SUCCESS,
onPaymentSetup,
card,
] );
const { setIsAxoActive, setIsGuest, setIsAxoScriptLoaded } = const { setIsAxoActive, setIsGuest, setIsAxoScriptLoaded } =
useDispatch( STORE_NAME ); useDispatch( STORE_NAME );