From fb9ddad7e22b4a9cd579e6f2f5cb7503542e9919 Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Tue, 8 Nov 2022 12:39:44 +0100 Subject: [PATCH 1/3] [PW-7460] - Support googlepay tx_variant support --- view/frontend/web/js/googlepay/button.js | 24 ++++++++++++------- .../web/js/helpers/getPaymentMethod.js | 8 +++++-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/view/frontend/web/js/googlepay/button.js b/view/frontend/web/js/googlepay/button.js index e2ea0f6..b9e3753 100644 --- a/view/frontend/web/js/googlepay/button.js +++ b/view/frontend/web/js/googlepay/button.js @@ -64,7 +64,8 @@ define([ googlePayToken: null, googlePayAllowed: null, isProductView: false, - maskedId: null + maskedId: null, + googlePayTxVariant: null }, initialize: async function (config, element) { @@ -74,9 +75,9 @@ define([ 'googlePayAllowed' ]); - this.isProductView = config.isProductView; - let googlePaymentMethod = await getPaymentMethod('paywithgoogle', this.isProductView); + let googlePaymentMethod = await getPaymentMethod('paywithgoogle', this.isProductView) ?? await getPaymentMethod('googlepay', this.isProductView); + this.googlePayTxVariant = googlePaymentMethod; // If express methods is not set then set it. if (this.isProductView) { @@ -107,7 +108,8 @@ define([ }); }.bind(this)); - googlePaymentMethod = await getPaymentMethod('paywithgoogle', this.isProductView); + let googlePaymentMethod = await getPaymentMethod('paywithgoogle', this.isProductView) ?? await getPaymentMethod('googlepay', this.isProductView); + this.googlePayTxVariant = googlePaymentMethod; if (!isConfigSet(googlePaymentMethod, ['gatewayMerchantId', 'merchantId'])) { return; @@ -136,7 +138,7 @@ define([ }); const googlePayConfig = this.getGooglePayConfig(googlePaymentMethod, element); - this.googlepay = checkoutComponent.create('paywithgoogle', googlePayConfig); + this.googlepay = checkoutComponent.create(googlePaymentMethod, googlePayConfig); this.googlepay.isAvailable() .then(function () { @@ -156,7 +158,9 @@ define([ }, reloadGooglePayButton: async function (element) { - const googlePaymentMethod = await getPaymentMethod('paywithgoogle', this.isProductView); + let googlePaymentMethod = await getPaymentMethod('paywithgoogle', this.isProductView) ?? await getPaymentMethod('googlepay', this.isProductView); + this.googlePayTxVariant = googlePaymentMethod; + const pdpResponse = await getExpressMethods().getRequest(element); setExpressMethods(pdpResponse); @@ -300,13 +304,17 @@ define([ }, startPlaceOrder: function (paymentData) { + debugger; + + let self = this; + this.setShippingInformation(paymentData) .done(function () { const stateData = JSON.stringify({ paymentMethod: { googlePayCardNetwork: paymentData.paymentMethodData.info.cardNetwork, googlePayToken: paymentData.paymentMethodData.tokenizationData.token, - type: 'paywithgoogle' + type: self.googlePayTxVariant.type } }), payload = { @@ -316,7 +324,7 @@ define([ paymentMethod: { method: 'adyen_hpp', additional_data: { - brand_code: 'paywithgoogle', + brand_code: self.googlePayTxVariant.type, stateData }, extension_attributes: getExtensionAttributes(paymentData) diff --git a/view/frontend/web/js/helpers/getPaymentMethod.js b/view/frontend/web/js/helpers/getPaymentMethod.js index a5954b2..05f4212 100644 --- a/view/frontend/web/js/helpers/getPaymentMethod.js +++ b/view/frontend/web/js/helpers/getPaymentMethod.js @@ -45,8 +45,12 @@ define([ const foundMethods = findPaymentMethod(paymentMethods, paymentType); - foundMethods.configuration = convertKeysToCamelCase(foundMethods.configuration); - return foundMethods; + if (!!foundMethods) { + foundMethods.configuration = convertKeysToCamelCase(foundMethods.configuration); + return foundMethods; + } + + return null; }); }; From 43d8a634eefbdb9199c76f17cbb0e91337e9dc67 Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Tue, 8 Nov 2022 13:27:22 +0100 Subject: [PATCH 2/3] [PW-7460] - Remove debugger syntax --- view/frontend/web/js/googlepay/button.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/view/frontend/web/js/googlepay/button.js b/view/frontend/web/js/googlepay/button.js index b9e3753..d451426 100644 --- a/view/frontend/web/js/googlepay/button.js +++ b/view/frontend/web/js/googlepay/button.js @@ -304,8 +304,6 @@ define([ }, startPlaceOrder: function (paymentData) { - debugger; - let self = this; this.setShippingInformation(paymentData) From 10f3124e7e782f8bee0c2b2cb230f2aeabd9d246 Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Thu, 10 Nov 2022 13:59:44 +0100 Subject: [PATCH 3/3] [PW-7460] - Create function for getting active Google Pay tx_variant --- view/frontend/web/js/googlepay/button.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/view/frontend/web/js/googlepay/button.js b/view/frontend/web/js/googlepay/button.js index d451426..b6b6635 100644 --- a/view/frontend/web/js/googlepay/button.js +++ b/view/frontend/web/js/googlepay/button.js @@ -76,8 +76,7 @@ define([ ]); this.isProductView = config.isProductView; - let googlePaymentMethod = await getPaymentMethod('paywithgoogle', this.isProductView) ?? await getPaymentMethod('googlepay', this.isProductView); - this.googlePayTxVariant = googlePaymentMethod; + let googlePaymentMethod = await this.getGooglePayTxVariant(); // If express methods is not set then set it. if (this.isProductView) { @@ -108,8 +107,7 @@ define([ }); }.bind(this)); - let googlePaymentMethod = await getPaymentMethod('paywithgoogle', this.isProductView) ?? await getPaymentMethod('googlepay', this.isProductView); - this.googlePayTxVariant = googlePaymentMethod; + let googlePaymentMethod = await this.getGooglePayTxVariant(); if (!isConfigSet(googlePaymentMethod, ['gatewayMerchantId', 'merchantId'])) { return; @@ -158,8 +156,7 @@ define([ }, reloadGooglePayButton: async function (element) { - let googlePaymentMethod = await getPaymentMethod('paywithgoogle', this.isProductView) ?? await getPaymentMethod('googlepay', this.isProductView); - this.googlePayTxVariant = googlePaymentMethod; + let googlePaymentMethod = await this.getGooglePayTxVariant(); const pdpResponse = await getExpressMethods().getRequest(element); @@ -222,6 +219,13 @@ define([ }; }, + getGooglePayTxVariant: async function () { + let googlePaymentMethod = await getPaymentMethod('paywithgoogle', this.isProductView) ?? await getPaymentMethod('googlepay', this.isProductView); + this.googlePayTxVariant = googlePaymentMethod; + + return googlePaymentMethod; + }, + onPaymentDataChanged: function (data) { return new Promise((resolve, reject) => { const payload = {