mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Introduce a unified script loader to improve script loading, debugging and prevent conflicts
This commit is contained in:
parent
1325779582
commit
5e1c2a22d2
10 changed files with 186 additions and 65 deletions
|
@ -52,11 +52,12 @@ class AxoManager {
|
|||
billingView = null;
|
||||
cardView = null;
|
||||
|
||||
constructor( axoConfig, ppcpConfig ) {
|
||||
constructor( namespace, axoConfig, ppcpConfig ) {
|
||||
this.namespace = namespace;
|
||||
this.axoConfig = axoConfig;
|
||||
this.ppcpConfig = ppcpConfig;
|
||||
|
||||
this.fastlane = new Fastlane();
|
||||
this.fastlane = new Fastlane( namespace );
|
||||
this.$ = jQuery;
|
||||
|
||||
this.status = {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class Fastlane {
|
||||
construct() {
|
||||
constructor( namespace ) {
|
||||
this.namespace = namespace;
|
||||
this.connection = null;
|
||||
this.identity = null;
|
||||
this.profile = null;
|
||||
|
@ -10,7 +11,16 @@ class Fastlane {
|
|||
|
||||
connect( config ) {
|
||||
return new Promise( ( resolve, reject ) => {
|
||||
window.paypal
|
||||
if ( ! window[ this.namespace ] ) {
|
||||
reject(
|
||||
new Error(
|
||||
`Namespace ${ this.namespace } not found on window object`
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
window[ this.namespace ]
|
||||
.Fastlane( config )
|
||||
.then( ( result ) => {
|
||||
this.init( result );
|
||||
|
@ -18,7 +28,7 @@ class Fastlane {
|
|||
} )
|
||||
.catch( ( error ) => {
|
||||
console.error( error );
|
||||
reject();
|
||||
reject( error );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
|
|
@ -1,21 +1,27 @@
|
|||
import AxoManager from './AxoManager';
|
||||
import { loadPaypalScript } from '../../../ppcp-button/resources/js/modules/Helper/ScriptLoading';
|
||||
import UnifiedScriptLoader from '../../../ppcp-button/resources/js/modules/Helper/UnifiedScriptLoader';
|
||||
|
||||
( function ( { axoConfig, ppcpConfig, jQuery } ) {
|
||||
const namespace = 'ppcpPaypalClassicAxo';
|
||||
const bootstrap = () => {
|
||||
new AxoManager( axoConfig, ppcpConfig );
|
||||
new AxoManager( namespace, axoConfig, ppcpConfig );
|
||||
};
|
||||
|
||||
document.addEventListener( 'DOMContentLoaded', () => {
|
||||
if ( ! typeof PayPalCommerceGateway ) {
|
||||
if ( typeof PayPalCommerceGateway === 'undefined' ) {
|
||||
console.error( 'AXO could not be configured.' );
|
||||
return;
|
||||
}
|
||||
|
||||
// Load PayPal
|
||||
loadPaypalScript( ppcpConfig, () => {
|
||||
bootstrap();
|
||||
} );
|
||||
UnifiedScriptLoader.loadPayPalScript( namespace, ppcpConfig )
|
||||
.then( () => {
|
||||
console.log( 'PayPal script loaded successfully' );
|
||||
bootstrap();
|
||||
} )
|
||||
.catch( ( error ) => {
|
||||
console.error( 'Failed to load PayPal script:', error );
|
||||
} );
|
||||
} );
|
||||
} )( {
|
||||
axoConfig: window.wc_ppcp_axo,
|
||||
|
|
|
@ -378,7 +378,8 @@ class AxoModule implements ServiceModule, ExtendingModule, ExecutableModule {
|
|||
return ! is_user_logged_in()
|
||||
&& CartCheckoutDetector::has_classic_checkout()
|
||||
&& $dcc_configuration->use_fastlane()
|
||||
&& ! $this->is_excluded_endpoint();
|
||||
&& ! $this->is_excluded_endpoint()
|
||||
&& is_checkout();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue