mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
import { useEffect, useCallback } from '@wordpress/element';
|
|
import { useSelect } from '@wordpress/data';
|
|
import { __ } from '@wordpress/i18n';
|
|
import { Card } from '../Card';
|
|
import { STORE_NAME } from '../../stores/axoStore';
|
|
|
|
export const Payment = ( { fastlaneSdk, card, onPaymentLoad } ) => {
|
|
const isGuest = useSelect( ( select ) =>
|
|
select( STORE_NAME ).getIsGuest()
|
|
);
|
|
|
|
const isEmailLookupCompleted = useSelect( ( select ) =>
|
|
select( STORE_NAME ).getIsEmailLookupCompleted()
|
|
);
|
|
|
|
const loadPaymentComponent = useCallback( async () => {
|
|
if ( isGuest && isEmailLookupCompleted ) {
|
|
const paymentComponent = await fastlaneSdk.FastlaneCardComponent(
|
|
{}
|
|
);
|
|
paymentComponent.render( `#fastlane-card` );
|
|
onPaymentLoad( paymentComponent );
|
|
}
|
|
}, [ isGuest, isEmailLookupCompleted, fastlaneSdk, onPaymentLoad ] );
|
|
|
|
useEffect( () => {
|
|
loadPaymentComponent();
|
|
}, [ loadPaymentComponent ] );
|
|
|
|
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.',
|
|
'woocommerce-paypal-payments'
|
|
) }
|
|
</div>
|
|
);
|
|
}
|
|
return (
|
|
<Card
|
|
card={ card }
|
|
fastlaneSdk={ fastlaneSdk }
|
|
showWatermark={ ! isGuest }
|
|
/>
|
|
);
|
|
};
|