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 45c79d64 authored by cyattilakiss's avatar cyattilakiss Committed by GitHub

Use OrderId to get Order instead of using the session (#691)

For PWA integrations session is not necessarily accessible
OrderId is in the response from the payment-information endpoint, send
it back for all threeDS2 api calls
parent c2495e1c
...@@ -37,17 +37,11 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface ...@@ -37,17 +37,11 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface
*/ */
private $adyenHelper; private $adyenHelper;
/** /**
* @var \Magento\Sales\Model\OrderFactory * @var \Magento\Sales\Model\OrderFactory
*/ */
private $orderFactory; private $orderFactory;
/**
* @var
*/
private $order;
/** /**
* @var \Adyen\Payment\Logger\AdyenLogger * @var \Adyen\Payment\Logger\AdyenLogger
*/ */
...@@ -58,6 +52,8 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface ...@@ -58,6 +52,8 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface
* *
* @param \Magento\Checkout\Model\Session $checkoutSession * @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Sales\Model\OrderFactory $orderFactory
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
*/ */
public function __construct( public function __construct(
\Magento\Checkout\Model\Session $checkoutSession, \Magento\Checkout\Model\Session $checkoutSession,
...@@ -87,8 +83,12 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface ...@@ -87,8 +83,12 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface
throw new \Magento\Framework\Exception\LocalizedException(__('3D secure 2.0 failed because the request was not a valid JSON')); throw new \Magento\Framework\Exception\LocalizedException(__('3D secure 2.0 failed because the request was not a valid JSON'));
} }
// Get payment and cart information from session if (empty($payload['orderId'])) {
$order = $this->getOrder(); throw new \Magento\Framework\Exception\LocalizedException(__('3D secure 2.0 failed because of a missing order id'));
}
// Create order by order id
$order = $this->orderFactory->create()->load($payload['orderId']);
$payment = $order->getPayment(); $payment = $order->getPayment();
// Init payments/details request // Init payments/details request
...@@ -139,7 +139,6 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface ...@@ -139,7 +139,6 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface
// To actually save the additional info changes into the quote // To actually save the additional info changes into the quote
$order->save(); $order->save();
$response = []; $response = [];
if($result['resultCode'] != 'Authorised') { if($result['resultCode'] != 'Authorised') {
...@@ -158,18 +157,4 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface ...@@ -158,18 +157,4 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface
$response['result'] = $result['resultCode']; $response['result'] = $result['resultCode'];
return json_encode($response); return json_encode($response);
} }
/**
* Get order object
*
* @return \Magento\Sales\Model\Order
*/
protected function getOrder()
{
if (!$this->order) {
$incrementId = $this->checkoutSession->getLastRealOrderId();
$this->order = $this->orderFactory->create()->loadByIncrementId($incrementId);
}
return $this->order;
}
} }
...@@ -213,7 +213,7 @@ define( ...@@ -213,7 +213,7 @@ define(
* @param type * @param type
* @param token * @param token
*/ */
renderThreeDS2Component: function (type, token) { renderThreeDS2Component: function (type, token, orderId) {
var self = this; var self = this;
var threeDS2Node = document.getElementById('threeDS2Container'); var threeDS2Node = document.getElementById('threeDS2Container');
...@@ -223,8 +223,10 @@ define( ...@@ -223,8 +223,10 @@ define(
fingerprintToken: token, fingerprintToken: token,
onComplete: function (result) { onComplete: function (result) {
self.threeDS2IdentifyComponent.unmount(); self.threeDS2IdentifyComponent.unmount();
threeds2.processThreeDS2(result.data).done(function (responseJSON) { var request = result.data;
self.validateThreeDS2OrPlaceOrder(responseJSON) request.orderId = orderId;
threeds2.processThreeDS2(request).done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON, orderId)
}).fail(function (result) { }).fail(function (result) {
errorProcessor.process(result, self.messageContainer); errorProcessor.process(result, self.messageContainer);
self.isPlaceOrderActionAllowed(true); self.isPlaceOrderActionAllowed(true);
...@@ -262,8 +264,10 @@ define( ...@@ -262,8 +264,10 @@ define(
self.threeDS2ChallengeComponent.unmount(); self.threeDS2ChallengeComponent.unmount();
self.closeModal(popupModal); self.closeModal(popupModal);
fullScreenLoader.startLoader(); fullScreenLoader.startLoader();
threeds2.processThreeDS2(result.data).done(function (responseJSON) { var request = result.data;
self.validateThreeDS2OrPlaceOrder(responseJSON); request.orderId = orderId;
threeds2.processThreeDS2(request).done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON, orderId);
}).fail(function (result) { }).fail(function (result) {
errorProcessor.process(result, self.messageContainer); errorProcessor.process(result, self.messageContainer);
self.isPlaceOrderActionAllowed(true); self.isPlaceOrderActionAllowed(true);
...@@ -357,11 +361,11 @@ define( ...@@ -357,11 +361,11 @@ define(
self.isPlaceOrderActionAllowed(true); self.isPlaceOrderActionAllowed(true);
} }
).done( ).done(
function (response) { function (orderId) {
self.afterPlaceOrder(); self.afterPlaceOrder();
adyenPaymentService.getOrderPaymentStatus(response) adyenPaymentService.getOrderPaymentStatus(orderId)
.done(function (responseJSON) { .done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON) self.validateThreeDS2OrPlaceOrder(responseJSON, orderId)
}); });
} }
); );
...@@ -372,13 +376,13 @@ define( ...@@ -372,13 +376,13 @@ define(
* Based on the response we can start a 3DS2 validation or place the order * Based on the response we can start a 3DS2 validation or place the order
* @param responseJSON * @param responseJSON
*/ */
validateThreeDS2OrPlaceOrder: function (responseJSON) { validateThreeDS2OrPlaceOrder: function (responseJSON, orderId) {
var self = this; var self = this;
var response = JSON.parse(responseJSON); var response = JSON.parse(responseJSON);
if (!!response.threeDS2) { if (!!response.threeDS2) {
// render component // render component
self.renderThreeDS2Component(response.type, response.token); self.renderThreeDS2Component(response.type, response.token, orderId);
} else { } else {
window.location.replace(url.build( window.location.replace(url.build(
window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl) window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl)
......
...@@ -231,11 +231,11 @@ define( ...@@ -231,11 +231,11 @@ define(
self.isPlaceOrderActionAllowed(true); self.isPlaceOrderActionAllowed(true);
} }
).done( ).done(
function (response) { function (orderId) {
self.afterPlaceOrder(); self.afterPlaceOrder();
adyenPaymentService.getOrderPaymentStatus(response) adyenPaymentService.getOrderPaymentStatus(orderId)
.done(function (responseJSON) { .done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON) self.validateThreeDS2OrPlaceOrder(responseJSON, orderId)
}); });
} }
); );
...@@ -310,13 +310,13 @@ define( ...@@ -310,13 +310,13 @@ define(
* Based on the response we can start a 3DS2 validation or place the order * Based on the response we can start a 3DS2 validation or place the order
* @param responseJSON * @param responseJSON
*/ */
validateThreeDS2OrPlaceOrder: function (responseJSON) { validateThreeDS2OrPlaceOrder: function (responseJSON, orderId) {
var self = this; var self = this;
var response = JSON.parse(responseJSON); var response = JSON.parse(responseJSON);
if (!!response.threeDS2) { if (!!response.threeDS2) {
// render component // render component
self.renderThreeDS2Component(response.type, response.token); self.renderThreeDS2Component(response.type, response.token, orderId);
} else { } else {
window.location.replace(url.build(window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl)); window.location.replace(url.build(window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl));
} }
...@@ -332,7 +332,7 @@ define( ...@@ -332,7 +332,7 @@ define(
* @param type * @param type
* @param token * @param token
*/ */
renderThreeDS2Component: function (type, token) { renderThreeDS2Component: function (type, token, orderId) {
var self = this; var self = this;
var threeDS2Node = document.getElementById('threeDS2ContainerOneClick'); var threeDS2Node = document.getElementById('threeDS2ContainerOneClick');
...@@ -341,8 +341,10 @@ define( ...@@ -341,8 +341,10 @@ define(
self.threeDS2Component = checkout.create('threeDS2DeviceFingerprint', { self.threeDS2Component = checkout.create('threeDS2DeviceFingerprint', {
fingerprintToken: token, fingerprintToken: token,
onComplete: function (result) { onComplete: function (result) {
threeds2.processThreeDS2(result.data).done(function (responseJSON) { var request = result.data;
self.validateThreeDS2OrPlaceOrder(responseJSON) request.orderId = orderId;
threeds2.processThreeDS2(request).done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON, orderId)
}).fail(function (result) { }).fail(function (result) {
errorProcessor.process(result, self.getMessageContainer()); errorProcessor.process(result, self.getMessageContainer());
self.isPlaceOrderActionAllowed(true); self.isPlaceOrderActionAllowed(true);
...@@ -375,8 +377,10 @@ define( ...@@ -375,8 +377,10 @@ define(
onComplete: function (result) { onComplete: function (result) {
popupModal.modal("closeModal"); popupModal.modal("closeModal");
fullScreenLoader.startLoader(); fullScreenLoader.startLoader();
threeds2.processThreeDS2(result.data).done(function (responseJSON) { var request = result.data;
self.validateThreeDS2OrPlaceOrder(responseJSON) request.orderId = orderId;
threeds2.processThreeDS2(request).done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON, orderId)
}).fail(function (result) { }).fail(function (result) {
errorProcessor.process(result, self.getMessageContainer()); errorProcessor.process(result, self.getMessageContainer());
self.isPlaceOrderActionAllowed(true); self.isPlaceOrderActionAllowed(true);
......
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