We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) 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 @@
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
* Adyen Payment Module
*
* Copyright (c) 2019 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
* 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\Plugin;
namespace Adyen\Payment\Model;
use Adyen\Payment\Model\Ui\AdyenCcConfigProvider;
use Adyen\Payment\Model\Ui\AdyenOneclickConfigProvider;
class PaymentInformationManagement
class AdyenOrderPaymentStatus implements \Adyen\Payment\Api\AdyenOrderPaymentStatusInterface
{
/**
* @var \Magento\Sales\Api\OrderRepositoryInterface
*/
......@@ -46,7 +45,8 @@ class PaymentInformationManagement
protected $adyenHelper;
/**
* PaymentInformationManagement constructor.
* AdyenOrderPaymentStatus constructor.
*
* @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param \Adyen\Payment\Helper\Data $adyenHelper
......@@ -62,32 +62,23 @@ class PaymentInformationManagement
}
/**
* @param \Magento\Checkout\Api\PaymentInformationManagementInterface $subject
* @param $result
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
* @param string $orderId
* @return bool|string
*/
public function afterSavePaymentInformationAndPlaceOrder(
\Magento\Checkout\Api\PaymentInformationManagementInterface $subject,
$result
) {
try {
$order = $this->orderRepository->get($result);
$payment = $order->getPayment();
public function getOrderPaymentStatus($orderId)
{
$order = $this->orderRepository->get($orderId);
$payment = $order->getPayment();
if ($payment->getMethod() === AdyenCcConfigProvider::CODE ||
$payment->getMethod() === AdyenOneclickConfigProvider::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.'));
if ($payment->getMethod() === AdyenCcConfigProvider::CODE ||
$payment->getMethod() === AdyenOneclickConfigProvider::CODE
) {
$additionalInformation = $payment->getAdditionalInformation();
return $this->adyenHelper->buildThreeDS2ProcessResponseJson(
$additionalInformation['threeDSType'],
$additionalInformation['threeDS2Token']
);
}
return $result;
return true;
}
}
<?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 @@
type="Adyen\Payment\Model\AdyenThreeDS2Process"/>
<preference for="Adyen\Payment\Api\AdyenOriginKeyInterface"
type="Adyen\Payment\Model\AdyenOriginKey"/>
<preference for="Adyen\Payment\Api\AdyenOrderPaymentStatusInterface"
type="Adyen\Payment\Model\AdyenOrderPaymentStatus"/>
<type name="Magento\Vault\Api\PaymentTokenRepositoryInterface">
<plugin name="AdyenPaymentVaultDeleteToken" type="Adyen\Payment\Plugin\PaymentVaultDeleteToken" sortOrder="10"/>
</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-->
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
......@@ -1050,5 +1046,4 @@
<argument name="resourceModel" xsi:type="string">Adyen\Payment\Model\ResourceModel\Notification</argument>
</arguments>
</virtualType>
</config>
......@@ -71,4 +71,11 @@
<resource ref="anonymous"/>
</resources>
</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(
}
}
).fail(
function (response) {
function () {
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(
'Magento_Checkout/js/action/select-payment-method',
'Adyen_Payment/js/threeds2-js-utils',
'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';
......@@ -103,7 +124,7 @@ define(
* set up the installments
*/
renderSecureFields: function () {
let self = this;
var self = this;
if (!self.getOriginKey()) {
return;
......@@ -112,8 +133,8 @@ define(
self.installments(0);
// installments
let allInstallments = self.getAllInstallments();
let cardNode = document.getElementById('cardContainer');
var allInstallments = self.getAllInstallments();
var cardNode = document.getElementById('cardContainer');
self.cardComponent = self.checkout.create('card', {
originKey: self.getOriginKey(),
......@@ -146,15 +167,15 @@ define(
if (creditCardType) {
// If the credit card type is already set, check if it changed or not
if (!self.creditCardType() || self.creditCardType() && self.creditCardType() != creditCardType) {
let numberOfInstallments = [];
var numberOfInstallments = [];
if (creditCardType in allInstallments) {
// get for the creditcard the installments
let installmentCreditcard = allInstallments[creditCardType];
let grandTotal = quote.totals().grand_total;
let precision = quote.getPriceFormat().precision;
let currencyCode = quote.totals().quote_currency_code;
var installmentCreditcard = allInstallments[creditCardType];
var grandTotal = quote.totals().grand_total;
var precision = quote.getPriceFormat().precision;
var currencyCode = quote.totals().quote_currency_code;
numberOfInstallments = installmentsHelper.getInstallmentsWithPrices(installmentCreditcard, grandTotal, precision, currencyCode);
}
......@@ -229,7 +250,6 @@ define(
modalClass: 'threeDS2Modal'
});
popupModal.modal("openModal");
self.threeDS2ChallengeComponent = self.checkout
......@@ -239,7 +259,6 @@ define(
onComplete: function (result) {
self.threeDS2ChallengeComponent.unmount();
self.closeModal(popupModal);
fullScreenLoader.startLoader();
threeds2.processThreeDS2(result.data).done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON);
......@@ -338,7 +357,10 @@ define(
).done(
function (response) {
self.afterPlaceOrder();
self.validateThreeDS2OrPlaceOrder(response);
adyenPaymentService.getOrderPaymentStatus(response)
.done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON)
});
}
);
}
......
......@@ -40,9 +40,32 @@ define(
'mage/storage',
'Magento_Checkout/js/action/place-order',
'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';
......@@ -210,7 +233,10 @@ define(
).done(
function (response) {
self.afterPlaceOrder();
self.validateThreeDS2OrPlaceOrder(response);
adyenPaymentService.getOrderPaymentStatus(response)
.done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON)
});
}
);
}
......
......@@ -60,15 +60,15 @@ define(
},
initialize: function () {
this._super();
let self = this;
var self = this;
// installments
let allInstallments = self.getAllInstallments();
let grandTotal = quote.totals().grand_total;
let precision = quote.getPriceFormat().precision;
let currencyCode = quote.totals().quote_currency_code;
var allInstallments = self.getAllInstallments();
var grandTotal = quote.totals().grand_total;
var precision = quote.getPriceFormat().precision;
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) {
self.installments(numberOfInstallments);
......@@ -86,7 +86,7 @@ define(
serviceUrl = urlBuilder.createUrl('/adyen/initiate', {});
fullScreenLoader.startLoader();
let payload = {
var payload = {
"payload": JSON.stringify({
terminal_id: self.terminalId(),
number_of_installments: self.installment()
......@@ -129,10 +129,10 @@ define(
)
},
getConnectedTerminals: function() {
let connectedTerminals = [];
var 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(
{
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