mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
39 lines
948 B
JavaScript
39 lines
948 B
JavaScript
import { useEffect, useCallback } from '@wordpress/element';
|
|
import { useSelect } from '@wordpress/data';
|
|
import { CreditCard } from './CreditCard';
|
|
import { STORE_NAME } from '../stores/axoStore';
|
|
|
|
export const Payment = ( {
|
|
fastlaneSdk,
|
|
card,
|
|
onPaymentLoad,
|
|
} ) => {
|
|
const isGuest = useSelect( ( select ) =>
|
|
select( STORE_NAME ).getIsGuest()
|
|
);
|
|
|
|
// Memoized Fastlane card rendering
|
|
const loadPaymentComponent = useCallback( async () => {
|
|
if ( isGuest ) {
|
|
const paymentComponent = await fastlaneSdk.FastlaneCardComponent(
|
|
{}
|
|
);
|
|
paymentComponent.render( `#fastlane-card` );
|
|
onPaymentLoad( paymentComponent );
|
|
}
|
|
}, [ isGuest, fastlaneSdk, onPaymentLoad ] );
|
|
|
|
useEffect( () => {
|
|
loadPaymentComponent();
|
|
}, [ loadPaymentComponent ] );
|
|
|
|
return isGuest ? (
|
|
<div id="fastlane-card" key="fastlane-card" />
|
|
) : (
|
|
<CreditCard
|
|
card={ card }
|
|
fastlaneSdk={ fastlaneSdk }
|
|
showWatermark={ ! isGuest }
|
|
/>
|
|
);
|
|
};
|