Commit 2773ec48 authored by Maikel Koek's avatar Maikel Koek

[VM] +: Save Vault token at 3D Secure payment return

parent 29dbe5e3
...@@ -23,8 +23,12 @@ ...@@ -23,8 +23,12 @@
namespace Adyen\Payment\Controller\Process; namespace Adyen\Payment\Controller\Process;
use Magento\Payment\Model\InfoInterface;
use Magento\Vault\Api\Data\PaymentTokenInterface; use Magento\Vault\Api\Data\PaymentTokenInterface;
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface; use Magento\Vault\Api\Data\PaymentTokenFactoryInterface;
use Magento\Sales\Api\Data\OrderPaymentExtensionInterface;
use Magento\Sales\Api\Data\OrderPaymentExtensionInterfaceFactory;
use Magento\Sales\Model\ResourceModel\Order\Payment as OrderPaymentResource;
class Validate3d extends \Magento\Framework\App\Action\Action class Validate3d extends \Magento\Framework\App\Action\Action
{ {
...@@ -63,6 +67,16 @@ class Validate3d extends \Magento\Framework\App\Action\Action ...@@ -63,6 +67,16 @@ class Validate3d extends \Magento\Framework\App\Action\Action
*/ */
private $paymentTokenFactory; private $paymentTokenFactory;
/**
* @var OrderPaymentExtensionInterfaceFactory
*/
private $paymentExtensionFactory;
/**
* @var OrderPaymentResource
*/
private $orderPaymentResource;
/** /**
* Validate3d constructor. * Validate3d constructor.
* *
...@@ -70,6 +84,10 @@ class Validate3d extends \Magento\Framework\App\Action\Action ...@@ -70,6 +84,10 @@ class Validate3d extends \Magento\Framework\App\Action\Action
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger * @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Adyen\Payment\Model\Api\PaymentRequest $paymentRequest * @param \Adyen\Payment\Model\Api\PaymentRequest $paymentRequest
* @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository
* @param PaymentTokenFactoryInterface $paymentTokenFactory
* @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory
* @param OrderPaymentResource $orderPaymentResource
*/ */
public function __construct( public function __construct(
\Magento\Framework\App\Action\Context $context, \Magento\Framework\App\Action\Context $context,
...@@ -77,7 +95,9 @@ class Validate3d extends \Magento\Framework\App\Action\Action ...@@ -77,7 +95,9 @@ class Validate3d extends \Magento\Framework\App\Action\Action
\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 PaymentTokenFactoryInterface $paymentTokenFactory,
OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory,
OrderPaymentResource $orderPaymentResource
) { ) {
parent::__construct($context); parent::__construct($context);
$this->_adyenLogger = $adyenLogger; $this->_adyenLogger = $adyenLogger;
...@@ -85,6 +105,8 @@ class Validate3d extends \Magento\Framework\App\Action\Action ...@@ -85,6 +105,8 @@ class Validate3d extends \Magento\Framework\App\Action\Action
$this->_paymentRequest = $paymentRequest; $this->_paymentRequest = $paymentRequest;
$this->_orderRepository = $orderRepository; $this->_orderRepository = $orderRepository;
$this->paymentTokenFactory = $paymentTokenFactory; $this->paymentTokenFactory = $paymentTokenFactory;
$this->paymentExtensionFactory = $paymentExtensionFactory;
$this->orderPaymentResource = $orderPaymentResource;
} }
/** /**
...@@ -163,6 +185,16 @@ class Validate3d extends \Magento\Framework\App\Action\Action ...@@ -163,6 +185,16 @@ class Validate3d extends \Magento\Framework\App\Action\Action
'expirationDate' => $expirationDate 'expirationDate' => $expirationDate
]; ];
$paymentToken->setTokenDetails(json_encode($details)); $paymentToken->setTokenDetails(json_encode($details));
$extensionAttributes = $this->getExtensionAttributes($order->getPayment());
$extensionAttributes->setVaultPaymentToken($paymentToken);
$orderPayment = $order->getPayment()->setExtensionAttributes($extensionAttributes);
$add = unserialize($orderPayment->getAdditionalData());
$add['force_save'] = true;
$orderPayment->setAdditionalData(serialize($add));
$this->orderPaymentResource->save($orderPayment);
} catch(\Exception $e) { } catch(\Exception $e) {
$this->_adyenLogger->error((string)$e->getMessage()); $this->_adyenLogger->error((string)$e->getMessage());
} }
...@@ -201,6 +233,21 @@ class Validate3d extends \Magento\Framework\App\Action\Action ...@@ -201,6 +233,21 @@ class Validate3d extends \Magento\Framework\App\Action\Action
} }
} }
/**
* Get payment extension attributes
* @param InfoInterface $payment
* @return OrderPaymentExtensionInterface
*/
private function getExtensionAttributes(InfoInterface $payment)
{
$extensionAttributes = $payment->getExtensionAttributes();
if (null === $extensionAttributes) {
$extensionAttributes = $this->paymentExtensionFactory->create();
$payment->setExtensionAttributes($extensionAttributes);
}
return $extensionAttributes;
}
/** /**
* @param $expirationDate * @param $expirationDate
* @return string * @return string
......
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