We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit 9abbb9f3 authored by acampos1916's avatar acampos1916

Fix for code smells and extra log message

parent 54a76efc
...@@ -23,29 +23,41 @@ ...@@ -23,29 +23,41 @@
namespace Adyen\Payment\Gateway\Response; namespace Adyen\Payment\Gateway\Response;
use Adyen\Payment\Helper\Data;
use Adyen\Payment\Logger\AdyenLogger;
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface; use Magento\Vault\Api\Data\PaymentTokenFactoryInterface;
use Magento\Payment\Gateway\Response\HandlerInterface; use Magento\Payment\Gateway\Response\HandlerInterface;
use Magento\Payment\Model\InfoInterface; use Magento\Payment\Model\InfoInterface;
use Magento\Vault\Model\PaymentTokenManagement; use Magento\Vault\Model\PaymentTokenManagement;
use Adyen\Payment\Api\Data\OrderPaymentInterface;
use Magento\Payment\Gateway\Data\PaymentDataObject; use Magento\Payment\Gateway\Data\PaymentDataObject;
use Magento\Vault\Api\PaymentTokenRepositoryInterface; use Magento\Vault\Api\PaymentTokenRepositoryInterface;
class VaultDetailsHandler implements HandlerInterface class VaultDetailsHandler implements HandlerInterface
{ {
const ADDITIONAL_DATA_ERRORS = array(
'recurring.recurringDetailReference' => 'Missing Token in Result please enable in ' .
'Settings -> API URLs and Response menu in the Adyen Customer Area Recurring details setting',
'cardSummary' => 'Missing cardSummary in Result please login to the adyen portal ' .
'and go to Settings -> API URLs and Response and enable the Card summary property',
'expiryDate' => 'Missing expiryDate in Result please login to the adyen portal and go to ' .
'Settings -> API URLs and Response and enable the Expiry date property',
'paymentMethod' => 'Missing paymentMethod in Result please login to the adyen portal and go to ' .
'Settings -> API URLs and Response and enable the Variant property'
);
/** /**
* @var PaymentTokenInterfaceFactory * @var PaymentTokenFactoryInterface
*/ */
protected $paymentTokenFactory; protected $paymentTokenFactory;
/** /**
* @var \Adyen\Payment\Logger\AdyenLogger * @var AdyenLogger
*/ */
private $adyenLogger; private $adyenLogger;
/** /**
* @var \Adyen\Payment\Helper\Data * @var Data
*/ */
private $adyenHelper; private $adyenHelper;
...@@ -63,13 +75,15 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -63,13 +75,15 @@ class VaultDetailsHandler implements HandlerInterface
* VaultDetailsHandler constructor. * VaultDetailsHandler constructor.
* *
* @param PaymentTokenFactoryInterface $paymentTokenFactory * @param PaymentTokenFactoryInterface $paymentTokenFactory
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger * @param AdyenLogger $adyenLogger
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param Data $adyenHelper
* @param PaymentTokenManagement $paymentTokenManagement
* @param PaymentTokenRepositoryInterface $paymentTokenRepository
*/ */
public function __construct( public function __construct(
PaymentTokenFactoryInterface $paymentTokenFactory, PaymentTokenFactoryInterface $paymentTokenFactory,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger, AdyenLogger $adyenLogger,
\Adyen\Payment\Helper\Data $adyenHelper, Data $adyenHelper,
PaymentTokenManagement $paymentTokenManagement, PaymentTokenManagement $paymentTokenManagement,
PaymentTokenRepositoryInterface $paymentTokenRepository PaymentTokenRepositoryInterface $paymentTokenRepository
) { ) {
...@@ -85,7 +99,7 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -85,7 +99,7 @@ class VaultDetailsHandler implements HandlerInterface
*/ */
public function handle(array $handlingSubject, array $response) public function handle(array $handlingSubject, array $response)
{ {
/** @var @var PaymentDataObject $orderPayment */ /** @var PaymentDataObject $orderPayment */
$orderPayment = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($handlingSubject); $orderPayment = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($handlingSubject);
$payment = $orderPayment->getPayment(); $payment = $orderPayment->getPayment();
...@@ -97,6 +111,11 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -97,6 +111,11 @@ class VaultDetailsHandler implements HandlerInterface
if (null !== $paymentToken) { if (null !== $paymentToken) {
$extensionAttributes = $this->getExtensionAttributes($payment); $extensionAttributes = $this->getExtensionAttributes($payment);
$extensionAttributes->setVaultPaymentToken($paymentToken); $extensionAttributes->setVaultPaymentToken($paymentToken);
} else {
$this->adyenLogger->error(
sprintf('Failure trying to save credit card token in vault for order %s',
$payment->getOrder()->getIncrementId())
);
} }
} }
} }
...@@ -115,49 +134,18 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -115,49 +134,18 @@ class VaultDetailsHandler implements HandlerInterface
if (!empty($response['additionalData'])) { if (!empty($response['additionalData'])) {
$additionalData = $response['additionalData']; $additionalData = $response['additionalData'];
foreach (self::ADDITIONAL_DATA_ERRORS as $key => $errorMsg) {
if (empty($additionalData['recurring.recurringDetailReference'])) { if (empty($additionalData[$key])) {
$this->adyenLogger->error( $this->adyenLogger->error($errorMsg);
'Missing Token in Result please enable in ' .
'Settings -> API URLs and Response menu in the Adyen Customer Area Recurring details setting'
);
return null;
}
$token = $additionalData['recurring.recurringDetailReference'];
if (empty($additionalData['cardSummary'])) {
$this->adyenLogger->error(
'Missing cardSummary in Result please login to the adyen portal ' .
'and go to Settings -> API URLs and Response and enable the Card summary property'
);
return null; return null;
} }
$cardSummary = $additionalData['cardSummary'];
if (empty($additionalData['expiryDate'])) {
$this->adyenLogger->error(
'Missing expiryDate in Result please login to the adyen portal and go to ' .
'Settings -> API URLs and Response and enable the Expiry date property'
);
return null;
} }
$expirationDate = $additionalData['expiryDate'];
if (empty($additionalData['paymentMethod'])) {
$this->adyenLogger->error(
'Missing paymentMethod in Result please login to the adyen portal and go to ' .
'Settings -> API URLs and Response and enable the Variant property'
);
return null;
}
$cardType = $additionalData['paymentMethod'];
try { try {
// Check if paymentToken exists already // Check if paymentToken exists already
$paymentToken = $this->paymentTokenManagement->getByGatewayToken($token, $payment->getMethodInstance()->getCode(), $payment->getOrder()->getCustomerId()); $paymentToken = $this->paymentTokenManagement->getByGatewayToken($additionalData['recurring.recurringDetailReference'],
$payment->getMethodInstance()->getCode(), $payment->getOrder()->getCustomerId());
$paymentTokenSaveRequired = false; $paymentTokenSaveRequired = false;
...@@ -168,22 +156,23 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -168,22 +156,23 @@ class VaultDetailsHandler implements HandlerInterface
PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD
); );
$paymentToken->setGatewayToken($token); $paymentToken->setGatewayToken($additionalData['recurring.recurringDetailReference']);
if (strpos($cardType, "paywithgoogle") !== false && !empty($additionalData['paymentMethodVariant'])) { if (strpos($additionalData['paymentMethod'], "paywithgoogle") !== false
$cardType = $additionalData['paymentMethodVariant']; && !empty($additionalData['paymentMethodVariant'])) {
$additionalData['paymentMethod'] = $additionalData['paymentMethodVariant'];
$paymentToken->setIsVisible(false); $paymentToken->setIsVisible(false);
} }
} else { } else {
$paymentTokenSaveRequired = true; $paymentTokenSaveRequired = true;
} }
$paymentToken->setExpiresAt($this->getExpirationDate($expirationDate)); $paymentToken->setExpiresAt($this->getExpirationDate($additionalData['expiryDate']));
$details = [ $details = [
'type' => $cardType, 'type' => $additionalData['paymentMethod'],
'maskedCC' => $cardSummary, 'maskedCC' => $additionalData['cardSummary'],
'expirationDate' => $expirationDate 'expirationDate' => $additionalData['expiryDate']
]; ];
$paymentToken->setTokenDetails(json_encode($details)); $paymentToken->setTokenDetails(json_encode($details));
......
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