🔀 Merge branch 'PCP-3380’

This commit is contained in:
Philipp Stracker 2024-09-16 16:35:12 +02:00
commit 55635d11c0
No known key found for this signature in database
6 changed files with 39 additions and 48 deletions

View file

@ -172,7 +172,7 @@ $fast-transition-duration: 0.5s;
}
// 4.7 Validation Error
.wc-block-components-validation-error {
.wc-block-components-address-form__email .wc-block-components-validation-error {
grid-area: error;
width: 100%;
margin-top: 4px;

View file

@ -8,24 +8,35 @@ export const Payment = ( { fastlaneSdk, card, onPaymentLoad } ) => {
select( STORE_NAME ).getIsGuest()
);
// Memoized Fastlane card rendering
const isEmailLookupCompleted = useSelect( ( select ) =>
select( STORE_NAME ).getIsEmailLookupCompleted()
);
const loadPaymentComponent = useCallback( async () => {
if ( isGuest ) {
if ( isGuest && isEmailLookupCompleted ) {
const paymentComponent = await fastlaneSdk.FastlaneCardComponent(
{}
);
paymentComponent.render( `#fastlane-card` );
onPaymentLoad( paymentComponent );
}
}, [ isGuest, fastlaneSdk, onPaymentLoad ] );
}, [ isGuest, isEmailLookupCompleted, fastlaneSdk, onPaymentLoad ] );
useEffect( () => {
loadPaymentComponent();
}, [ loadPaymentComponent ] );
return isGuest ? (
<div id="fastlane-card" key="fastlane-card" />
) : (
if ( isGuest ) {
if ( isEmailLookupCompleted ) {
return <div id="fastlane-card" key="fastlane-card" />;
}
return (
<div id="ppcp-axo-block-radio-content">
Enter your email address above to continue.
</div>
);
}
return (
<Card
card={ card }
fastlaneSdk={ fastlaneSdk }

View file

@ -17,9 +17,15 @@ const useHandlePaymentSetup = (
}
if ( ! cardToken ) {
let reason = 'tokenization error';
if ( ! paymentComponent ) {
reason = 'initialization error';
}
return {
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;

View file

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

View file

@ -1,6 +1,10 @@
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.
* It pre-processes the payment details and returns data for server-side processing.
@ -13,10 +17,12 @@ const usePaymentSetupEffect = ( onPaymentSetup, handlePaymentSetup ) => {
};
}, [ onPaymentSetup, handlePaymentSetup ] );
const handlePaymentLoad = useCallback( ( component ) => {
// We'll return this function instead of calling setPaymentComponent directly
return component;
}, [] );
const handlePaymentLoad = useCallback(
( component ) => {
setPaymentComponent( component );
},
[ setPaymentComponent ]
);
return { handlePaymentLoad };
};

View file

@ -6,7 +6,6 @@ import useFastlaneSdk from './hooks/useFastlaneSdk';
import useTokenizeCustomerData from './hooks/useTokenizeCustomerData';
import useCardChange from './hooks/useCardChange';
import useAxoSetup from './hooks/useAxoSetup';
import usePaymentSetup from './hooks/usePaymentSetup';
import useAxoCleanup from './hooks/useAxoCleanup';
import useHandlePaymentSetup from './hooks/useHandlePaymentSetup';
@ -49,11 +48,11 @@ const Axo = ( props ) => {
setCard,
setWooPhone
);
usePaymentSetup( onPaymentSetup, emitResponse, card );
const { handlePaymentLoad } = usePaymentSetupEffect(
onPaymentSetup,
handlePaymentSetup
handlePaymentSetup,
setPaymentComponent
);
useAxoCleanup();