Add transaction info to ApplePay initialization

This commit is contained in:
Philipp Stracker 2024-10-08 14:54:00 +02:00
parent 35473df661
commit 6a48c07236
No known key found for this signature in database
3 changed files with 85 additions and 4 deletions

View file

@ -8,6 +8,7 @@ class ApplePayManager {
#ppcpConfig = null;
#applePayConfig = null;
#contextHandler = null;
#transactionInfo = null;
#buttons = [];
constructor( namespace, buttonConfig, ppcpConfig ) {
@ -40,7 +41,7 @@ class ApplePayManager {
// Ensure ApplePayConfig is loaded before proceeding.
await this.init();
button.configure( this.#applePayConfig );
button.configure( this.#applePayConfig, this.#transactionInfo );
button.init();
}
@ -55,11 +56,31 @@ class ApplePayManager {
console.error( 'No ApplePayConfig received during init' );
}
}
if ( ! this.#transactionInfo ) {
this.#transactionInfo = await this.fetchTransactionInfo();
if ( ! this.#applePayConfig ) {
console.error( 'No transactionInfo found during init' );
}
}
} catch ( error ) {
console.error( 'Error during initialization:', error );
}
}
async fetchTransactionInfo() {
try {
if ( ! this.#contextHandler ) {
throw new Error( 'ContextHandler is not initialized' );
}
return await this.#contextHandler.transactionInfo();
} catch ( error ) {
console.error( 'Error fetching transaction info:', error );
throw error;
}
}
reinit() {
for ( const button of this.#buttons ) {
button.reinit();