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

[WIP]

- Data builders use the requests helper functions
- In case of error from API during first payments call show an error on
the frontend
parent 9ece2e5f
...@@ -30,11 +30,6 @@ use Magento\Payment\Gateway\Request\BuilderInterface; ...@@ -30,11 +30,6 @@ use Magento\Payment\Gateway\Request\BuilderInterface;
*/ */
class AddressDataBuilder implements BuilderInterface class AddressDataBuilder implements BuilderInterface
{ {
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
/** /**
* @var \Adyen\Payment\Helper\Requests * @var \Adyen\Payment\Helper\Requests
*/ */
...@@ -43,15 +38,12 @@ class AddressDataBuilder implements BuilderInterface ...@@ -43,15 +38,12 @@ class AddressDataBuilder implements BuilderInterface
/** /**
* AddressDataBuilder constructor. * AddressDataBuilder constructor.
* *
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Adyen\Payment\Helper\Requests $adyenRequestsHelper * @param \Adyen\Payment\Helper\Requests $adyenRequestsHelper
*/ */
public function __construct( public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Helper\Requests $adyenRequestsHelper \Adyen\Payment\Helper\Requests $adyenRequestsHelper
) )
{ {
$this->adyenHelper = $adyenHelper;
$this->adyenRequestsHelper = $adyenRequestsHelper; $this->adyenRequestsHelper = $adyenRequestsHelper;
} }
...@@ -69,9 +61,6 @@ class AddressDataBuilder implements BuilderInterface ...@@ -69,9 +61,6 @@ class AddressDataBuilder implements BuilderInterface
$billingAddress = $order->getBillingAddress(); $billingAddress = $order->getBillingAddress();
$shippingAddress = $order->getShippingAddress(); $shippingAddress = $order->getShippingAddress();
$result = []; return $this->adyenRequestsHelper->buildAddressData([], $billingAddress, $shippingAddress);
$result = $this->adyenRequestsHelper->buildAddressData($result, $billingAddress, $shippingAddress);
return $result;
} }
} }
...@@ -52,7 +52,6 @@ class BrowserInfoDataBuilder implements BuilderInterface ...@@ -52,7 +52,6 @@ class BrowserInfoDataBuilder implements BuilderInterface
*/ */
public function build(array $buildSubject) public function build(array $buildSubject)
{ {
$result = $this->adyenRequestsHelper->buildBrowserData(); return $this->adyenRequestsHelper->buildBrowserData();
return $result;
} }
} }
...@@ -27,25 +27,10 @@ use Magento\Payment\Gateway\Request\BuilderInterface; ...@@ -27,25 +27,10 @@ use Magento\Payment\Gateway\Request\BuilderInterface;
class CcAuthorizationDataBuilder implements BuilderInterface class CcAuthorizationDataBuilder implements BuilderInterface
{ {
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
/**
* CcAuthorizationDataBuilder constructor.
*
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper
) {
$this->adyenHelper = $adyenHelper;
}
/** /**
* @param array $buildSubject * @param array $buildSubject
* @return mixed * @return array|mixed
* @throws \Magento\Framework\Exception\LocalizedException
*/ */
public function build(array $buildSubject) public function build(array $buildSubject)
{ {
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
namespace Adyen\Payment\Gateway\Request; namespace Adyen\Payment\Gateway\Request;
use Magento\Payment\Gateway\Request\BuilderInterface; use Magento\Payment\Gateway\Request\BuilderInterface;
use Adyen\Payment\Observer\AdyenHppDataAssignObserver;
/** /**
* Class CustomerDataBuilder * Class CustomerDataBuilder
...@@ -31,20 +30,20 @@ use Adyen\Payment\Observer\AdyenHppDataAssignObserver; ...@@ -31,20 +30,20 @@ use Adyen\Payment\Observer\AdyenHppDataAssignObserver;
class CustomerDataBuilder implements BuilderInterface class CustomerDataBuilder implements BuilderInterface
{ {
/** /**
* @var \Adyen\Payment\Helper\Data * @var \Adyen\Payment\Helper\Requests
*/ */
private $adyenHelper; private $adyenRequestsHelper;
/** /**
* CustomerDataBuilder constructor. * CustomerDataBuilder constructor.
* *
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Requests $adyenRequestsHelper
*/ */
public function __construct( public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper \Adyen\Payment\Helper\Requests $adyenRequestsHelper
) )
{ {
$this->adyenHelper = $adyenHelper; $this->adyenRequestsHelper = $adyenRequestsHelper;
} }
/** /**
...@@ -55,64 +54,13 @@ class CustomerDataBuilder implements BuilderInterface ...@@ -55,64 +54,13 @@ class CustomerDataBuilder implements BuilderInterface
*/ */
public function build(array $buildSubject) public function build(array $buildSubject)
{ {
$result = [];
/** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */ /** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject); $paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$order = $paymentDataObject->getOrder(); $order = $paymentDataObject->getOrder();
$payment = $paymentDataObject->getPayment(); $payment = $paymentDataObject->getPayment();
$customerId = $order->getCustomerId(); $customerId = $order->getCustomerId();
if ($customerId > 0) {
$result['shopperReference'] = $customerId;
}
$billingAddress = $order->getBillingAddress(); $billingAddress = $order->getBillingAddress();
if (!empty($billingAddress)) { return $this->adyenRequestsHelper->buildCustomerData([], $customerId, $billingAddress, $payment);
if ($this->adyenHelper->isPaymentMethodOpenInvoiceMethod(
$payment->getAdditionalInformation(AdyenHppDataAssignObserver::BRAND_CODE)
) && !$this->adyenHelper->isPaymentMethodAfterpayTouchMethod(
$payment->getAdditionalInformation(AdyenHppDataAssignObserver::BRAND_CODE)
)) {
if ($customerEmail = $billingAddress->getEmail()) {
$result['paymentMethod']['personalDetails']['shopperEmail'] = $customerEmail;
}
if ($customerTelephone = trim($billingAddress->getTelephone())) {
$result['paymentMethod']['personalDetails']['telephoneNumber'] = $customerTelephone;
}
if ($firstName = $billingAddress->getFirstname()) {
$result['paymentMethod']['personalDetails']['firstName'] = $firstName;
}
if ($lastName = $billingAddress->getLastname()) {
$result['paymentMethod']['personalDetails']['lastName'] = $lastName;
}
} else {
if ($customerEmail = $billingAddress->getEmail()) {
$result['shopperEmail'] = $customerEmail;
}
if ($customerTelephone = trim($billingAddress->getTelephone())) {
$result['telephoneNumber'] = $customerTelephone;
}
if ($firstName = $billingAddress->getFirstname()) {
$result['shopperName']['firstName'] = $firstName;
}
if ($lastName = $billingAddress->getLastname()) {
$result['shopperName']['lastName'] = $lastName;
}
}
if ($countryId = $billingAddress->getCountryId()) {
$result['countryCode'] = $countryId;
}
}
return $result;
} }
} }
...@@ -29,6 +29,21 @@ use Magento\Payment\Gateway\Request\BuilderInterface; ...@@ -29,6 +29,21 @@ use Magento\Payment\Gateway\Request\BuilderInterface;
*/ */
class CustomerIpDataBuilder implements BuilderInterface class CustomerIpDataBuilder implements BuilderInterface
{ {
/**
* @var \Adyen\Payment\Helper\Requests
*/
private $adyenRequestsHelper;
/**
* CustomerIpDataBuilder constructor.
*
* @param \Adyen\Payment\Helper\Requests $adyenRequestsHelper
*/
public function __construct(\Adyen\Payment\Helper\Requests $adyenRequestsHelper)
{
$this->adyenRequestsHelper = $adyenRequestsHelper;
}
/** /**
* @param array $buildSubject * @param array $buildSubject
* @return array * @return array
...@@ -38,6 +53,7 @@ class CustomerIpDataBuilder implements BuilderInterface ...@@ -38,6 +53,7 @@ class CustomerIpDataBuilder implements BuilderInterface
/** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */ /** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject); $paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$order = $paymentDataObject->getOrder(); $order = $paymentDataObject->getOrder();
return ['shopperIP' => $order->getRemoteIp()];
return $this->adyenRequestsHelper->buildCustomerIpData([], $order->getRemoteIp());
} }
} }
...@@ -28,19 +28,19 @@ use Magento\Payment\Gateway\Request\BuilderInterface; ...@@ -28,19 +28,19 @@ use Magento\Payment\Gateway\Request\BuilderInterface;
class MerchantAccountDataBuilder implements BuilderInterface class MerchantAccountDataBuilder implements BuilderInterface
{ {
/** /**
* @var \Adyen\Payment\Helper\Data * @var \Adyen\Payment\Helper\Requests
*/ */
private $adyenHelper; private $adyenRequestsHelper;
/** /**
* RecurringDataBuilder constructor. * MerchantAccountDataBuilder constructor.
* *
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Requests $adyenRequestsHelper
*/ */
public function __construct( public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper \Adyen\Payment\Helper\Requests $adyenRequestsHelper
) { ) {
$this->adyenHelper = $adyenHelper; $this->adyenRequestsHelper = $adyenRequestsHelper;
} }
/** /**
...@@ -52,12 +52,10 @@ class MerchantAccountDataBuilder implements BuilderInterface ...@@ -52,12 +52,10 @@ class MerchantAccountDataBuilder implements BuilderInterface
/** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */ /** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject); $paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$order = $paymentDataObject->getOrder(); $order = $paymentDataObject->getOrder();
$storeId = $order->getStoreId();
$payment = $paymentDataObject->getPayment(); $payment = $paymentDataObject->getPayment();
$storeId = $order->getStoreId();
$method = $payment->getMethod(); $method = $payment->getMethod();
$merchantAccount = $this->adyenHelper->getAdyenMerchantAccount($method, $storeId); return $this->adyenRequestsHelper->buildMerchantAccountData([], $method, $storeId);
return ["merchantAccount" => $merchantAccount];
} }
} }
...@@ -29,20 +29,19 @@ use Magento\Payment\Gateway\Request\BuilderInterface; ...@@ -29,20 +29,19 @@ use Magento\Payment\Gateway\Request\BuilderInterface;
*/ */
class PaymentDataBuilder implements BuilderInterface class PaymentDataBuilder implements BuilderInterface
{ {
/** /**
* @var \Adyen\Payment\Helper\Data * @var \Adyen\Payment\Helper\Requests
*/ */
private $adyenHelper; private $adyenRequestsHelper;
/** /**
* PaymentDataBuilder constructor. * PaymentDataBuilder constructor.
* *
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Requests $adyenRequestsHelper
*/ */
public function __construct(\Adyen\Payment\Helper\Data $adyenHelper) public function __construct(\Adyen\Payment\Helper\Requests $adyenRequestsHelper)
{ {
$this->adyenHelper = $adyenHelper; $this->adyenRequestsHelper = $adyenRequestsHelper;
} }
/** /**
...@@ -60,14 +59,8 @@ class PaymentDataBuilder implements BuilderInterface ...@@ -60,14 +59,8 @@ class PaymentDataBuilder implements BuilderInterface
$currencyCode = $fullOrder->getOrderCurrencyCode(); $currencyCode = $fullOrder->getOrderCurrencyCode();
$amount = $fullOrder->getGrandTotal(); $amount = $fullOrder->getGrandTotal();
$reference = $order->getOrderIncrementId();
$amount = ['currency' => $currencyCode, return $this->adyenRequestsHelper->buildPaymentData([], $amount, $currencyCode, $reference);
'value' => $this->adyenHelper->formatAmount($amount, $currencyCode)];
return [
"amount" => $amount,
"reference" => $order->getOrderIncrementId(),
"fraudOffset" => "0"
];
} }
} }
...@@ -28,27 +28,27 @@ use Magento\Payment\Gateway\Request\BuilderInterface; ...@@ -28,27 +28,27 @@ use Magento\Payment\Gateway\Request\BuilderInterface;
class RecurringDataBuilder implements BuilderInterface class RecurringDataBuilder implements BuilderInterface
{ {
/** /**
* @var \Adyen\Payment\Helper\Data * @var \Magento\Framework\App\State
*/ */
private $adyenHelper; private $appState;
/** /**
* @var \Magento\Framework\App\State * @var \Adyen\Payment\Helper\Requests
*/ */
private $appState; private $adyenRequestsHelper;
/** /**
* RecurringDataBuilder constructor. * RecurringDataBuilder constructor.
* *
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Model\Context $context
* @param \Adyen\Payment\Helper\Requests $adyenRequestsHelper
*/ */
public function __construct( public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper, \Magento\Framework\Model\Context $context,
\Magento\Framework\Model\Context $context \Adyen\Payment\Helper\Requests $adyenRequestsHelper
) { ) {
$this->adyenHelper = $adyenHelper;
$this->appState = $context->getAppState(); $this->appState = $context->getAppState();
$this->adyenRequestsHelper = $adyenRequestsHelper;
} }
...@@ -59,39 +59,12 @@ class RecurringDataBuilder implements BuilderInterface ...@@ -59,39 +59,12 @@ class RecurringDataBuilder implements BuilderInterface
*/ */
public function build(array $buildSubject) public function build(array $buildSubject)
{ {
$result = [];
// If the vault feature is on this logic is handled in the VaultDataBuilder
if (!$this->adyenHelper->isCreditCardVaultEnabled()) {
/** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */ /** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject); $paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$payment = $paymentDataObject->getPayment(); $payment = $paymentDataObject->getPayment();
$storeId = null;
if ($this->appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
$storeId = $payment->getOrder()->getStoreId(); $storeId = $payment->getOrder()->getStoreId();
} $areaCode = $this->appState->getAreaCode();
$enableOneclick = $this->adyenHelper->getAdyenAbstractConfigData('enable_oneclick', $storeId);
$enableRecurring = $this->adyenHelper->getAdyenAbstractConfigData('enable_recurring', $storeId);
if ($enableOneclick) {
$result['enableOneClick'] = true;
} else {
$result['enableOneClick'] = false;
}
if ($enableRecurring) {
$result['enableRecurring'] = true;
} else {
$result['enableRecurring'] = false;
}
if ($payment->getAdditionalInformation('store_cc') === '1') {
$result['paymentMethod']['storeDetails'] = true;
}
}
return $result; return $this->adyenRequestsHelper->buildRecurringData([], $areaCode, $storeId, $payment);
} }
} }
...@@ -24,17 +24,23 @@ ...@@ -24,17 +24,23 @@
namespace Adyen\Payment\Gateway\Request; namespace Adyen\Payment\Gateway\Request;
use Magento\Payment\Gateway\Request\BuilderInterface; use Magento\Payment\Gateway\Request\BuilderInterface;
use Magento\Vault\Model\Ui\VaultConfigProvider;
use \Magento\Payment\Gateway\Helper\SubjectReader;
class VaultDataBuilder implements BuilderInterface class VaultDataBuilder implements BuilderInterface
{ {
/**
* @var \Adyen\Payment\Helper\Requests
*/
private $adyenRequestsHelper;
/** /**
* Recurring variable * VaultDataBuilder constructor.
* @var string *
* @param \Adyen\Payment\Helper\Requests $adyenRequestsHelper
*/ */
private static $enableRecurring = 'enableRecurring'; public function __construct(\Adyen\Payment\Helper\Requests $adyenRequestsHelper)
{
$this->adyenRequestsHelper = $adyenRequestsHelper;
}
/** /**
* @param array $buildSubject * @param array $buildSubject
...@@ -43,21 +49,11 @@ class VaultDataBuilder implements BuilderInterface ...@@ -43,21 +49,11 @@ class VaultDataBuilder implements BuilderInterface
public function build(array $buildSubject) public function build(array $buildSubject)
{ {
// vault is enabled and shopper provided consent to store card this logic is triggered // vault is enabled and shopper provided consent to store card this logic is triggered
$request = []; /** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
$paymentDO = SubjectReader::readPayment($buildSubject); $paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$payment = $paymentDataObject->getPayment();
$payment = $paymentDO->getPayment(); $additionalInformation = $payment->getAdditionalInformation();
$data = $payment->getAdditionalInformation();
if (!empty($data[VaultConfigProvider::IS_ACTIVE_CODE]) && return $this->adyenRequestsHelper->buildVaultData([], $additionalInformation);
$data[VaultConfigProvider::IS_ACTIVE_CODE] === true
) {
// store it only as oneclick otherwise we store oneclick tokens (maestro+bcmc) that will fail
$request[self::$enableRecurring] = true;
} else {
// explicity turn this off as merchants have recurring on by default
$request[self::$enableRecurring] = false;
}
return $request;
} }
} }
...@@ -174,11 +174,9 @@ class PaymentInformationManagement ...@@ -174,11 +174,9 @@ class PaymentInformationManagement
// Check if 3DS2.0 validation is needed or not // Check if 3DS2.0 validation is needed or not
// In case 3DS2.0 validation is necessary send the type and token back to the frontend // In case 3DS2.0 validation is necessary send the type and token back to the frontend
if (!empty($paymentsResponse['resultCode']) && if (!empty($paymentsResponse['resultCode'])) {
($paymentsResponse['resultCode'] == 'IdentifyShopper' || if ($paymentsResponse['resultCode'] == 'IdentifyShopper' ||
$paymentsResponse['resultCode'] == 'ChallengeShopper') $paymentsResponse['resultCode'] == 'ChallengeShopper') {
) {
if ($this->threeDS2ResponseValidator->validate(array( if ($this->threeDS2ResponseValidator->validate(array(
"response" => $paymentsResponse, "response" => $paymentsResponse,
"payment" => $payment "payment" => $payment
...@@ -188,6 +186,10 @@ class PaymentInformationManagement ...@@ -188,6 +186,10 @@ class PaymentInformationManagement
$payment->getAdditionalInformation('threeDS2Token')); $payment->getAdditionalInformation('threeDS2Token'));
} }
} }
} else {
$errorMsg = __('Error with payment method please select different payment method.');
throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
}
// Save the payments response because we are going to need it during the place order flow // Save the payments response because we are going to need it during the place order flow
$payment->setAdditionalInformation("paymentsResponse", $paymentsResponse); $payment->setAdditionalInformation("paymentsResponse", $paymentsResponse);
......
...@@ -339,7 +339,11 @@ define( ...@@ -339,7 +339,11 @@ define(
fullScreenLoader.stopLoader(); fullScreenLoader.stopLoader();
self.isPlaceOrderActionAllowed(true); self.isPlaceOrderActionAllowed(true);
self.validateThreeDS2OrPlaceOrder(responseJSON); self.validateThreeDS2OrPlaceOrder(responseJSON);
}).error(function() {
fullScreenLoader.stopLoader();
self.isPlaceOrderActionAllowed(true);
}); });
return false; return false;
} }
......
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