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
*/
private $adyenHelper;
/**
* @var \Magento\Sales\Model\OrderFactory
*/
private $orderFactory;
/**
* @var
*/
private $order;
/**
* @var \Adyen\Payment\Logger\AdyenLogger
*/
......@@ -58,6 +52,8 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface
*
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Sales\Model\OrderFactory $orderFactory
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
*/
public function __construct(
\Magento\Checkout\Model\Session $checkoutSession,
......@@ -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'));
}
// Get payment and cart information from session
$order = $this->getOrder();
if (empty($payload['orderId'])) {
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();
// Init payments/details request
......@@ -139,7 +139,6 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface
// To actually save the additional info changes into the quote
$order->save();
$response = [];
if($result['resultCode'] != 'Authorised') {
......@@ -158,18 +157,4 @@ class AdyenThreeDS2Process implements AdyenThreeDS2ProcessInterface
$response['result'] = $result['resultCode'];
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(
* @param type
* @param token
*/
renderThreeDS2Component: function (type, token) {
renderThreeDS2Component: function (type, token, orderId) {
var self = this;
var threeDS2Node = document.getElementById('threeDS2Container');
......@@ -223,8 +223,10 @@ define(
fingerprintToken: token,
onComplete: function (result) {
self.threeDS2IdentifyComponent.unmount();
threeds2.processThreeDS2(result.data).done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON)
var request = result.data;
request.orderId = orderId;
threeds2.processThreeDS2(request).done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON, orderId)
}).fail(function (result) {
errorProcessor.process(result, self.messageContainer);
self.isPlaceOrderActionAllowed(true);
......@@ -262,8 +264,10 @@ define(
self.threeDS2ChallengeComponent.unmount();
self.closeModal(popupModal);
fullScreenLoader.startLoader();
threeds2.processThreeDS2(result.data).done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON);
var request = result.data;
request.orderId = orderId;
threeds2.processThreeDS2(request).done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON, orderId);
}).fail(function (result) {
errorProcessor.process(result, self.messageContainer);
self.isPlaceOrderActionAllowed(true);
......@@ -357,11 +361,11 @@ define(
self.isPlaceOrderActionAllowed(true);
}
).done(
function (response) {
function (orderId) {
self.afterPlaceOrder();
adyenPaymentService.getOrderPaymentStatus(response)
adyenPaymentService.getOrderPaymentStatus(orderId)
.done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON)
self.validateThreeDS2OrPlaceOrder(responseJSON, orderId)
});
}
);
......@@ -372,13 +376,13 @@ define(
* Based on the response we can start a 3DS2 validation or place the order
* @param responseJSON
*/
validateThreeDS2OrPlaceOrder: function (responseJSON) {
validateThreeDS2OrPlaceOrder: function (responseJSON, orderId) {
var self = this;
var response = JSON.parse(responseJSON);
if (!!response.threeDS2) {
// render component
self.renderThreeDS2Component(response.type, response.token);
self.renderThreeDS2Component(response.type, response.token, orderId);
} else {
window.location.replace(url.build(
window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl)
......
......@@ -231,11 +231,11 @@ define(
self.isPlaceOrderActionAllowed(true);
}
).done(
function (response) {
function (orderId) {
self.afterPlaceOrder();
adyenPaymentService.getOrderPaymentStatus(response)
adyenPaymentService.getOrderPaymentStatus(orderId)
.done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON)
self.validateThreeDS2OrPlaceOrder(responseJSON, orderId)
});
}
);
......@@ -310,13 +310,13 @@ define(
* Based on the response we can start a 3DS2 validation or place the order
* @param responseJSON
*/
validateThreeDS2OrPlaceOrder: function (responseJSON) {
validateThreeDS2OrPlaceOrder: function (responseJSON, orderId) {
var self = this;
var response = JSON.parse(responseJSON);
if (!!response.threeDS2) {
// render component
self.renderThreeDS2Component(response.type, response.token);
self.renderThreeDS2Component(response.type, response.token, orderId);
} else {
window.location.replace(url.build(window.checkoutConfig.payment[quote.paymentMethod().method].redirectUrl));
}
......@@ -332,7 +332,7 @@ define(
* @param type
* @param token
*/
renderThreeDS2Component: function (type, token) {
renderThreeDS2Component: function (type, token, orderId) {
var self = this;
var threeDS2Node = document.getElementById('threeDS2ContainerOneClick');
......@@ -341,8 +341,10 @@ define(
self.threeDS2Component = checkout.create('threeDS2DeviceFingerprint', {
fingerprintToken: token,
onComplete: function (result) {
threeds2.processThreeDS2(result.data).done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON)
var request = result.data;
request.orderId = orderId;
threeds2.processThreeDS2(request).done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON, orderId)
}).fail(function (result) {
errorProcessor.process(result, self.getMessageContainer());
self.isPlaceOrderActionAllowed(true);
......@@ -375,8 +377,10 @@ define(
onComplete: function (result) {
popupModal.modal("closeModal");
fullScreenLoader.startLoader();
threeds2.processThreeDS2(result.data).done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON)
var request = result.data;
request.orderId = orderId;
threeds2.processThreeDS2(request).done(function (responseJSON) {
self.validateThreeDS2OrPlaceOrder(responseJSON, orderId)
}).fail(function (result) {
errorProcessor.process(result, self.getMessageContainer());
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