mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
import GooglepayButton from './GooglepayButton';
|
|
import ContextHandlerFactory from './Context/ContextHandlerFactory';
|
|
|
|
class GooglepayManagerBlockEditor {
|
|
constructor( buttonConfig, ppcpConfig ) {
|
|
this.buttonConfig = buttonConfig;
|
|
this.ppcpConfig = ppcpConfig;
|
|
this.googlePayConfig = null;
|
|
this.transactionInfo = null;
|
|
this.contextHandler = null;
|
|
}
|
|
|
|
init() {
|
|
( async () => {
|
|
await this.config();
|
|
} )();
|
|
}
|
|
|
|
async config() {
|
|
try {
|
|
// Gets GooglePay configuration of the PayPal merchant.
|
|
this.googlePayConfig = await ppcpBlocksEditorPaypalGooglepay.Googlepay().config();
|
|
|
|
// Fetch transaction information.
|
|
this.transactionInfo = await this.fetchTransactionInfo();
|
|
|
|
const button = new GooglepayButton(
|
|
this.ppcpConfig.context,
|
|
null,
|
|
this.buttonConfig,
|
|
this.ppcpConfig,
|
|
this.contextHandler
|
|
);
|
|
|
|
button.init( this.googlePayConfig, this.transactionInfo );
|
|
} catch ( error ) {
|
|
console.error( 'Failed to initialize Google Pay:', error );
|
|
}
|
|
}
|
|
|
|
async fetchTransactionInfo() {
|
|
try {
|
|
if ( ! this.contextHandler ) {
|
|
this.contextHandler = ContextHandlerFactory.create(
|
|
this.ppcpConfig.context,
|
|
this.buttonConfig,
|
|
this.ppcpConfig,
|
|
null
|
|
);
|
|
}
|
|
return null;
|
|
} catch ( error ) {
|
|
console.error( 'Error fetching transaction info:', error );
|
|
throw error;
|
|
}
|
|
}
|
|
}
|
|
|
|
export default GooglepayManagerBlockEditor;
|