2024-09-25 00:09:27 +02:00
|
|
|
import { useState, createElement } from '@wordpress/element';
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2024-09-05 21:17:36 +02:00
|
|
|
import { registerPaymentMethod } from '@woocommerce/blocks-registry';
|
|
|
|
|
|
|
|
// Hooks
|
2024-09-12 14:37:22 +02:00
|
|
|
import useFastlaneSdk from './hooks/useFastlaneSdk';
|
2024-09-14 00:21:27 +02:00
|
|
|
import useTokenizeCustomerData from './hooks/useTokenizeCustomerData';
|
2024-09-13 19:24:23 +02:00
|
|
|
import useAxoSetup from './hooks/useAxoSetup';
|
|
|
|
import useAxoCleanup from './hooks/useAxoCleanup';
|
2024-09-14 00:21:27 +02:00
|
|
|
import useHandlePaymentSetup from './hooks/useHandlePaymentSetup';
|
2024-09-24 14:46:12 +02:00
|
|
|
import usePaymentSetupEffect from './hooks/usePaymentSetupEffect';
|
2024-09-05 21:17:36 +02:00
|
|
|
|
|
|
|
// Components
|
2024-09-13 17:27:39 +02:00
|
|
|
import { Payment } from './components/Payment/Payment';
|
2024-09-24 02:09:38 +02:00
|
|
|
|
2024-09-09 18:06:29 +02:00
|
|
|
const gatewayHandle = 'ppcp-axo-gateway';
|
|
|
|
const ppcpConfig = wc.wcSettings.getSetting( `${ gatewayHandle }_data` );
|
2024-09-05 21:17:36 +02:00
|
|
|
|
|
|
|
if ( typeof window.PayPalCommerceGateway === 'undefined' ) {
|
|
|
|
window.PayPalCommerceGateway = ppcpConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
const axoConfig = window.wc_ppcp_axo;
|
|
|
|
|
2024-09-11 13:00:25 +02:00
|
|
|
const Axo = ( props ) => {
|
|
|
|
const { eventRegistration, emitResponse } = props;
|
|
|
|
const { onPaymentSetup } = eventRegistration;
|
2024-09-11 16:08:59 +02:00
|
|
|
const [ paymentComponent, setPaymentComponent ] = useState( null );
|
2024-09-11 12:50:05 +02:00
|
|
|
|
2024-09-12 14:37:22 +02:00
|
|
|
const fastlaneSdk = useFastlaneSdk( axoConfig, ppcpConfig );
|
2024-09-14 00:21:27 +02:00
|
|
|
const tokenizedCustomerData = useTokenizeCustomerData();
|
|
|
|
const handlePaymentSetup = useHandlePaymentSetup(
|
|
|
|
emitResponse,
|
2024-09-11 16:18:08 +02:00
|
|
|
paymentComponent,
|
2024-09-14 00:21:27 +02:00
|
|
|
tokenizedCustomerData
|
2024-09-11 22:58:13 +02:00
|
|
|
);
|
2024-09-10 12:03:50 +02:00
|
|
|
|
2024-09-24 14:46:12 +02:00
|
|
|
useAxoSetup( ppcpConfig, fastlaneSdk, paymentComponent );
|
2024-09-05 21:17:36 +02:00
|
|
|
|
2024-09-14 00:21:27 +02:00
|
|
|
const { handlePaymentLoad } = usePaymentSetupEffect(
|
|
|
|
onPaymentSetup,
|
2024-09-16 15:45:41 +02:00
|
|
|
handlePaymentSetup,
|
|
|
|
setPaymentComponent
|
2024-09-14 00:21:27 +02:00
|
|
|
);
|
2024-09-05 21:17:36 +02:00
|
|
|
|
2024-09-14 00:21:27 +02:00
|
|
|
useAxoCleanup();
|
2024-09-05 21:17:36 +02:00
|
|
|
|
|
|
|
return fastlaneSdk ? (
|
|
|
|
<Payment
|
|
|
|
fastlaneSdk={ fastlaneSdk }
|
|
|
|
onPaymentLoad={ handlePaymentLoad }
|
|
|
|
/>
|
|
|
|
) : (
|
2024-09-25 00:09:27 +02:00
|
|
|
<>{ __( 'Loading Fastlane…', 'woocommerce-paypal-payments' ) }</>
|
2024-09-05 21:17:36 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
registerPaymentMethod( {
|
|
|
|
name: ppcpConfig.id,
|
|
|
|
label: (
|
|
|
|
<div
|
|
|
|
id="ppcp-axo-block-radio-label"
|
|
|
|
dangerouslySetInnerHTML={ { __html: ppcpConfig.title } }
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
content: <Axo />,
|
2024-09-25 00:09:27 +02:00
|
|
|
edit: createElement( ppcpConfig.title ),
|
2024-09-05 21:17:36 +02:00
|
|
|
ariaLabel: ppcpConfig.title,
|
2024-09-13 19:24:23 +02:00
|
|
|
canMakePayment: () => true,
|
2024-09-05 21:17:36 +02:00
|
|
|
supports: {
|
|
|
|
showSavedCards: true,
|
|
|
|
features: ppcpConfig.supports,
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
|
|
|
|
export default Axo;
|