woocommerce-paypal-payments/modules/ppcp-googlepay/resources/js/Helper/TransactionInfo.js

62 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-08-13 18:41:42 +02:00
export default class TransactionInfo {
#country = '';
#currency = '';
#isFinal = false;
#amount = 0;
2024-08-13 19:31:51 +02:00
#shippingFee = 0;
2024-08-13 18:41:42 +02:00
2024-08-13 19:31:51 +02:00
constructor( total, shippingFee, currency, country, isFinal ) {
2024-08-13 18:41:42 +02:00
this.#country = country;
this.#currency = currency;
this.#isFinal = isFinal;
2024-08-13 19:31:51 +02:00
this.shippingFee = shippingFee;
this.amount = total - shippingFee;
2024-08-13 18:41:42 +02:00
}
set amount( newAmount ) {
this.#amount = Number( newAmount ) || 0;
}
2024-08-13 19:31:51 +02:00
set shippingFee( newCost ) {
this.#shippingFee = Number( newCost ) || 0;
}
set total( newTotal ) {
newTotal = Number( newTotal ) || 0;
if ( ! newTotal ) {
return;
}
this.#amount = newTotal - this.#shippingFee;
}
2024-08-13 18:41:42 +02:00
get currencyCode() {
return this.#currency;
}
get countryCode() {
return this.#country;
}
get totalPriceStatus() {
return this.#isFinal ? 'FINAL' : 'DRAFT';
}
get totalPrice() {
2024-08-13 19:31:51 +02:00
const total = this.#amount + this.#shippingFee;
return total.toFixed( 2 );
2024-08-13 18:41:42 +02:00
}
get dataObject() {
return {
countryCode: this.countryCode,
currencyCode: this.currencyCode,
totalPriceStatus: this.totalPriceStatus,
totalPrice: this.totalPrice,
};
}
}