2024-07-12 12:58:34 +02:00
|
|
|
import AxoManager from './AxoManager';
|
2024-10-08 00:41:30 +02:00
|
|
|
import { loadPayPalScript } from '../../../ppcp-button/resources/js/modules/Helper/PayPalScriptLoading';
|
2024-10-07 10:42:56 +02:00
|
|
|
import { log } from './Helper/Debug';
|
2024-02-08 14:37:56 +00:00
|
|
|
|
2025-07-17 15:07:13 +02:00
|
|
|
( function ( { axoConfig, ppcpConfig } ) {
|
2024-10-05 02:26:09 +02:00
|
|
|
const namespace = 'ppcpPaypalClassicAxo';
|
2024-07-12 12:58:34 +02:00
|
|
|
const bootstrap = () => {
|
2024-10-05 02:26:09 +02:00
|
|
|
new AxoManager( namespace, axoConfig, ppcpConfig );
|
2024-07-12 12:58:34 +02:00
|
|
|
};
|
2024-02-08 14:37:56 +00:00
|
|
|
|
2025-07-17 16:44:25 +02:00
|
|
|
document.addEventListener( 'DOMContentLoaded', async () => {
|
2024-10-05 02:26:09 +02:00
|
|
|
if ( typeof PayPalCommerceGateway === 'undefined' ) {
|
2024-07-12 12:58:34 +02:00
|
|
|
console.error( 'AXO could not be configured.' );
|
|
|
|
return;
|
|
|
|
}
|
2024-02-15 17:58:56 +00:00
|
|
|
|
2025-07-17 16:44:25 +02:00
|
|
|
const res = await fetch(
|
|
|
|
axoConfig.ajax.axo_script_attributes.endpoint,
|
|
|
|
{
|
|
|
|
method: 'POST',
|
|
|
|
credentials: 'same-origin',
|
|
|
|
body: JSON.stringify( {
|
|
|
|
nonce: axoConfig.ajax.axo_script_attributes.nonce,
|
|
|
|
} ),
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
const json = await res.json();
|
|
|
|
if ( ! json.success ) {
|
|
|
|
throw new Error( json.data.message );
|
|
|
|
}
|
|
|
|
|
2025-07-17 15:07:13 +02:00
|
|
|
loadPayPalScript( namespace, {
|
|
|
|
...ppcpConfig,
|
|
|
|
script_attributes: {
|
|
|
|
...ppcpConfig.script_attributes,
|
2025-07-17 16:44:25 +02:00
|
|
|
'data-sdk-client-token': json.data.sdk_client_token,
|
2025-07-17 15:07:13 +02:00
|
|
|
},
|
|
|
|
} )
|
2024-10-05 02:26:09 +02:00
|
|
|
.then( () => {
|
|
|
|
bootstrap();
|
|
|
|
} )
|
|
|
|
.catch( ( error ) => {
|
2024-10-07 10:42:56 +02:00
|
|
|
log( `Failed to load PayPal script: ${ error }`, 'error' );
|
2024-10-05 02:26:09 +02:00
|
|
|
} );
|
2024-07-12 12:58:34 +02:00
|
|
|
} );
|
|
|
|
} )( {
|
|
|
|
axoConfig: window.wc_ppcp_axo,
|
|
|
|
ppcpConfig: window.PayPalCommerceGateway,
|
|
|
|
} );
|