We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit 34cfc4a6 authored by cyattilakiss's avatar cyattilakiss Committed by GitHub

[PW 2022] Fix payment-information interceptor to work with other plugins (#643)

* Remove PaymentInformationManagement plugins

Delete GuestPaymentInformationManagement.php and
PaymentInformationManagement.php
Remove these from the interceptors list in di.xml

* Add new API endpoint to retrieve order payment status

* Only load 'return_path' config data if it's required. (#638)

* Only load 'return_path' config data if it's required.

It doesn't make sense to retrieve the configuration for failure on each request.
It's enough to only do it on failure.

* Update Controller/Process/Result.php
Co-Authored-By: default avatarcyattilakiss <42297201+cyattilakiss@users.noreply.github.com>

* Add AdyenOrderPaymentStatus class to retrieve order payment status

Add getOrderPaymentStatus() to handle threeDS2 extra steps but nothing
more
Later this function can be used for more extensive PWA implementation

* Add getOrderPaymentStatus() to consume the /payment-status API endpoint

Use the new method in the placeOrder() function in the
adyen-cc-method.js

* Remove excess comma
Co-Authored-By: default avatarAlessio Zampatti <alessio.zampatti@adyen.com>

* [PW-2022] changes to get it working (#650)

* Update return value to a more specific one

* Remove unused variables

* Improve code readability

* Improve code readability

* Improve code readability

* Work in progress changes

* removed throw exception as we are not doing anything on the front-end. Fix front-end to work with code changes as well include oneclick into the solution as this was now broken with all the changes.

* remove let as this is not supported in older browsers

* remove debugger statements
Co-authored-by: default avatarFabian Hurnaus <fahu@outlook.com>
Co-authored-by: default avatarRik ter Beek <rikterbeek@users.noreply.github.com>
Co-authored-by: default avatarMarcos Garcia <marcos.asgarcia@gmail.com>
Co-authored-by: default avatarAlessio Zampatti <gigendh@gmail.com>
parent 8897c847
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
*
* Copyright (c) 2020 Adyen B.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Api;
interface AdyenOrderPaymentStatusInterface
{
/**
* @param string $orderId
* @return string
*/
public function getOrderPaymentStatus($orderId);
}
...@@ -13,23 +13,22 @@ ...@@ -13,23 +13,22 @@
* ############# * #############
* ############ * ############
* *
* Adyen Payment module (https://www.adyen.com/) * Adyen Payment Module
* *
* Copyright (c) 2019 Adyen BV (https://www.adyen.com/) * Copyright (c) 2020 Adyen B.V.
* See LICENSE.txt for license details. * This file is open source and available under the MIT license.
* See the LICENSE file for more info.
* *
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
namespace Adyen\Payment\Plugin; namespace Adyen\Payment\Model;
use Adyen\Payment\Model\Ui\AdyenCcConfigProvider; use Adyen\Payment\Model\Ui\AdyenCcConfigProvider;
use Adyen\Payment\Model\Ui\AdyenOneclickConfigProvider; use Adyen\Payment\Model\Ui\AdyenOneclickConfigProvider;
class PaymentInformationManagement class AdyenOrderPaymentStatus implements \Adyen\Payment\Api\AdyenOrderPaymentStatusInterface
{ {
/** /**
* @var \Magento\Sales\Api\OrderRepositoryInterface * @var \Magento\Sales\Api\OrderRepositoryInterface
*/ */
...@@ -46,7 +45,8 @@ class PaymentInformationManagement ...@@ -46,7 +45,8 @@ class PaymentInformationManagement
protected $adyenHelper; protected $adyenHelper;
/** /**
* PaymentInformationManagement constructor. * AdyenOrderPaymentStatus constructor.
*
* @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger * @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
...@@ -62,32 +62,23 @@ class PaymentInformationManagement ...@@ -62,32 +62,23 @@ class PaymentInformationManagement
} }
/** /**
* @param \Magento\Checkout\Api\PaymentInformationManagementInterface $subject * @param string $orderId
* @param $result * @return bool|string
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/ */
public function afterSavePaymentInformationAndPlaceOrder( public function getOrderPaymentStatus($orderId)
\Magento\Checkout\Api\PaymentInformationManagementInterface $subject, {
$result $order = $this->orderRepository->get($orderId);
) { $payment = $order->getPayment();
try {
$order = $this->orderRepository->get($result);
$payment = $order->getPayment();
if ($payment->getMethod() === AdyenCcConfigProvider::CODE || if ($payment->getMethod() === AdyenCcConfigProvider::CODE ||
$payment->getMethod() === AdyenOneclickConfigProvider::CODE $payment->getMethod() === AdyenOneclickConfigProvider::CODE
) { ) {
return $this->adyenHelper->buildThreeDS2ProcessResponseJson($payment->getAdditionalInformation('threeDSType'), $additionalInformation = $payment->getAdditionalInformation();
$payment->getAdditionalInformation('threeDS2Token')); return $this->adyenHelper->buildThreeDS2ProcessResponseJson(
} else { $additionalInformation['threeDSType'],
return $result; $additionalInformation['threeDS2Token']
} );
} catch (NoSuchEntityException $e) {
$this->adyenLogger->error("Exception: " . $e->getMessage());
throw new \Magento\Framework\Exception\LocalizedException(__('This order no longer exists.'));
} }
return true;
return $result;
} }
} }
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2019 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Plugin;
use Adyen\Payment\Model\Ui\AdyenCcConfigProvider;
class GuestPaymentInformationManagement
{
/**
* @var \Magento\Sales\Api\OrderRepositoryInterface
*/
protected $orderRepository;
/**
* @var \Adyen\Payment\Logger\AdyenLogger
*/
protected $adyenLogger;
/**
* @var \Adyen\Payment\Helper\Data
*/
protected $adyenHelper;
/**
* GuestPaymentInformationManagement constructor.
*
* @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Adyen\Payment\Helper\Data $adyenHelper
) {
$this->orderRepository = $orderRepository;
$this->adyenLogger = $adyenLogger;
$this->adyenHelper = $adyenHelper;
}
/**
* @param \Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject
* @param $result
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function afterSavePaymentInformationAndPlaceOrder(
\Magento\Checkout\Api\GuestPaymentInformationManagementInterface $subject,
$result
) {
try {
$order = $this->orderRepository->get($result);
$payment = $order->getPayment();
if ($payment->getMethod() === AdyenCcConfigProvider::CODE) {
return $this->adyenHelper->buildThreeDS2ProcessResponseJson(
$payment->getAdditionalInformation('threeDSType'),
$payment->getAdditionalInformation('threeDS2Token')
);
} else {
return $result;
}
} catch (NoSuchEntityException $e) {
$this->adyenLogger->error("Exception: " . $e->getMessage());
throw new \Magento\Framework\Exception\LocalizedException(__('This order no longer exists.'));
}
return $result;
}
}
...@@ -1026,15 +1026,11 @@ ...@@ -1026,15 +1026,11 @@
type="Adyen\Payment\Model\AdyenThreeDS2Process"/> type="Adyen\Payment\Model\AdyenThreeDS2Process"/>
<preference for="Adyen\Payment\Api\AdyenOriginKeyInterface" <preference for="Adyen\Payment\Api\AdyenOriginKeyInterface"
type="Adyen\Payment\Model\AdyenOriginKey"/> type="Adyen\Payment\Model\AdyenOriginKey"/>
<preference for="Adyen\Payment\Api\AdyenOrderPaymentStatusInterface"
type="Adyen\Payment\Model\AdyenOrderPaymentStatus"/>
<type name="Magento\Vault\Api\PaymentTokenRepositoryInterface"> <type name="Magento\Vault\Api\PaymentTokenRepositoryInterface">
<plugin name="AdyenPaymentVaultDeleteToken" type="Adyen\Payment\Plugin\PaymentVaultDeleteToken" sortOrder="10"/> <plugin name="AdyenPaymentVaultDeleteToken" type="Adyen\Payment\Plugin\PaymentVaultDeleteToken" sortOrder="10"/>
</type> </type>
<type name="Magento\Checkout\Api\PaymentInformationManagementInterface">
<plugin name="AdyenPaymentInformationManagementAddPaymentInfo" type="Adyen\Payment\Plugin\PaymentInformationManagement" sortOrder="10"/>
</type>
<type name="Magento\Checkout\Api\GuestPaymentInformationManagementInterface">
<plugin name="AdyenGuestPaymentInformationManagementAddPaymentInfo" type="Adyen\Payment\Plugin\GuestPaymentInformationManagement" sortOrder="10"/>
</type>
<!--Notifications overview--> <!--Notifications overview-->
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory"> <type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
...@@ -1050,5 +1046,4 @@ ...@@ -1050,5 +1046,4 @@
<argument name="resourceModel" xsi:type="string">Adyen\Payment\Model\ResourceModel\Notification</argument> <argument name="resourceModel" xsi:type="string">Adyen\Payment\Model\ResourceModel\Notification</argument>
</arguments> </arguments>
</virtualType> </virtualType>
</config> </config>
...@@ -71,4 +71,11 @@ ...@@ -71,4 +71,11 @@
<resource ref="anonymous"/> <resource ref="anonymous"/>
</resources> </resources>
</route> </route>
</routes>
\ No newline at end of file <route url="/V1/adyen/orders/:orderId/payment-status" method="GET">
<service class="Adyen\Payment\Api\AdyenOrderPaymentStatusInterface" method="getOrderPaymentStatus"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
</routes>
...@@ -61,10 +61,17 @@ define( ...@@ -61,10 +61,17 @@ define(
} }
} }
).fail( ).fail(
function (response) { function () {
self.setPaymentMethods([]); self.setPaymentMethods([]);
} }
) )
},
getOrderPaymentStatus: function (orderId) {
var serviceUrl = urlBuilder.createUrl('/adyen/orders/:orderId/payment-status', {
orderId: orderId
});
return storage.get(serviceUrl);
} }
}; };
} }
......
...@@ -38,9 +38,30 @@ define( ...@@ -38,9 +38,30 @@ define(
'Magento_Checkout/js/action/select-payment-method', 'Magento_Checkout/js/action/select-payment-method',
'Adyen_Payment/js/threeds2-js-utils', 'Adyen_Payment/js/threeds2-js-utils',
'Adyen_Payment/js/model/threeds2', 'Adyen_Payment/js/model/threeds2',
'Magento_Checkout/js/model/error-processor' 'Magento_Checkout/js/model/error-processor',
'Adyen_Payment/js/model/adyen-payment-service'
], ],
function ($, ko, Component, customer, creditCardData, additionalValidators, quote, installmentsHelper, url, VaultEnabler, urlBuilder, storage, fullScreenLoader, setPaymentMethodAction, selectPaymentMethodAction, threeDS2Utils, threeds2, errorProcessor) { function (
$,
ko,
Component,
customer,
creditCardData,
additionalValidators,
quote,
installmentsHelper,
url,
VaultEnabler,
urlBuilder,
storage,
fullScreenLoader,
setPaymentMethodAction,
selectPaymentMethodAction,
threeDS2Utils,
threeds2,
errorProcessor,
adyenPaymentService
) {
'use strict'; 'use strict';
...@@ -103,7 +124,7 @@ define( ...@@ -103,7 +124,7 @@ define(
* set up the installments * set up the installments
*/ */
renderSecureFields: function () { renderSecureFields: function () {
let self = this; var self = this;
if (!self.getOriginKey()) { if (!self.getOriginKey()) {
return; return;
...@@ -112,8 +133,8 @@ define( ...@@ -112,8 +133,8 @@ define(
self.installments(0); self.installments(0);
// installments // installments
let allInstallments = self.getAllInstallments(); var allInstallments = self.getAllInstallments();
let cardNode = document.getElementById('cardContainer'); var cardNode = document.getElementById('cardContainer');
self.cardComponent = self.checkout.create('card', { self.cardComponent = self.checkout.create('card', {
originKey: self.getOriginKey(), originKey: self.getOriginKey(),
...@@ -146,15 +167,15 @@ define( ...@@ -146,15 +167,15 @@ define(
if (creditCardType) { if (creditCardType) {
// If the credit card type is already set, check if it changed or not // If the credit card type is already set, check if it changed or not
if (!self.creditCardType() || self.creditCardType() && self.creditCardType() != creditCardType) { if (!self.creditCardType() || self.creditCardType() && self.creditCardType() != creditCardType) {
let numberOfInstallments = []; var numberOfInstallments = [];
if (creditCardType in allInstallments) { if (creditCardType in allInstallments) {
// get for the creditcard the installments // get for the creditcard the installments
let installmentCreditcard = allInstallments[creditCardType]; var installmentCreditcard = allInstallments[creditCardType];
let grandTotal = quote.totals().grand_total; var grandTotal = quote.totals().grand_total;
let precision = quote.getPriceFormat().precision; var precision = quote.getPriceFormat().precision;
let currencyCode = quote.totals().quote_currency_code; var currencyCode = quote.totals().quote_currency_code;
numberOfInstallments = installmentsHelper.getInstallmentsWithPrices(installmentCreditcard, grandTotal, precision, currencyCode); numberOfInstallments = installmentsHelper.getInstallmentsWithPrices(installmentCreditcard, grandTotal, precision, currencyCode);
} }
...@@ -229,7 +250,6 @@ define( ...@@ -229,7 +250,6 @@ define(
modalClass: 'threeDS2Modal' modalClass: 'threeDS2Modal'
}); });
popupModal.modal("openModal"); popupModal.modal("openModal");
self.threeDS2ChallengeComponent = self.checkout self.threeDS2ChallengeComponent = self.checkout
...@@ -239,7 +259,6 @@ define( ...@@ -239,7 +259,6 @@ define(
onComplete: function (result) { onComplete: function (result) {
self.threeDS2ChallengeComponent.unmount(); self.threeDS2ChallengeComponent.unmount();
self.closeModal(popupModal); self.closeModal(popupModal);
fullScreenLoader.startLoader(); fullScreenLoader.startLoader();
threeds2.processThreeDS2(result.data).done(function (responseJSON) { threeds2.processThreeDS2(result.data).done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON); self.validateThreeDS2OrPlaceOrder(responseJSON);
...@@ -338,7 +357,10 @@ define( ...@@ -338,7 +357,10 @@ define(
).done( ).done(
function (response) { function (response) {
self.afterPlaceOrder(); self.afterPlaceOrder();
self.validateThreeDS2OrPlaceOrder(response); adyenPaymentService.getOrderPaymentStatus(response)
.done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON)
});
} }
); );
} }
......
...@@ -40,9 +40,32 @@ define( ...@@ -40,9 +40,32 @@ define(
'mage/storage', 'mage/storage',
'Magento_Checkout/js/action/place-order', 'Magento_Checkout/js/action/place-order',
'Adyen_Payment/js/model/threeds2', 'Adyen_Payment/js/model/threeds2',
'Magento_Checkout/js/model/error-processor' 'Magento_Checkout/js/model/error-processor',
'Adyen_Payment/js/model/adyen-payment-service'
], ],
function (ko, _, $, Component, selectPaymentMethodAction, additionalValidators, quote, checkoutData, redirectOnSuccessAction, layout, Messages, url, threeDS2Utils, fullScreenLoader, setPaymentMethodAction, urlBuilder, storage, placeOrderAction, threeds2, errorProcessor) { function (
ko,
_,
$,
Component,
selectPaymentMethodAction,
additionalValidators,
quote,
checkoutData,
redirectOnSuccessAction,
layout,
Messages,
url,
threeDS2Utils,
fullScreenLoader,
setPaymentMethodAction,
urlBuilder,
storage,
placeOrderAction,
threeds2,
errorProcessor,
adyenPaymentService
) {
'use strict'; 'use strict';
...@@ -210,7 +233,10 @@ define( ...@@ -210,7 +233,10 @@ define(
).done( ).done(
function (response) { function (response) {
self.afterPlaceOrder(); self.afterPlaceOrder();
self.validateThreeDS2OrPlaceOrder(response); adyenPaymentService.getOrderPaymentStatus(response)
.done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON)
});
} }
); );
} }
......
...@@ -60,15 +60,15 @@ define( ...@@ -60,15 +60,15 @@ define(
}, },
initialize: function () { initialize: function () {
this._super(); this._super();
let self = this; var self = this;
// installments // installments
let allInstallments = self.getAllInstallments(); var allInstallments = self.getAllInstallments();
let grandTotal = quote.totals().grand_total; var grandTotal = quote.totals().grand_total;
let precision = quote.getPriceFormat().precision; var precision = quote.getPriceFormat().precision;
let currencyCode = quote.totals().quote_currency_code; var currencyCode = quote.totals().quote_currency_code;
let numberOfInstallments = installmentsHelper.getInstallmentsWithPrices(allInstallments, grandTotal, precision, currencyCode); var numberOfInstallments = installmentsHelper.getInstallmentsWithPrices(allInstallments, grandTotal, precision, currencyCode);
if (numberOfInstallments) { if (numberOfInstallments) {
self.installments(numberOfInstallments); self.installments(numberOfInstallments);
...@@ -86,7 +86,7 @@ define( ...@@ -86,7 +86,7 @@ define(
serviceUrl = urlBuilder.createUrl('/adyen/initiate', {}); serviceUrl = urlBuilder.createUrl('/adyen/initiate', {});
fullScreenLoader.startLoader(); fullScreenLoader.startLoader();
let payload = { var payload = {
"payload": JSON.stringify({ "payload": JSON.stringify({
terminal_id: self.terminalId(), terminal_id: self.terminalId(),
number_of_installments: self.installment() number_of_installments: self.installment()
...@@ -129,10 +129,10 @@ define( ...@@ -129,10 +129,10 @@ define(
) )
}, },
getConnectedTerminals: function() { getConnectedTerminals: function() {
let connectedTerminals = []; var connectedTerminals = [];
const connectedTerminalsList = window.checkoutConfig.payment.adyenPos.connectedTerminals; const connectedTerminalsList = window.checkoutConfig.payment.adyenPos.connectedTerminals;
for (let i = 0; i < connectedTerminalsList.length; i++) { for (var i = 0; i < connectedTerminalsList.length; i++) {
connectedTerminals.push( connectedTerminals.push(
{ {
key: connectedTerminalsList[i], key: connectedTerminalsList[i],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment