woocommerce-paypal-payments/modules/ppcp-axo/resources/js/Connection/Fastlane.js

53 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-02-09 17:49:45 +00:00
class Fastlane {
constructor( namespace ) {
this.namespace = namespace;
2024-07-12 12:58:34 +02:00
this.connection = null;
this.identity = null;
this.profile = null;
this.FastlaneCardComponent = null;
this.FastlanePaymentComponent = null;
this.FastlaneWatermarkComponent = null;
}
2024-02-09 17:49:45 +00:00
2024-07-12 12:58:34 +02:00
connect( config ) {
return new Promise( ( resolve, reject ) => {
if ( ! window[ this.namespace ] ) {
reject(
new Error(
`Namespace ${ this.namespace } not found on window object`
)
);
return;
}
window[ this.namespace ]
2024-07-12 12:58:34 +02:00
.Fastlane( config )
.then( ( result ) => {
this.init( result );
resolve();
} )
.catch( ( error ) => {
console.error( error );
reject( error );
2024-07-12 12:58:34 +02:00
} );
} );
}
2024-02-09 17:49:45 +00:00
2024-07-12 12:58:34 +02:00
init( connection ) {
this.connection = connection;
this.identity = this.connection.identity;
this.profile = this.connection.profile;
this.FastlaneCardComponent = this.connection.FastlaneCardComponent;
this.FastlanePaymentComponent =
this.connection.FastlanePaymentComponent;
this.FastlaneWatermarkComponent =
this.connection.FastlaneWatermarkComponent;
}
2024-02-09 17:49:45 +00:00
2024-07-12 12:58:34 +02:00
setLocale( locale ) {
this.connection.setLocale( locale );
}
2024-02-09 17:49:45 +00:00
}
export default Fastlane;