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 87c72deb authored by Ángel Campos's avatar Ángel Campos Committed by GitHub

[PW-2913] Adding redirect data builder to CC authorize requests (#799)

* [PW-2913] Adding redirect data builder to CC authorize requests

* Adding termUrl to redirect form

* Adding termUrl to redirect form

* Update Gateway/Validator/CheckoutResponseValidator.php
Co-authored-by: default avatarAttila Kiss <42297201+cyattilakiss@users.noreply.github.com>

* [PW-2913 ] Adjusting Redirect controller for new 3DS1 flow

* Removing redirect data builder from AdyenPaymentCcVaultAuthorizeRequest
Co-authored-by: default avatarAttila Kiss <42297201+cyattilakiss@users.noreply.github.com>
parent b541b3f8
......@@ -470,14 +470,15 @@ class Redirect extends \Magento\Payment\Block\Form
}
/**
* @return string
* @return mixed
*/
public function getTermUrl()
{
return $this->getUrl(
'adyen/process/redirect',
['_secure' => $this->_getRequest()->isSecure()]
);
if ($termUrl = $this->getPayment()->getAdditionalInformation('termUrl')) {
return $termUrl;
}
throw new AdyenException("No termUrl is provided.");
}
/**
......
......@@ -155,96 +155,97 @@ class Redirect extends \Magento\Framework\App\Action\Action
if ($active && $success != true) {
$this->_adyenLogger->addAdyenResult("3D secure is active");
// check if it is already processed
if ($this->getRequest()->isPost()) {
// check if the GET request contains the required 3DS params
if ($this->getRequest()->getParam('PaRes') && $this->getRequest()->getParam('MD')) {
$this->_adyenLogger->addAdyenResult("Process 3D secure payment");
$requestMD = $this->getRequest()->getPost('MD');
$requestPaRes = $this->getRequest()->getPost('PaRes');
$md = $order->getPayment()->getAdditionalInformation('md');
if ($requestMD == $md) {
$order->getPayment()->setAdditionalInformation('paResponse', $requestPaRes);
try {
$result = $this->_authorise3d($order->getPayment());
$responseCode = $result['resultCode'];
} catch (\Exception $e) {
$this->_adyenLogger->addAdyenResult("Process 3D secure payment was refused");
$responseCode = 'Refused';
}
$requestMD = $this->getRequest()->getParam('MD');
$requestPaRes = $this->getRequest()->getParam('PaRes');
//Reset the payment's additional info to the new MD and PaRes
$order->getPayment()->setAdditionalInformation('md', $requestMD);
$order->getPayment()->setAdditionalInformation('paRequest', $requestPaRes);
$this->_adyenLogger->addAdyenResult("Process 3D secure payment result is: " . $responseCode);
// check if authorise3d was successful
if ($responseCode == 'Authorised') {
$order->addStatusHistoryComment(__('3D-secure validation was successful'))->save();
// set back to false so when pressed back button on the success page
// it will reactivate 3D secure
$order->getPayment()->setAdditionalInformation('3dActive', '');
$order->getPayment()->setAdditionalInformation('3dSuccess', true);
if (!$this->_adyenHelper->isCreditCardVaultEnabled() &&
!empty($result['additionalData']['recurring.recurringDetailReference'])) {
$this->_adyenHelper->createAdyenBillingAgreement($order, $result['additionalData']);
} elseif (!empty($result['additionalData']['recurring.recurringDetailReference'])
) {
try {
$additionalData = $result['additionalData'];
$token = $additionalData['recurring.recurringDetailReference'];
$expirationDate = $additionalData['expiryDate'];
$cardType = $additionalData['paymentMethod'];
$cardSummary = $additionalData['cardSummary'];
/** @var PaymentTokenInterface $paymentToken */
$paymentToken = $this->paymentTokenFactory->create(
PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD
);
$paymentToken->setGatewayToken($token);
$paymentToken->setExpiresAt($this->getExpirationDate($expirationDate));
$details = [
'type' => $cardType,
'maskedCC' => $cardSummary,
'expirationDate' => $expirationDate
];
$paymentToken->setTokenDetails(json_encode($details));
$extensionAttributes = $this->getExtensionAttributes($order->getPayment());
$extensionAttributes->setVaultPaymentToken($paymentToken);
$orderPayment = $order->getPayment()->setExtensionAttributes($extensionAttributes);
$add = $this->serializer->unserialize($orderPayment->getAdditionalData());
$add['force_save'] = true;
$orderPayment->setAdditionalData($this->serializer->serialize($add));
$this->orderPaymentResource->save($orderPayment);
} catch (\Exception $e) {
$this->_adyenLogger->error((string)$e->getMessage());
}
$order->getPayment()->setAdditionalInformation('paResponse', $requestPaRes);
try {
$result = $this->_authorise3d($order->getPayment());
$responseCode = $result['resultCode'];
} catch (\Exception $e) {
$this->_adyenLogger->addAdyenResult("Process 3D secure payment was refused");
$responseCode = 'Refused';
}
$this->_adyenLogger->addAdyenResult("Process 3D secure payment result is: " . $responseCode);
// check if authorise3d was successful
if ($responseCode == 'Authorised') {
$order->addStatusHistoryComment(__('3D-secure validation was successful'))->save();
// set back to false so when pressed back button on the success page
// it will reactivate 3D secure
$order->getPayment()->setAdditionalInformation('3dActive', '');
$order->getPayment()->setAdditionalInformation('3dSuccess', true);
if (!$this->_adyenHelper->isCreditCardVaultEnabled() &&
!empty($result['additionalData']['recurring.recurringDetailReference'])) {
$this->_adyenHelper->createAdyenBillingAgreement($order, $result['additionalData']);
} elseif (!empty($result['additionalData']['recurring.recurringDetailReference'])
) {
try {
$additionalData = $result['additionalData'];
$token = $additionalData['recurring.recurringDetailReference'];
$expirationDate = $additionalData['expiryDate'];
$cardType = $additionalData['paymentMethod'];
$cardSummary = $additionalData['cardSummary'];
/** @var PaymentTokenInterface $paymentToken */
$paymentToken = $this->paymentTokenFactory->create(
PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD
);
$paymentToken->setGatewayToken($token);
$paymentToken->setExpiresAt($this->getExpirationDate($expirationDate));
$details = [
'type' => $cardType,
'maskedCC' => $cardSummary,
'expirationDate' => $expirationDate
];
$paymentToken->setTokenDetails(json_encode($details));
$extensionAttributes = $this->getExtensionAttributes($order->getPayment());
$extensionAttributes->setVaultPaymentToken($paymentToken);
$orderPayment = $order->getPayment()->setExtensionAttributes($extensionAttributes);
$add = $this->serializer->unserialize($orderPayment->getAdditionalData());
$add['force_save'] = true;
$orderPayment->setAdditionalData($this->serializer->serialize($add));
$this->orderPaymentResource->save($orderPayment);
} catch (\Exception $e) {
$this->_adyenLogger->error((string)$e->getMessage());
}
}
$this->_orderRepository->save($order);
$this->_redirect('checkout/onepage/success', ['_query' => ['utm_nooverride' => '1']]);
} else {
/*
* Since responseCode!='Authorised' the order could be cancelled immediately,
* but redirect payments can have multiple conflicting responses.
* The order will be cancelled if an Authorization
* Success=False notification is processed instead
*/
$order->addStatusHistoryComment(
__(
'3D-secure validation was unsuccessful. This order will be cancelled when the related
$this->_orderRepository->save($order);
$this->_redirect('checkout/onepage/success', ['_query' => ['utm_nooverride' => '1']]);
} else {
/*
* Since responseCode!='Authorised' the order could be cancelled immediately,
* but redirect payments can have multiple conflicting responses.
* The order will be cancelled if an Authorization
* Success=False notification is processed instead
*/
$order->addStatusHistoryComment(
__(
'3D-secure validation was unsuccessful. This order will be cancelled when the related
notification has been processed.'
)
)->save();
)
)->save();
$this->messageManager->addErrorMessage("3D-secure validation was unsuccessful");
$this->messageManager->addErrorMessage("3D-secure validation was unsuccessful");
// reactivate the quote
$session = $this->_getCheckout();
// reactivate the quote
$session = $this->_getCheckout();
// restore the quote
$session->restoreQuote();
// restore the quote
$session->restoreQuote();
$this->_redirect($this->_adyenHelper->getAdyenAbstractConfigData('return_path'));
}
$this->_redirect($this->_adyenHelper->getAdyenAbstractConfigData('return_path'));
}
} else {
$this->_adyenLogger->addAdyenResult("Customer was redirected to bank for 3D-secure validation.");
......
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2020 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Gateway\Request;
use Magento\Payment\Gateway\Request\BuilderInterface;
class RedirectDataBuilder implements BuilderInterface
{
/**
* @var \Magento\Framework\App\State
*/
private $appState;
/**
* @var \Adyen\Payment\Helper\Requests
*/
private $adyenRequestsHelper;
/**
* RedirectDataBuilder constructor.
*
* @param \Magento\Framework\Model\Context $context
* @param \Adyen\Payment\Helper\Requests $adyenRequestsHelper
*/
public function __construct(
\Magento\Framework\Model\Context $context,
\Adyen\Payment\Helper\Requests $adyenRequestsHelper
) {
$this->appState = $context->getAppState();
$this->adyenRequestsHelper = $adyenRequestsHelper;
}
/**
* @param array $buildSubject
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function build(array $buildSubject)
{
$request['body'] = $this->adyenRequestsHelper->buildRedirectData([]);
return $request;
}
}
......@@ -148,9 +148,14 @@ class CheckoutResponseValidator extends AbstractValidator
}
// If the redirect data is there then the payment is a card payment with 3d secure
if (isset($response['redirect']['data']['PaReq']) && isset($response['redirect']['data']['MD'])) {
if (
isset($response['redirect']['data']['PaReq']) &&
isset($response['redirect']['data']['MD']) &&
isset($response['redirect']['data']['TermUrl'])
) {
$paReq = null;
$md = null;
$termUrl = null;
$payment->setAdditionalInformation('3dActive', true);
......@@ -162,11 +167,16 @@ class CheckoutResponseValidator extends AbstractValidator
$md = $response['redirect']['data']['MD'];
}
if ($paReq && $md && $redirectUrl && $paymentData && $redirectMethod) {
if (!empty($response['redirect']['data']['TermUrl'])) {
$termUrl = $response['redirect']['data']['TermUrl'];
}
if ($paReq && $md && $termUrl && $redirectUrl && $paymentData && $redirectMethod) {
$payment->setAdditionalInformation('redirectUrl', $redirectUrl);
$payment->setAdditionalInformation('redirectMethod', $redirectMethod);
$payment->setAdditionalInformation('paRequest', $paReq);
$payment->setAdditionalInformation('md', $md);
$payment->setAdditionalInformation('termUrl', $termUrl);
$payment->setAdditionalInformation('paymentData', $paymentData);
} else {
$isValid = false;
......
......@@ -341,6 +341,19 @@ class Requests extends AbstractHelper
return $request;
}
/**
* @param array $request
* @return array
*/
public function buildRedirectData($request = [])
{
$request['redirectFromIssuerMethod'] = 'GET';
$request['redirectToIssuerMethod'] = 'POST';
$request['returnUrl'] = $this->adyenHelper->getOrigin() . '/adyen/process/redirect';
return $request;
}
/**
* @param $request
* @param $areaCode
......
......@@ -560,6 +560,7 @@
<item name="transaction" xsi:type="string">Adyen\Payment\Gateway\Request\CcAuthorizationDataBuilder</item>
<item name="vault" xsi:type="string">Adyen\Payment\Gateway\Request\VaultDataBuilder</item>
<item name="threeds2" xsi:type="string">Adyen\Payment\Gateway\Request\ThreeDS2DataBuilder</item>
<item name="redirect" xsi:type="string">Adyen\Payment\Gateway\Request\RedirectDataBuilder</item>
</argument>
</arguments>
</virtualType>
......@@ -607,6 +608,7 @@
<item name="recurring" xsi:type="string">Adyen\Payment\Gateway\Request\RecurringDataBuilder</item>
<item name="oneclick" xsi:type="string">Adyen\Payment\Gateway\Request\OneclickAuthorizationDataBuilder</item>
<item name="threeds2" xsi:type="string">Adyen\Payment\Gateway\Request\ThreeDS2DataBuilder</item>
<item name="redirect" xsi:type="string">Adyen\Payment\Gateway\Request\RedirectDataBuilder</item>
</argument>
</arguments>
</virtualType>
......
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