Commit 3194acc1 authored by Maikel Koek's avatar Maikel Koek

[VM] B: Create Vault token at 3D Secure validation return

parent 114a3aca
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
namespace Adyen\Payment\Controller\Process; namespace Adyen\Payment\Controller\Process;
use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface;
class Validate3d extends \Magento\Framework\App\Action\Action class Validate3d extends \Magento\Framework\App\Action\Action
{ {
/** /**
...@@ -55,6 +58,11 @@ class Validate3d extends \Magento\Framework\App\Action\Action ...@@ -55,6 +58,11 @@ class Validate3d extends \Magento\Framework\App\Action\Action
*/ */
protected $_orderRepository; protected $_orderRepository;
/**
* @var PaymentTokenFactoryInterface
*/
private $paymentTokenFactory;
/** /**
* Validate3d constructor. * Validate3d constructor.
* *
...@@ -68,13 +76,15 @@ class Validate3d extends \Magento\Framework\App\Action\Action ...@@ -68,13 +76,15 @@ class Validate3d extends \Magento\Framework\App\Action\Action
\Adyen\Payment\Logger\AdyenLogger $adyenLogger, \Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Adyen\Payment\Helper\Data $adyenHelper, \Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Model\Api\PaymentRequest $paymentRequest, \Adyen\Payment\Model\Api\PaymentRequest $paymentRequest,
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository \Magento\Sales\Api\OrderRepositoryInterface $orderRepository,
PaymentTokenFactoryInterface $paymentTokenFactory
) { ) {
parent::__construct($context); parent::__construct($context);
$this->_adyenLogger = $adyenLogger; $this->_adyenLogger = $adyenLogger;
$this->_adyenHelper = $adyenHelper; $this->_adyenHelper = $adyenHelper;
$this->_paymentRequest = $paymentRequest; $this->_paymentRequest = $paymentRequest;
$this->_orderRepository = $orderRepository; $this->_orderRepository = $orderRepository;
$this->paymentTokenFactory = $paymentTokenFactory;
} }
/** /**
...@@ -135,6 +145,27 @@ class Validate3d extends \Magento\Framework\App\Action\Action ...@@ -135,6 +145,27 @@ class Validate3d extends \Magento\Framework\App\Action\Action
$order->getPayment()->setAdditionalInformation('3dSuccess', true); $order->getPayment()->setAdditionalInformation('3dSuccess', true);
$this->_orderRepository->save($order); $this->_orderRepository->save($order);
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));
} catch(\Exception $e) {
$this->_adyenLogger->error(print_r($e, true));
}
$this->_redirect('checkout/onepage/success', ['_query' => ['utm_nooverride' => '1']]); $this->_redirect('checkout/onepage/success', ['_query' => ['utm_nooverride' => '1']]);
} else { } else {
$order->addStatusHistoryComment(__('3D-secure validation was unsuccessful.'))->save(); $order->addStatusHistoryComment(__('3D-secure validation was unsuccessful.'))->save();
...@@ -169,6 +200,33 @@ class Validate3d extends \Magento\Framework\App\Action\Action ...@@ -169,6 +200,33 @@ class Validate3d extends \Magento\Framework\App\Action\Action
} }
} }
/**
* @param $expirationDate
* @return string
*/
private function getExpirationDate($expirationDate)
{
$expirationDate = explode('/', $expirationDate);
//add leading zero to month
$month = sprintf("%02d", $expirationDate[0]);
$expDate = new \DateTime(
$expirationDate[1]
. '-'
. $month
. '-'
. '01'
. ' '
. '00:00:00',
new \DateTimeZone('UTC')
);
// add one month
$expDate->add(new \DateInterval('P1M'));
return $expDate->format('Y-m-d 00:00:00');
}
/** /**
* Called by validate3d controller when cc payment has 3D secure * Called by validate3d controller when cc payment has 3D secure
* *
......
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