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 ...@@ -470,14 +470,15 @@ class Redirect extends \Magento\Payment\Block\Form
} }
/** /**
* @return string * @return mixed
*/ */
public function getTermUrl() public function getTermUrl()
{ {
return $this->getUrl( if ($termUrl = $this->getPayment()->getAdditionalInformation('termUrl')) {
'adyen/process/redirect', return $termUrl;
['_secure' => $this->_getRequest()->isSecure()] }
);
throw new AdyenException("No termUrl is provided.");
} }
/** /**
......
...@@ -155,96 +155,97 @@ class Redirect extends \Magento\Framework\App\Action\Action ...@@ -155,96 +155,97 @@ class Redirect extends \Magento\Framework\App\Action\Action
if ($active && $success != true) { if ($active && $success != true) {
$this->_adyenLogger->addAdyenResult("3D secure is active"); $this->_adyenLogger->addAdyenResult("3D secure is active");
// check if it is already processed // check if the GET request contains the required 3DS params
if ($this->getRequest()->isPost()) { if ($this->getRequest()->getParam('PaRes') && $this->getRequest()->getParam('MD')) {
$this->_adyenLogger->addAdyenResult("Process 3D secure payment"); $this->_adyenLogger->addAdyenResult("Process 3D secure payment");
$requestMD = $this->getRequest()->getPost('MD'); $requestMD = $this->getRequest()->getParam('MD');
$requestPaRes = $this->getRequest()->getPost('PaRes'); $requestPaRes = $this->getRequest()->getParam('PaRes');
$md = $order->getPayment()->getAdditionalInformation('md');
//Reset the payment's additional info to the new MD and PaRes
if ($requestMD == $md) { $order->getPayment()->setAdditionalInformation('md', $requestMD);
$order->getPayment()->setAdditionalInformation('paResponse', $requestPaRes); $order->getPayment()->setAdditionalInformation('paRequest', $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); $order->getPayment()->setAdditionalInformation('paResponse', $requestPaRes);
// check if authorise3d was successful try {
if ($responseCode == 'Authorised') { $result = $this->_authorise3d($order->getPayment());
$order->addStatusHistoryComment(__('3D-secure validation was successful'))->save(); $responseCode = $result['resultCode'];
// set back to false so when pressed back button on the success page } catch (\Exception $e) {
// it will reactivate 3D secure $this->_adyenLogger->addAdyenResult("Process 3D secure payment was refused");
$order->getPayment()->setAdditionalInformation('3dActive', ''); $responseCode = 'Refused';
$order->getPayment()->setAdditionalInformation('3dSuccess', true); }
if (!$this->_adyenHelper->isCreditCardVaultEnabled() && $this->_adyenLogger->addAdyenResult("Process 3D secure payment result is: " . $responseCode);
!empty($result['additionalData']['recurring.recurringDetailReference'])) {
$this->_adyenHelper->createAdyenBillingAgreement($order, $result['additionalData']); // check if authorise3d was successful
} elseif (!empty($result['additionalData']['recurring.recurringDetailReference']) if ($responseCode == 'Authorised') {
) { $order->addStatusHistoryComment(__('3D-secure validation was successful'))->save();
try { // set back to false so when pressed back button on the success page
$additionalData = $result['additionalData']; // it will reactivate 3D secure
$token = $additionalData['recurring.recurringDetailReference']; $order->getPayment()->setAdditionalInformation('3dActive', '');
$expirationDate = $additionalData['expiryDate']; $order->getPayment()->setAdditionalInformation('3dSuccess', true);
$cardType = $additionalData['paymentMethod'];
$cardSummary = $additionalData['cardSummary']; if (!$this->_adyenHelper->isCreditCardVaultEnabled() &&
/** @var PaymentTokenInterface $paymentToken */ !empty($result['additionalData']['recurring.recurringDetailReference'])) {
$paymentToken = $this->paymentTokenFactory->create( $this->_adyenHelper->createAdyenBillingAgreement($order, $result['additionalData']);
PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD } elseif (!empty($result['additionalData']['recurring.recurringDetailReference'])
); ) {
$paymentToken->setGatewayToken($token); try {
$paymentToken->setExpiresAt($this->getExpirationDate($expirationDate)); $additionalData = $result['additionalData'];
$details = [ $token = $additionalData['recurring.recurringDetailReference'];
'type' => $cardType, $expirationDate = $additionalData['expiryDate'];
'maskedCC' => $cardSummary, $cardType = $additionalData['paymentMethod'];
'expirationDate' => $expirationDate $cardSummary = $additionalData['cardSummary'];
]; /** @var PaymentTokenInterface $paymentToken */
$paymentToken->setTokenDetails(json_encode($details)); $paymentToken = $this->paymentTokenFactory->create(
$extensionAttributes = $this->getExtensionAttributes($order->getPayment()); PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD
$extensionAttributes->setVaultPaymentToken($paymentToken); );
$orderPayment = $order->getPayment()->setExtensionAttributes($extensionAttributes); $paymentToken->setGatewayToken($token);
$add = $this->serializer->unserialize($orderPayment->getAdditionalData()); $paymentToken->setExpiresAt($this->getExpirationDate($expirationDate));
$add['force_save'] = true; $details = [
$orderPayment->setAdditionalData($this->serializer->serialize($add)); 'type' => $cardType,
$this->orderPaymentResource->save($orderPayment); 'maskedCC' => $cardSummary,
} catch (\Exception $e) { 'expirationDate' => $expirationDate
$this->_adyenLogger->error((string)$e->getMessage()); ];
} $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->_orderRepository->save($order);
$this->_redirect('checkout/onepage/success', ['_query' => ['utm_nooverride' => '1']]); $this->_redirect('checkout/onepage/success', ['_query' => ['utm_nooverride' => '1']]);
} else { } else {
/* /*
* Since responseCode!='Authorised' the order could be cancelled immediately, * Since responseCode!='Authorised' the order could be cancelled immediately,
* but redirect payments can have multiple conflicting responses. * but redirect payments can have multiple conflicting responses.
* The order will be cancelled if an Authorization * The order will be cancelled if an Authorization
* Success=False notification is processed instead * Success=False notification is processed instead
*/ */
$order->addStatusHistoryComment( $order->addStatusHistoryComment(
__( __(
'3D-secure validation was unsuccessful. This order will be cancelled when the related '3D-secure validation was unsuccessful. This order will be cancelled when the related
notification has been processed.' 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 // reactivate the quote
$session = $this->_getCheckout(); $session = $this->_getCheckout();
// restore the quote // restore the quote
$session->restoreQuote(); $session->restoreQuote();
$this->_redirect($this->_adyenHelper->getAdyenAbstractConfigData('return_path')); $this->_redirect($this->_adyenHelper->getAdyenAbstractConfigData('return_path'));
}
} }
} else { } else {
$this->_adyenLogger->addAdyenResult("Customer was redirected to bank for 3D-secure validation."); $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 ...@@ -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 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; $paReq = null;
$md = null; $md = null;
$termUrl = null;
$payment->setAdditionalInformation('3dActive', true); $payment->setAdditionalInformation('3dActive', true);
...@@ -162,11 +167,16 @@ class CheckoutResponseValidator extends AbstractValidator ...@@ -162,11 +167,16 @@ class CheckoutResponseValidator extends AbstractValidator
$md = $response['redirect']['data']['MD']; $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('redirectUrl', $redirectUrl);
$payment->setAdditionalInformation('redirectMethod', $redirectMethod); $payment->setAdditionalInformation('redirectMethod', $redirectMethod);
$payment->setAdditionalInformation('paRequest', $paReq); $payment->setAdditionalInformation('paRequest', $paReq);
$payment->setAdditionalInformation('md', $md); $payment->setAdditionalInformation('md', $md);
$payment->setAdditionalInformation('termUrl', $termUrl);
$payment->setAdditionalInformation('paymentData', $paymentData); $payment->setAdditionalInformation('paymentData', $paymentData);
} else { } else {
$isValid = false; $isValid = false;
......
...@@ -341,6 +341,19 @@ class Requests extends AbstractHelper ...@@ -341,6 +341,19 @@ class Requests extends AbstractHelper
return $request; 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 $request
* @param $areaCode * @param $areaCode
......
...@@ -560,6 +560,7 @@ ...@@ -560,6 +560,7 @@
<item name="transaction" xsi:type="string">Adyen\Payment\Gateway\Request\CcAuthorizationDataBuilder</item> <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="vault" xsi:type="string">Adyen\Payment\Gateway\Request\VaultDataBuilder</item>
<item name="threeds2" xsi:type="string">Adyen\Payment\Gateway\Request\ThreeDS2DataBuilder</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> </argument>
</arguments> </arguments>
</virtualType> </virtualType>
...@@ -607,6 +608,7 @@ ...@@ -607,6 +608,7 @@
<item name="recurring" xsi:type="string">Adyen\Payment\Gateway\Request\RecurringDataBuilder</item> <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="oneclick" xsi:type="string">Adyen\Payment\Gateway\Request\OneclickAuthorizationDataBuilder</item>
<item name="threeds2" xsi:type="string">Adyen\Payment\Gateway\Request\ThreeDS2DataBuilder</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> </argument>
</arguments> </arguments>
</virtualType> </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