From ac98600b8fc085e468ed157afc2be16efa958601 Mon Sep 17 00:00:00 2001 From: Philipp Stracker Date: Tue, 13 Aug 2024 20:23:51 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5=20Simplify=20code,=20remove=20cons?= =?UTF-8?q?ole=20output?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/js/Context/BaseHandler.js | 3 +-- .../resources/js/Context/PayNowHandler.js | 3 +-- .../js/Context/SingleProductHandler.js | 3 +-- .../resources/js/GooglepayButton.js | 4 ++-- .../resources/js/Helper/TransactionInfo.js | 21 +++---------------- 5 files changed, 8 insertions(+), 26 deletions(-) diff --git a/modules/ppcp-googlepay/resources/js/Context/BaseHandler.js b/modules/ppcp-googlepay/resources/js/Context/BaseHandler.js index a9297fca6..d49bee615 100644 --- a/modules/ppcp-googlepay/resources/js/Context/BaseHandler.js +++ b/modules/ppcp-googlepay/resources/js/Context/BaseHandler.js @@ -39,8 +39,7 @@ class BaseHandler { data.total, data.shipping_fee, data.currency_code, - data.country_code, - true + data.country_code ); resolve( transaction ); diff --git a/modules/ppcp-googlepay/resources/js/Context/PayNowHandler.js b/modules/ppcp-googlepay/resources/js/Context/PayNowHandler.js index 8516d8809..81d60b078 100644 --- a/modules/ppcp-googlepay/resources/js/Context/PayNowHandler.js +++ b/modules/ppcp-googlepay/resources/js/Context/PayNowHandler.js @@ -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 ); diff --git a/modules/ppcp-googlepay/resources/js/Context/SingleProductHandler.js b/modules/ppcp-googlepay/resources/js/Context/SingleProductHandler.js index 3502e7701..670b9a7c0 100644 --- a/modules/ppcp-googlepay/resources/js/Context/SingleProductHandler.js +++ b/modules/ppcp-googlepay/resources/js/Context/SingleProductHandler.js @@ -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 ); diff --git a/modules/ppcp-googlepay/resources/js/GooglepayButton.js b/modules/ppcp-googlepay/resources/js/GooglepayButton.js index 9f8524997..d626a172b 100644 --- a/modules/ppcp-googlepay/resources/js/GooglepayButton.js +++ b/modules/ppcp-googlepay/resources/js/GooglepayButton.js @@ -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; } //------------------------ diff --git a/modules/ppcp-googlepay/resources/js/Helper/TransactionInfo.js b/modules/ppcp-googlepay/resources/js/Helper/TransactionInfo.js index 93ffe2e6e..9216ad7c9 100644 --- a/modules/ppcp-googlepay/resources/js/Helper/TransactionInfo.js +++ b/modules/ppcp-googlepay/resources/js/Helper/TransactionInfo.js @@ -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 - ); } } }