From 8eb98b9908ce2eccd4611c8526e4caed2c376aaa Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Fri, 17 Feb 2023 09:35:17 +0100 Subject: [PATCH 1/6] [PW-7999] Fix quote totals --- Model/ExpressInit.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Model/ExpressInit.php b/Model/ExpressInit.php index 0143f0b..8c0deb9 100644 --- a/Model/ExpressInit.php +++ b/Model/ExpressInit.php @@ -189,6 +189,13 @@ public function execute( ); // We have to save it here to get the totals in the express data builder $this->quoteRepository->save($adyenExpressQuote); + + // Quote object is required to collect the totals instead of cart object. + $quoteModel = $this->quoteRepository->getActive($adyenExpressQuote->getId()); + $quoteModel->collectTotals(); + $quoteModel->setTotalsCollectedFlag(false); + $this->quoteRepository->save($quoteModel); + $expressData = $this->expressDataBuilder->execute( $adyenExpressQuote, $product @@ -234,8 +241,7 @@ private function addProductToAdyenExpressQuote( $product, $productCartParams ); - $adyenExpressQuote->collectTotals(); - $adyenExpressQuote->setTotalsCollectedFlag(false); + return $adyenExpressQuote; } From fbdff1f2d77a79fbc5ceb27770f8ce9fbfcc6235 Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Wed, 29 Mar 2023 17:20:33 +0200 Subject: [PATCH 2/6] [PW-8234] Add component state data to the payment-information call payload (#23) --- view/frontend/web/js/applepay/button.js | 9 ++------- view/frontend/web/js/googlepay/button.js | 12 +++--------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/view/frontend/web/js/applepay/button.js b/view/frontend/web/js/applepay/button.js index b1e03d7..8316028 100644 --- a/view/frontend/web/js/applepay/button.js +++ b/view/frontend/web/js/applepay/button.js @@ -422,12 +422,7 @@ define([ } }; - const stateData = { - 'paymentMethod': { - 'type': 'applepay', - 'applePayToken': btoa(JSON.stringify(event.payment.token.paymentData)) - } - }; + let componentData = self.applePayComponent.data; setShippingInformation(payload, this.isProductView).done(function () { // Submit payment information @@ -437,7 +432,7 @@ define([ method: 'adyen_hpp', additional_data: { brand_code: 'applepay', - stateData: JSON.stringify(stateData) + stateData: JSON.stringify(componentData) } } }; diff --git a/view/frontend/web/js/googlepay/button.js b/view/frontend/web/js/googlepay/button.js index 736d841..ee7c329 100644 --- a/view/frontend/web/js/googlepay/button.js +++ b/view/frontend/web/js/googlepay/button.js @@ -331,17 +331,11 @@ define([ startPlaceOrder: function (paymentData) { let self = this; + let componentData = self.googlePayComponent.data; this.setShippingInformation(paymentData) .done(function () { - const stateData = JSON.stringify({ - paymentMethod: { - googlePayCardNetwork: paymentData.paymentMethodData.info.cardNetwork, - googlePayToken: paymentData.paymentMethodData.tokenizationData.token, - type: self.googlePayComponent.props.type - } - }), - payload = { + const payload = { email: paymentData.email, shippingAddress: this.mapAddress(paymentData.shippingAddress), billingAddress: this.mapAddress(paymentData.paymentMethodData.info.billingAddress), @@ -349,7 +343,7 @@ define([ method: 'adyen_hpp', additional_data: { brand_code: self.googlePayComponent.props.type, - stateData + stateData: JSON.stringify(componentData) }, extension_attributes: getExtensionAttributes(paymentData) } From 3186afdce0ad853cfec7f13dc3361247c60ba20d Mon Sep 17 00:00:00 2001 From: RokPopov Date: Tue, 23 May 2023 17:33:17 +0200 Subject: [PATCH 3/6] setup new js action, helper and make a call to internal /payment-status to determine further action --- .../web/js/actions/getPaymentStatus.js | 15 ++++++++++ view/frontend/web/js/googlepay/button.js | 29 +++++++++++++++++-- .../web/js/helpers/getAdyenPaymentApiUrl.js | 11 +++++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 view/frontend/web/js/actions/getPaymentStatus.js create mode 100644 view/frontend/web/js/helpers/getAdyenPaymentApiUrl.js diff --git a/view/frontend/web/js/actions/getPaymentStatus.js b/view/frontend/web/js/actions/getPaymentStatus.js new file mode 100644 index 0000000..39aa968 --- /dev/null +++ b/view/frontend/web/js/actions/getPaymentStatus.js @@ -0,0 +1,15 @@ +define([ + 'mage/storage', + 'Adyen_ExpressCheckout/js/helpers/getAdyenPaymentApiUrl' +], function (storage, getAdyenPaymentApiUrl) { + 'use strict'; + + return function (payload) { + return storage.post( + getAdyenPaymentApiUrl('orders/payment-status'), + JSON.stringify(payload), + true + ); + }; +}); + diff --git a/view/frontend/web/js/googlepay/button.js b/view/frontend/web/js/googlepay/button.js index ee7c329..6ae9aa3 100644 --- a/view/frontend/web/js/googlepay/button.js +++ b/view/frontend/web/js/googlepay/button.js @@ -1,4 +1,5 @@ define([ + 'jquery', 'uiComponent', 'mage/translate', 'Magento_Customer/js/customer-data', @@ -6,6 +7,7 @@ define([ 'Adyen_ExpressCheckout/js/actions/activateCart', 'Adyen_ExpressCheckout/js/actions/cancelCart', 'Adyen_ExpressCheckout/js/actions/createPayment', + 'Adyen_ExpressCheckout/js/actions/getPaymentStatus', 'Adyen_ExpressCheckout/js/actions/getShippingMethods', 'Adyen_ExpressCheckout/js/actions/getExpressMethods', 'Adyen_ExpressCheckout/js/actions/setShippingInformation', @@ -26,9 +28,11 @@ define([ 'Adyen_ExpressCheckout/js/model/config', 'Adyen_ExpressCheckout/js/model/countries', 'Adyen_ExpressCheckout/js/model/totals', - 'Adyen_ExpressCheckout/js/model/currency' + 'Adyen_ExpressCheckout/js/model/currency', + 'mage/cookies', ], function ( + $, Component, $t, customerData, @@ -36,6 +40,7 @@ define([ activateCart, cancelCart, createPayment, + getPaymentStatus, getShippingMethods, getExpressMethods, setShippingInformation, @@ -356,7 +361,27 @@ define([ } createPayment(JSON.stringify(payload), this.isProductView) - .done(redirectToSuccess) + .done( function (orderId) { + // TODO + debugger; + // orderId && getPaymentStatus(orderId) + var payload = { + orderId: orderId, + form_key: $.mage.cookies.get('form_key') + } + getPaymentStatus(payload).then(function (response) { + console.log('response to payment status: ', response) + // if the result is final, then redirectToSuccess + if (!!response.isFinal) { + redirectToSuccess(); + + // if the result is not final, call the method to handle additional action (make a payment details call) + } else { + // handle action + } + }) + }) + .fail(function (e) { console.error('Adyen GooglePay Unable to take payment', e); }); diff --git a/view/frontend/web/js/helpers/getAdyenPaymentApiUrl.js b/view/frontend/web/js/helpers/getAdyenPaymentApiUrl.js new file mode 100644 index 0000000..9494625 --- /dev/null +++ b/view/frontend/web/js/helpers/getAdyenPaymentApiUrl.js @@ -0,0 +1,11 @@ +define([ + 'Adyen_ExpressCheckout/js/model/config' +], function (configModel) { + 'use strict'; + + return function (uri) { + const config = configModel().getConfig(); + + return 'rest/' + config.storeCode + '/V1/internal/adyen/' + uri; + }; +}); From 2d37e564656621f0494371199fb2dad01a1790cb Mon Sep 17 00:00:00 2001 From: RokPopov Date: Wed, 24 May 2023 09:21:23 +0200 Subject: [PATCH 4/6] wip handling the action --- view/frontend/web/js/googlepay/button.js | 81 ++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 7 deletions(-) diff --git a/view/frontend/web/js/googlepay/button.js b/view/frontend/web/js/googlepay/button.js index 6ae9aa3..3249224 100644 --- a/view/frontend/web/js/googlepay/button.js +++ b/view/frontend/web/js/googlepay/button.js @@ -1,9 +1,14 @@ define([ 'jquery', + 'ko', 'uiComponent', 'mage/translate', 'Magento_Customer/js/customer-data', + 'Magento_Checkout/js/model/full-screen-loader', + 'Magento_Checkout/js/model/quote', 'Adyen_Payment/js/adyen', + 'Adyen_Payment/js/model/adyen-payment-modal', + 'Adyen_Payment/js/model/adyen-payment-service', 'Adyen_ExpressCheckout/js/actions/activateCart', 'Adyen_ExpressCheckout/js/actions/cancelCart', 'Adyen_ExpressCheckout/js/actions/createPayment', @@ -33,10 +38,15 @@ define([ ], function ( $, + ko, Component, $t, customerData, + fullScreenLoader, + quote, AdyenCheckout, + adyenPaymentModal, + adyenPaymentService, activateCart, cancelCart, createPayment, @@ -66,13 +76,17 @@ define([ 'use strict'; return Component.extend({ + isPlaceOrderActionAllowed: ko.observable( + quote.billingAddress() != null), + defaults: { shippingMethods: {}, googlePayToken: null, googlePayAllowed: null, isProductView: false, maskedId: null, - googlePayComponent: null + googlePayComponent: null, + modalLabel: 'cc_actionModal' }, initialize: async function (config, element) { @@ -146,12 +160,13 @@ define([ this.initialiseGooglePayComponent(googlePaymentMethod, element); }, - initialiseGooglePayComponent: async function (googlePaymentMethod, element) { + initialiseGooglePayComponent: async function (googlePaymentMethod, element, handleOnAdditionalDetails) { const config = configModel().getConfig(); const checkoutComponent = await new AdyenCheckout({ locale: config.locale, originKey: config.originkey, environment: config.checkoutenv, + onAdditionalDetails: this.handleOnAdditionalDetails, risk: { enabled: false } @@ -369,15 +384,14 @@ define([ orderId: orderId, form_key: $.mage.cookies.get('form_key') } - getPaymentStatus(payload).then(function (response) { - console.log('response to payment status: ', response) - // if the result is final, then redirectToSuccess + getPaymentStatus(payload).done(function (responseJSON) { + let response = JSON.parse(responseJSON); + // if result is final redirect to success page if (!!response.isFinal) { redirectToSuccess(); - - // if the result is not final, call the method to handle additional action (make a payment details call) } else { // handle action + self.handleAction(response.action, orderId) } }) }) @@ -415,6 +429,59 @@ define([ return setShippingInformation(payload, this.isProductView); }, + // handleOnAdditionalDetails: function(result) { + // const self = this; + // let request = result.data; + // adyenPaymentModal.hideModalLabel(this.modalLabel); + // fullScreenLoader.startLoader(); + // request.orderId = self.orderId; + // let popupModal = self.showModal(); + // + // adyenPaymentService.paymentDetails(request). + // done(function(responseJSON) { + // fullScreenLoader.stopLoader(); + // self.handleAdyenResult(responseJSON, self.orderId); + // }). + // fail(function(response) { + // self.closeModal(popupModal); + // errorProcessor.process(response, self.messageContainer); + // self.isPlaceOrderActionAllowed(true); + // fullScreenLoader.stopLoader(); + // }); + // }, + + handleAction: function(action, orderId) { + var self = this; + let popupModal; + + fullScreenLoader.stopLoader(); + + debugger; + + if (action.type === 'threeDS2' || action.type === 'await') { + popupModal = self.showModal(); + } + + try { + this.googlePayComponent.createFromAction( + action).mount('#' + this.modalLabel); + } catch (e) { + console.log(e); + self.closeModal(popupModal); + } + }, + + showModal: function() { + let actionModal = adyenPaymentModal.showModal(adyenPaymentService, fullScreenLoader, this.messageContainer, this.orderId, this.modalLabel, this.isPlaceOrderActionAllowed); + $("." + this.modalLabel + " .action-close").hide(); + + return actionModal; + }, + + closeModal: function(popupModal) { + adyenPaymentModal.closeModal(popupModal, this.modalLabel) + }, + mapAddress: function (address) { const [firstname, ...lastname] = address.name.split(' '); From 26b70f6460520438bd27d18d40745b6a0580881d Mon Sep 17 00:00:00 2001 From: RokPopov Date: Wed, 24 May 2023 16:00:56 +0200 Subject: [PATCH 5/6] handle the paymentDetails call, correctly initiate the checkout component, fix csp_whitelist, handle 3DS2 on product page, add a new html element in the template file --- etc/csp_whitelist.xml | 24 +++- .../templates/googlepay/shortcut.phtml | 1 + .../web/js/actions/getPaymentStatus.js | 15 --- view/frontend/web/js/googlepay/button.js | 108 +++++++++--------- .../web/js/helpers/getAdyenPaymentApiUrl.js | 11 -- 5 files changed, 79 insertions(+), 80 deletions(-) delete mode 100644 view/frontend/web/js/actions/getPaymentStatus.js delete mode 100644 view/frontend/web/js/helpers/getAdyenPaymentApiUrl.js diff --git a/etc/csp_whitelist.xml b/etc/csp_whitelist.xml index 07b7f17..30e0831 100644 --- a/etc/csp_whitelist.xml +++ b/etc/csp_whitelist.xml @@ -13,23 +13,41 @@ + + + *.adyen.com + + + + + *.adyen.com + + https://*.gstatic.com + *.adyen.com + + + + + *.adyen.com - https://*.gstatic.com - https://fonts.googleapis.com/ + + + *.adyen.com + + - diff --git a/view/frontend/templates/googlepay/shortcut.phtml b/view/frontend/templates/googlepay/shortcut.phtml index e85e05d..06ddd3c 100644 --- a/view/frontend/templates/googlepay/shortcut.phtml +++ b/view/frontend/templates/googlepay/shortcut.phtml @@ -31,3 +31,4 @@ $config = [
+
diff --git a/view/frontend/web/js/actions/getPaymentStatus.js b/view/frontend/web/js/actions/getPaymentStatus.js deleted file mode 100644 index 39aa968..0000000 --- a/view/frontend/web/js/actions/getPaymentStatus.js +++ /dev/null @@ -1,15 +0,0 @@ -define([ - 'mage/storage', - 'Adyen_ExpressCheckout/js/helpers/getAdyenPaymentApiUrl' -], function (storage, getAdyenPaymentApiUrl) { - 'use strict'; - - return function (payload) { - return storage.post( - getAdyenPaymentApiUrl('orders/payment-status'), - JSON.stringify(payload), - true - ); - }; -}); - diff --git a/view/frontend/web/js/googlepay/button.js b/view/frontend/web/js/googlepay/button.js index 3249224..e3c1df0 100644 --- a/view/frontend/web/js/googlepay/button.js +++ b/view/frontend/web/js/googlepay/button.js @@ -12,7 +12,6 @@ define([ 'Adyen_ExpressCheckout/js/actions/activateCart', 'Adyen_ExpressCheckout/js/actions/cancelCart', 'Adyen_ExpressCheckout/js/actions/createPayment', - 'Adyen_ExpressCheckout/js/actions/getPaymentStatus', 'Adyen_ExpressCheckout/js/actions/getShippingMethods', 'Adyen_ExpressCheckout/js/actions/getExpressMethods', 'Adyen_ExpressCheckout/js/actions/setShippingInformation', @@ -50,7 +49,6 @@ define([ activateCart, cancelCart, createPayment, - getPaymentStatus, getShippingMethods, getExpressMethods, setShippingInformation, @@ -86,7 +84,8 @@ define([ isProductView: false, maskedId: null, googlePayComponent: null, - modalLabel: 'cc_actionModal' + modalLabel: 'googlepay_actionmodal', + orderId: 0 }, initialize: async function (config, element) { @@ -154,26 +153,26 @@ define([ let googlePaymentMethod = await getPaymentMethod('googlepay', this.isProductView); if (!isConfigSet(googlePaymentMethod, ['gatewayMerchantId', 'merchantId'])) { - return; } this.initialiseGooglePayComponent(googlePaymentMethod, element); }, - initialiseGooglePayComponent: async function (googlePaymentMethod, element, handleOnAdditionalDetails) { + initialiseGooglePayComponent: async function (googlePaymentMethod, element) { const config = configModel().getConfig(); - const checkoutComponent = await new AdyenCheckout({ + this.checkoutComponent = await new AdyenCheckout({ locale: config.locale, - originKey: config.originkey, + clientKey: config.originkey, environment: config.checkoutenv, - onAdditionalDetails: this.handleOnAdditionalDetails, + paymentMethodsResponse: getPaymentMethod('googlepay', this.isProductView), + onAdditionalDetails: this.handleOnAdditionalDetails.bind(this), risk: { enabled: false } }); const googlePayConfig = this.getGooglePayConfig(googlePaymentMethod, element); - this.googlePayComponent = checkoutComponent.create(googlePaymentMethod, googlePayConfig); + this.googlePayComponent = this.checkoutComponent.create(googlePaymentMethod, googlePayConfig); this.googlePayComponent.isAvailable() .then(function () { @@ -377,25 +376,14 @@ define([ createPayment(JSON.stringify(payload), this.isProductView) .done( function (orderId) { - // TODO - debugger; - // orderId && getPaymentStatus(orderId) - var payload = { - orderId: orderId, - form_key: $.mage.cookies.get('form_key') + if (!!orderId) { + self.orderId = orderId; + adyenPaymentService.getOrderPaymentStatus(orderId). + done(function (responseJSON) { + self.handleAdyenResult(responseJSON, orderId); + }) } - getPaymentStatus(payload).done(function (responseJSON) { - let response = JSON.parse(responseJSON); - // if result is final redirect to success page - if (!!response.isFinal) { - redirectToSuccess(); - } else { - // handle action - self.handleAction(response.action, orderId) - } - }) }) - .fail(function (e) { console.error('Adyen GooglePay Unable to take payment', e); }); @@ -429,26 +417,39 @@ define([ return setShippingInformation(payload, this.isProductView); }, - // handleOnAdditionalDetails: function(result) { - // const self = this; - // let request = result.data; - // adyenPaymentModal.hideModalLabel(this.modalLabel); - // fullScreenLoader.startLoader(); - // request.orderId = self.orderId; - // let popupModal = self.showModal(); - // - // adyenPaymentService.paymentDetails(request). - // done(function(responseJSON) { - // fullScreenLoader.stopLoader(); - // self.handleAdyenResult(responseJSON, self.orderId); - // }). - // fail(function(response) { - // self.closeModal(popupModal); - // errorProcessor.process(response, self.messageContainer); - // self.isPlaceOrderActionAllowed(true); - // fullScreenLoader.stopLoader(); - // }); - // }, + handleOnAdditionalDetails: function (result) { + const self = this; + let request = result.data; + adyenPaymentModal.hideModalLabel(this.modalLabel); + fullScreenLoader.startLoader(); + request.orderId = self.orderId; + let popupModal = self.showModal(); + + adyenPaymentService.paymentDetails(request). + done(function(responseJSON) { + fullScreenLoader.stopLoader(); + self.handleAdyenResult(responseJSON, self.orderId); + }). + fail(function(response) { + self.closeModal(popupModal); + errorProcessor.process(response, self.messageContainer); + self.isPlaceOrderActionAllowed(true); + fullScreenLoader.stopLoader(); + }); + }, + + handleAdyenResult: function (responseJSON, orderId) { + var self = this; + var response = JSON.parse(responseJSON); + + if (!!response.isFinal) { + // Status is final redirect to the success page + redirectToSuccess() + } else { + // Handle action + self.handleAction(response.action, orderId); + } + }, handleAction: function(action, orderId) { var self = this; @@ -456,15 +457,12 @@ define([ fullScreenLoader.stopLoader(); - debugger; - if (action.type === 'threeDS2' || action.type === 'await') { popupModal = self.showModal(); } try { - this.googlePayComponent.createFromAction( - action).mount('#' + this.modalLabel); + self.checkoutComponent.createFromAction(action).mount('#' + this.modalLabel); } catch (e) { console.log(e); self.closeModal(popupModal); @@ -472,7 +470,15 @@ define([ }, showModal: function() { - let actionModal = adyenPaymentModal.showModal(adyenPaymentService, fullScreenLoader, this.messageContainer, this.orderId, this.modalLabel, this.isPlaceOrderActionAllowed); + let actionModal = adyenPaymentModal.showModal( + adyenPaymentService, + fullScreenLoader, + this.messageContainer, + this.orderId, + this.modalLabel, + this.isPlaceOrderActionAllowed + ); + $("." + this.modalLabel + " .action-close").hide(); return actionModal; diff --git a/view/frontend/web/js/helpers/getAdyenPaymentApiUrl.js b/view/frontend/web/js/helpers/getAdyenPaymentApiUrl.js deleted file mode 100644 index 9494625..0000000 --- a/view/frontend/web/js/helpers/getAdyenPaymentApiUrl.js +++ /dev/null @@ -1,11 +0,0 @@ -define([ - 'Adyen_ExpressCheckout/js/model/config' -], function (configModel) { - 'use strict'; - - return function (uri) { - const config = configModel().getConfig(); - - return 'rest/' + config.storeCode + '/V1/internal/adyen/' + uri; - }; -}); From 3eb4da427d05cc58b9d75e3c20bd7a31d02a3644 Mon Sep 17 00:00:00 2001 From: RokPopov Date: Fri, 2 Jun 2023 10:42:11 +0200 Subject: [PATCH 6/6] version bump --- composer.json | 2 +- etc/module.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 5022299..b5a63e4 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "adyen/adyen-magento2-expresscheckout", "description": "Official Adyen Magento2 plugin to add express payment method shortcuts.", "type": "magento2-module", - "version": "1.0.0", + "version": "1.1.0", "license": "MIT", "repositories": [ { diff --git a/etc/module.xml b/etc/module.xml index 4c2c8c3..c75747d 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -11,7 +11,7 @@ */ --> - +