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 cfe59586 authored by attilak's avatar attilak

Fix for unhandled result in the query parameters

Fix for billing agreement undefined index in case of api response
misconfiguration
Fix undefined $store variable
parent 296f8de9
...@@ -214,14 +214,19 @@ class Result extends \Magento\Framework\App\Action\Action ...@@ -214,14 +214,19 @@ class Result extends \Magento\Framework\App\Action\Action
{ {
$result = false; $result = false;
$this->_adyenLogger->addAdyenResult('Updating the order');
if (!empty($response['authResult'])) { if (!empty($response['authResult'])) {
$authResult = $response['authResult']; $authResult = $response['authResult'];
} elseif (!empty($response['resultCode'])) { } elseif (!empty($response['resultCode'])) {
$authResult = $response['resultCode']; $authResult = $response['resultCode'];
} else {
// In case the result is unknown we log the request and don't update the history
$this->_adyenLogger->addError("Unexpected result query parameter. Response: " . json_encode($response));
return $result;
} }
$this->_adyenLogger->addAdyenResult('Updating the order');
$paymentMethod = isset($response['paymentMethod']) ? trim($response['paymentMethod']) : ''; $paymentMethod = isset($response['paymentMethod']) ? trim($response['paymentMethod']) : '';
$pspReference = isset($response['pspReference']) ? trim($response['pspReference']) : ''; $pspReference = isset($response['pspReference']) ? trim($response['pspReference']) : '';
......
...@@ -38,19 +38,27 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -38,19 +38,27 @@ class VaultDetailsHandler implements HandlerInterface
/** /**
* @var \Adyen\Payment\Logger\AdyenLogger * @var \Adyen\Payment\Logger\AdyenLogger
*/ */
private $_adyenLogger; private $adyenLogger;
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
/** /**
* VaultDetailsHandler constructor. * VaultDetailsHandler constructor.
* *
* @param PaymentTokenFactoryInterface $paymentTokenFactory * @param PaymentTokenFactoryInterface $paymentTokenFactory
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger * @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/ */
public function __construct( public function __construct(
PaymentTokenFactoryInterface $paymentTokenFactory, PaymentTokenFactoryInterface $paymentTokenFactory,
\Adyen\Payment\Logger\AdyenLogger $adyenLogger \Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Adyen\Payment\Helper\Data $adyenHelper
) { ) {
$this->_adyenLogger = $adyenLogger; $this->adyenLogger = $adyenLogger;
$this->adyenHelper = $adyenHelper;
$this->paymentTokenFactory = $paymentTokenFactory; $this->paymentTokenFactory = $paymentTokenFactory;
} }
...@@ -61,9 +69,10 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -61,9 +69,10 @@ class VaultDetailsHandler implements HandlerInterface
{ {
$payment = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($handlingSubject); $payment = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($handlingSubject);
/** @var OrderPaymentInterface $payment */ /** @var \Adyen\Payment\Api\Data\OrderPaymentInterface $payment */
$payment = $payment->getPayment(); $payment = $payment->getPayment();
if ($this->adyenHelper->isCreditCardVaultEnabled($payment->getOrder()->getStoreId())) {
// add vault payment token entity to extension attributes // add vault payment token entity to extension attributes
$paymentToken = $this->getVaultPaymentToken($response); $paymentToken = $this->getVaultPaymentToken($response);
...@@ -72,6 +81,7 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -72,6 +81,7 @@ class VaultDetailsHandler implements HandlerInterface
$extensionAttributes->setVaultPaymentToken($paymentToken); $extensionAttributes->setVaultPaymentToken($paymentToken);
} }
} }
}
/** /**
* Get vault payment token entity * Get vault payment token entity
...@@ -88,7 +98,7 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -88,7 +98,7 @@ class VaultDetailsHandler implements HandlerInterface
if (empty($additionalData['recurring.recurringDetailReference'])) { if (empty($additionalData['recurring.recurringDetailReference'])) {
$this->_adyenLogger->error( $this->adyenLogger->error(
'Missing Token in Result please enable in ' . 'Missing Token in Result please enable in ' .
'Settings -> API URLs and Response menu in the Adyen Customer Area Recurring details setting' 'Settings -> API URLs and Response menu in the Adyen Customer Area Recurring details setting'
); );
...@@ -98,7 +108,7 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -98,7 +108,7 @@ class VaultDetailsHandler implements HandlerInterface
if (empty($additionalData['cardSummary'])) { if (empty($additionalData['cardSummary'])) {
$this->_adyenLogger->error( $this->adyenLogger->error(
'Missing cardSummary in Result please login to the adyen portal ' . 'Missing cardSummary in Result please login to the adyen portal ' .
'and go to Settings -> API URLs and Response and enable the Card summary property' 'and go to Settings -> API URLs and Response and enable the Card summary property'
); );
...@@ -107,7 +117,7 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -107,7 +117,7 @@ class VaultDetailsHandler implements HandlerInterface
$cardSummary = $additionalData['cardSummary']; $cardSummary = $additionalData['cardSummary'];
if (empty($additionalData['expiryDate'])) { if (empty($additionalData['expiryDate'])) {
$this->_adyenLogger->error( $this->adyenLogger->error(
'Missing expiryDate in Result please login to the adyen portal and go to ' . 'Missing expiryDate in Result please login to the adyen portal and go to ' .
'Settings -> API URLs and Response and enable the Expiry date property' 'Settings -> API URLs and Response and enable the Expiry date property'
); );
...@@ -116,7 +126,7 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -116,7 +126,7 @@ class VaultDetailsHandler implements HandlerInterface
$expirationDate = $additionalData['expiryDate']; $expirationDate = $additionalData['expiryDate'];
if (empty($additionalData['paymentMethod'])) { if (empty($additionalData['paymentMethod'])) {
$this->_adyenLogger->error( $this->adyenLogger->error(
'Missing paymentMethod in Result please login to the adyen portal and go to ' . 'Missing paymentMethod in Result please login to the adyen portal and go to ' .
'Settings -> API URLs and Response and enable the Variant property' 'Settings -> API URLs and Response and enable the Variant property'
); );
...@@ -141,7 +151,7 @@ class VaultDetailsHandler implements HandlerInterface ...@@ -141,7 +151,7 @@ class VaultDetailsHandler implements HandlerInterface
$paymentToken->setTokenDetails(json_encode($details)); $paymentToken->setTokenDetails(json_encode($details));
} catch (\Exception $e) { } catch (\Exception $e) {
$this->_adyenLogger->error(print_r($e, true)); $this->adyenLogger->error(print_r($e, true));
} }
} }
......
...@@ -1595,7 +1595,6 @@ class Data extends AbstractHelper ...@@ -1595,7 +1595,6 @@ class Data extends AbstractHelper
// check if BA exists // check if BA exists
if (!($billingAgreement && $billingAgreement->getAgreementId() > 0 && $billingAgreement->isValid())) { if (!($billingAgreement && $billingAgreement->getAgreementId() > 0 && $billingAgreement->isValid())) {
// create new BA // create new BA
$this->adyenLogger->addAdyenDebug("Creating new Billing Agreement");
$billingAgreement = $this->billingAgreementFactory->create(); $billingAgreement = $this->billingAgreementFactory->create();
$billingAgreement->setStoreId($order->getStoreId()); $billingAgreement->setStoreId($order->getStoreId());
$billingAgreement->importOrderPayment($order->getPayment()); $billingAgreement->importOrderPayment($order->getPayment());
...@@ -1615,7 +1614,9 @@ class Data extends AbstractHelper ...@@ -1615,7 +1614,9 @@ class Data extends AbstractHelper
$storeOneClick = $order->getPayment()->getAdditionalInformation('store_cc'); $storeOneClick = $order->getPayment()->getAdditionalInformation('store_cc');
$billingAgreement->setCcBillingAgreement($additionalData, $storeOneClick, $order->getStoreId()); $billingAgreement->setCcBillingAgreement($additionalData, $storeOneClick, $order->getStoreId());
if ($billingAgreement->isValid()) { $billingAgreementErrors = $billingAgreement->getErrors();
if ($billingAgreement->isValid() && empty($billingAgreementErrors)) {
if (!$this->agreementResourceModel->getOrderRelation($billingAgreement->getAgreementId(), if (!$this->agreementResourceModel->getOrderRelation($billingAgreement->getAgreementId(),
$order->getId())) { $order->getId())) {
...@@ -1627,7 +1628,7 @@ class Data extends AbstractHelper ...@@ -1627,7 +1628,7 @@ class Data extends AbstractHelper
$order->addRelatedObject($billingAgreement); $order->addRelatedObject($billingAgreement);
} else { } else {
$message = __('Failed to create billing agreement for this order. Reason(s): ') . join(', ', $message = __('Failed to create billing agreement for this order. Reason(s): ') . join(', ',
$billingAgreement->getErrors()); $billingAgreementErrors);
throw new \Exception($message); throw new \Exception($message);
} }
...@@ -1799,7 +1800,7 @@ class Data extends AbstractHelper ...@@ -1799,7 +1800,7 @@ class Data extends AbstractHelper
$localeCode = $this->config->getValue( $localeCode = $this->config->getValue(
\Magento\Directory\Helper\Data::XML_PATH_DEFAULT_LOCALE, \Magento\Directory\Helper\Data::XML_PATH_DEFAULT_LOCALE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORES, \Magento\Store\Model\ScopeInterface::SCOPE_STORES,
$store->getCode() $this->storeManager->getStore($storeId)->getCode()
); );
return $localeCode; return $localeCode;
......
...@@ -179,12 +179,17 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement ...@@ -179,12 +179,17 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement
->setMethodCode('adyen_oneclick') ->setMethodCode('adyen_oneclick')
->setReferenceId($contractDetail['recurring.recurringDetailReference']); ->setReferenceId($contractDetail['recurring.recurringDetailReference']);
if (!isset($contractDetail['cardBin']) ||
!isset($contractDetail['cardHolderName']) ||
!isset($contractDetail['cardSummary']) ||
!isset($contractDetail['expiryDate']) ||
!isset($contractDetail['paymentMethod'])
) {
$this->_errors[] = __('"In the Additional data in API response section, select: Card summary, Expiry Date, Cardholder name, Recurring details and Variant to create billing agreements immediately after the payment is authorized."');
return $this;
}
// Billing agreement is CC // Billing agreement is CC
if (isset($contractDetail['cardBin']) &&
isset($contractDetail['cardHolderName']) &&
isset($contractDetail['cardSummary']) &&
isset($contractDetail['expiryDate']) &&
isset($contractDetail['paymentMethod'])) {
$ccType = $contractDetail['paymentMethod']; $ccType = $contractDetail['paymentMethod'];
$ccTypes = $this->adyenHelper->getCcTypesAltData(); $ccTypes = $this->adyenHelper->getCcTypesAltData();
...@@ -208,7 +213,7 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement ...@@ -208,7 +213,7 @@ class Agreement extends \Magento\Paypal\Model\Billing\Agreement
} }
$this->setAgreementLabel($label); $this->setAgreementLabel($label);
}
$expiryDate = explode('/', $contractDetail['expiryDate']); $expiryDate = explode('/', $contractDetail['expiryDate']);
if (!empty($contractDetail['pos_payment'])) { if (!empty($contractDetail['pos_payment'])) {
......
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