mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
✨ New TransactionInfo DTO
This commit is contained in:
parent
6b5421a2b1
commit
7946150f5b
5 changed files with 72 additions and 20 deletions
|
@ -1,5 +1,6 @@
|
|||
import ErrorHandler from '../../../../ppcp-button/resources/js/modules/ErrorHandler';
|
||||
import CartActionHandler from '../../../../ppcp-button/resources/js/modules/ActionHandler/CartActionHandler';
|
||||
import TransactionInfo from '../Helper/TransactionInfo';
|
||||
|
||||
class BaseHandler {
|
||||
constructor( buttonConfig, ppcpConfig, externalHandler ) {
|
||||
|
@ -35,12 +36,14 @@ class BaseHandler {
|
|||
// handle script reload
|
||||
const data = result.data;
|
||||
|
||||
resolve( {
|
||||
countryCode: data.country_code,
|
||||
currencyCode: data.currency_code,
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: data.total_str,
|
||||
} );
|
||||
resolve(
|
||||
new TransactionInfo(
|
||||
data.total,
|
||||
data.currency_code,
|
||||
data.country_code,
|
||||
true
|
||||
)
|
||||
);
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Spinner from '../../../../ppcp-button/resources/js/modules/Helper/Spinner';
|
||||
import BaseHandler from './BaseHandler';
|
||||
import CheckoutActionHandler from '../../../../ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler';
|
||||
import TransactionInfo from '../Helper/TransactionInfo';
|
||||
|
||||
class PayNowHandler extends BaseHandler {
|
||||
validateContext() {
|
||||
|
@ -14,12 +15,14 @@ class PayNowHandler extends BaseHandler {
|
|||
return new Promise( async ( resolve, reject ) => {
|
||||
const data = this.ppcpConfig.pay_now;
|
||||
|
||||
resolve( {
|
||||
countryCode: data.country_code,
|
||||
currencyCode: data.currency_code,
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: data.total_str,
|
||||
} );
|
||||
resolve(
|
||||
new TransactionInfo(
|
||||
data.total,
|
||||
data.currency_code,
|
||||
data.country_code,
|
||||
true
|
||||
)
|
||||
);
|
||||
} );
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import SimulateCart from '../../../../ppcp-button/resources/js/modules/Helper/Si
|
|||
import ErrorHandler from '../../../../ppcp-button/resources/js/modules/ErrorHandler';
|
||||
import UpdateCart from '../../../../ppcp-button/resources/js/modules/Helper/UpdateCart';
|
||||
import BaseHandler from './BaseHandler';
|
||||
import TransactionInfo from '../Helper/TransactionInfo';
|
||||
|
||||
class SingleProductHandler extends BaseHandler {
|
||||
validateContext() {
|
||||
|
@ -42,12 +43,14 @@ class SingleProductHandler extends BaseHandler {
|
|||
this.ppcpConfig.ajax.simulate_cart.endpoint,
|
||||
this.ppcpConfig.ajax.simulate_cart.nonce
|
||||
).simulate( ( data ) => {
|
||||
resolve( {
|
||||
countryCode: data.country_code,
|
||||
currencyCode: data.currency_code,
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: data.total_str,
|
||||
} );
|
||||
resolve(
|
||||
new TransactionInfo(
|
||||
data.total,
|
||||
data.currency_code,
|
||||
data.country_code,
|
||||
true
|
||||
)
|
||||
);
|
||||
}, products );
|
||||
} );
|
||||
}
|
||||
|
|
|
@ -331,7 +331,7 @@ class GooglepayButton {
|
|||
const paymentDataRequest = Object.assign( {}, baseRequest );
|
||||
paymentDataRequest.allowedPaymentMethods =
|
||||
googlePayConfig.allowedPaymentMethods;
|
||||
paymentDataRequest.transactionInfo = this.transactionInfo;
|
||||
paymentDataRequest.transactionInfo = this.transactionInfo.dataObject;
|
||||
paymentDataRequest.merchantInfo = googlePayConfig.merchantInfo;
|
||||
|
||||
if (
|
||||
|
@ -376,7 +376,7 @@ class GooglepayButton {
|
|||
const updatedData = await new UpdatePaymentData(
|
||||
this.buttonConfig.ajax.update_payment_data
|
||||
).update( paymentData );
|
||||
const transactionInfo = this.transactionInfo;
|
||||
const transactionInfo = this.transactionInfo.dataObject;
|
||||
|
||||
this.log( 'onPaymentDataChanged:updatedData', updatedData );
|
||||
this.log(
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
export default class TransactionInfo {
|
||||
#country = '';
|
||||
#currency = '';
|
||||
#isFinal = false;
|
||||
#amount = 0;
|
||||
|
||||
constructor( amount, currency, country, isFinal ) {
|
||||
this.#country = country;
|
||||
this.#currency = currency;
|
||||
this.#isFinal = isFinal;
|
||||
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
set amount( newAmount ) {
|
||||
this.#amount = Number( newAmount ) || 0;
|
||||
}
|
||||
|
||||
get currencyCode() {
|
||||
return this.#currency;
|
||||
}
|
||||
|
||||
get countryCode() {
|
||||
return this.#country;
|
||||
}
|
||||
|
||||
get totalPriceStatus() {
|
||||
return this.#isFinal ? 'FINAL' : 'DRAFT';
|
||||
}
|
||||
|
||||
get totalPrice() {
|
||||
return this.#amount.toFixed( 2 );
|
||||
}
|
||||
|
||||
get dataObject() {
|
||||
return {
|
||||
countryCode: this.countryCode,
|
||||
currencyCode: this.currencyCode,
|
||||
totalPriceStatus: this.totalPriceStatus,
|
||||
totalPrice: this.totalPrice,
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue