🔥 Simplify code, remove console output

This commit is contained in:
Philipp Stracker 2024-08-13 20:23:51 +02:00
parent f2301a4674
commit ac98600b8f
No known key found for this signature in database
5 changed files with 8 additions and 26 deletions

View file

@ -39,8 +39,7 @@ class BaseHandler {
data.total,
data.shipping_fee,
data.currency_code,
data.country_code,
true
data.country_code
);
resolve( transaction );

View file

@ -19,8 +19,7 @@ class PayNowHandler extends BaseHandler {
data.total,
data.shipping_fee,
data.currency_code,
data.country_code,
true
data.country_code
);
resolve( transaction );

View file

@ -47,8 +47,7 @@ class SingleProductHandler extends BaseHandler {
data.total,
data.shipping_fee,
data.currency_code,
data.country_code,
true
data.country_code
);
resolve( transaction );

View file

@ -337,7 +337,7 @@ class GooglepayButton {
const paymentDataRequest = Object.assign( {}, baseRequest );
paymentDataRequest.allowedPaymentMethods =
googlePayConfig.allowedPaymentMethods;
paymentDataRequest.transactionInfo = this.transactionInfo.dataObject;
paymentDataRequest.transactionInfo = this.transactionInfo.finalObject;
paymentDataRequest.merchantInfo = googlePayConfig.merchantInfo;
if (
@ -500,7 +500,7 @@ class GooglepayButton {
* @return {{totalPrice: string, countryCode: string, totalPriceStatus: string, currencyCode: string}} Updated details.
*/
calculateNewTransactionInfo( transactionInfo ) {
return transactionInfo.dataObject;
return transactionInfo.finalObject;
}
//------------------------

View file

@ -1,14 +1,12 @@
export default class TransactionInfo {
#country = '';
#currency = '';
#isFinal = false;
#amount = 0;
#shippingFee = 0;
constructor( total, shippingFee, currency, country, isFinal ) {
constructor( total, shippingFee, currency, country ) {
this.#country = country;
this.#currency = currency;
this.#isFinal = isFinal;
this.shippingFee = shippingFee;
this.amount = total - shippingFee;
@ -38,21 +36,17 @@ export default class TransactionInfo {
return this.#country;
}
get totalPriceStatus() {
return this.#isFinal ? 'FINAL' : 'DRAFT';
}
get totalPrice() {
const total = this.#amount + this.#shippingFee;
return total.toFixed( 2 );
}
get dataObject() {
get finalObject() {
return {
countryCode: this.countryCode,
currencyCode: this.currencyCode,
totalPriceStatus: this.totalPriceStatus,
totalPriceStatus: 'FINAL',
totalPrice: this.totalPrice,
};
}
@ -74,15 +68,6 @@ export default class TransactionInfo {
if ( totalPrice ) {
this.shippingFee = shippingFee;
this.amount = totalPrice - this.shippingFee;
console.log(
'New Total Price:',
totalPrice,
'=',
this.amount,
'+',
this.shippingFee
);
}
}
}