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

@ -36,6 +36,18 @@ import {
* @property {string} lang - The locale; an empty string will apply the user-agent's language.
*/
/**
* This object describes the transaction details.
*
* @typedef {Object} TransactionInfo
* @property {string} countryCode - The ISO country code
* @property {string} currencyCode - The ISO currency code
* @property {string} totalPriceStatus - Usually 'FINAL', can also be 'DRAFT'
* @property {string} totalPrice - Total monetary value of the transaction.
* @property {Array} chosenShippingMethods - Selected shipping method.
* @property {string} shippingPackages - A list of available shipping methods, defined by WooCommerce.
*/
/**
* A payment button for Apple Pay.
*
@ -63,6 +75,13 @@ class ApplePayButton extends PaymentButton {
*/
#initialPaymentRequest = null;
/**
* Details about the processed transaction, provided to the Apple SDK.
*
* @type {?TransactionInfo}
*/
#transactionInfo = null;
/**
* Apple Pay specific API configuration.
*/
@ -116,6 +135,29 @@ class ApplePayButton extends PaymentButton {
this.log( 'Create instance' );
}
/**
* Details about the processed transaction.
*
* This object defines the price that is charged, and text that is displayed inside the
* payment sheet.
*
* @return {?TransactionInfo} The TransactionInfo object.
*/
get transactionInfo() {
return this.#transactionInfo;
}
/**
* Assign the new transaction details to the payment button.
*
* @param {TransactionInfo} newTransactionInfo - Transaction details.
*/
set transactionInfo( newTransactionInfo ) {
this.#transactionInfo = newTransactionInfo;
this.refresh();
}
/**
* The nonce for ajax requests.
*
@ -189,10 +231,12 @@ class ApplePayButton extends PaymentButton {
/**
* Configures the button instance. Must be called before the initial `init()`.
*
* @param {Object} apiConfig - API configuration.
* @param {Object} apiConfig - API configuration.
* @param {TransactionInfo} transactionInfo - Transaction details.
*/
configure( apiConfig ) {
configure( apiConfig, transactionInfo ) {
this.#applePayConfig = apiConfig;
this.#transactionInfo = transactionInfo;
}
init() {