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 aa89f491 authored by Rik ter Beek's avatar Rik ter Beek

#67 Adyen CC and Adyen Oneclick are now using the Facade implementation

parent 482fd41f
...@@ -45,21 +45,29 @@ class Validate3d extends \Magento\Framework\App\Action\Action ...@@ -45,21 +45,29 @@ class Validate3d extends \Magento\Framework\App\Action\Action
*/ */
protected $_adyenHelper; protected $_adyenHelper;
/**
* @var \Adyen\Payment\Model\Api\PaymentRequest
*/
protected $_paymentRequest;
/** /**
* Validate3d constructor. * Validate3d constructor.
* *
* @param \Magento\Framework\App\Action\Context $context * @param \Magento\Framework\App\Action\Context $context
* @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
*/ */
public function __construct( public function __construct(
\Magento\Framework\App\Action\Context $context, \Magento\Framework\App\Action\Context $context,
\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
) { ) {
parent::__construct($context); parent::__construct($context);
$this->_adyenLogger = $adyenLogger; $this->_adyenLogger = $adyenLogger;
$this->_adyenHelper = $adyenHelper; $this->_adyenHelper = $adyenHelper;
$this->_paymentRequest = $paymentRequest;
} }
/** /**
...@@ -93,7 +101,17 @@ class Validate3d extends \Magento\Framework\App\Action\Action ...@@ -93,7 +101,17 @@ class Validate3d extends \Magento\Framework\App\Action\Action
$order->getPayment()->setAdditionalInformation('paResponse', $requestPaRes); $order->getPayment()->setAdditionalInformation('paResponse', $requestPaRes);
try { try {
$result = $order->getPayment()->getMethodInstance()->authorise3d($order->getPayment());
/**
* Magento should allow this.
* https://github.com/magento/magento2/issues/5819
*/
// $result = $order->getPayment()->getMethodInstance()->executeCommand(
// 'authorise_3d',
// ['payment' => $order->getPayment(), 'amount' => $order->getGrandTotal()]
// );
// old fashion way:
$result = $this->_authorise3d($order->getPayment());
} catch (\Exception $e) { } catch (\Exception $e) {
$this->_adyenLogger->addAdyenResult("Process 3D secure payment was refused"); $this->_adyenLogger->addAdyenResult("Process 3D secure payment was refused");
$result = 'Refused'; $result = 'Refused';
...@@ -134,6 +152,24 @@ class Validate3d extends \Magento\Framework\App\Action\Action ...@@ -134,6 +152,24 @@ class Validate3d extends \Magento\Framework\App\Action\Action
} }
} }
/**
* Called by validate3d controller when cc payment has 3D secure
*
* @param $payment
* @return mixed
* @throws \Exception
*/
protected function _authorise3d($payment)
{
try {
$response = $this->_paymentRequest->authorise3d($payment);
} catch(\Exception $e) {
throw $e;
}
$responseCode = $response['resultCode'];
return $responseCode;
}
/** /**
* Get order object * Get order object
* *
......
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Gateway\Request;
use Magento\Payment\Gateway\Request\BuilderInterface;
/**
* Payment Data Builder
*/
class Authorize3DSecureDataBuilder implements BuilderInterface
{
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
/**
* PaymentDataBuilder constructor.
*
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(\Adyen\Payment\Helper\Data $adyenHelper)
{
$this->adyenHelper = $adyenHelper;
}
/**
* @param array $buildSubject
* @return array
*/
public function build(array $buildSubject)
{
/** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$payment = $paymentDataObject->getPayment();
$md = $payment->getAdditionalInformation('md');
$paResponse = $payment->getAdditionalInformation('paResponse');
return [
"md" => $md,
"paResponse" => $paResponse,
];
}
}
\ No newline at end of file
...@@ -20,22 +20,27 @@ ...@@ -20,22 +20,27 @@
* *
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
namespace Adyen\Payment\Gateway\Request;
namespace Adyen\Payment\Gateway\Config; use Magento\Payment\Gateway\Request\BuilderInterface;
/** /**
* Class Config * Payment Data Builder
*/ */
class SepaConfig extends \Magento\Payment\Gateway\Config\Config class BrowserInfoDataBuilder implements BuilderInterface
{ {
const KEY_ACTIVE = 'active';
/** /**
* Get Payment configuration status * @param array $buildSubject
* @return bool * @return array
*/ */
public function isActive() public function build(array $buildSubject)
{ {
return (bool) $this->getValue(self::KEY_ACTIVE); return [
'browserInfo' =>
[
'userAgent' => $_SERVER['HTTP_USER_AGENT'],
'acceptHeader' => $_SERVER['HTTP_ACCEPT']
]
];
} }
} }
\ No newline at end of file
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Gateway\Request;
use Magento\Payment\Gateway\Request\BuilderInterface;
class CcAuthorizationDataBuilder implements BuilderInterface
{
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
/**
* @var \Magento\Framework\App\State
*/
private $appState;
/**
* CcAuthorizationDataBuilder constructor.
*
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Framework\Model\Context $context
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\Model\Context $context
) {
$this->adyenHelper = $adyenHelper;
$this->appState = $context->getAppState();
}
/**
* @param array $buildSubject
* @return mixed
*/
public function build(array $buildSubject)
{
/** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$payment = $paymentDataObject->getPayment();
$order = $paymentDataObject->getOrder();
$storeId = $order->getStoreId();
$request = [];
if ($this->adyenHelper->getAdyenCcConfigDataFlag('cse_enabled', $storeId)) {
$request['additionalData']['card.encrypted.json'] =
$payment->getAdditionalInformation("encrypted_data");
} else {
$requestCreditCardDetails = [
"expiryMonth" => $payment->getCcExpMonth(),
"expiryYear" => $payment->getCcExpYear(),
"holderName" => $payment->getCcOwner(),
"number" => $payment->getCcNumber(),
"cvc" => $payment->getCcCid(),
];
$cardDetails['card'] = $requestCreditCardDetails;
$request = array_merge($request, $cardDetails);
}
/**
* if MOTO for backend is enabled use MOTO as shopper interaction type
*/
$enableMoto = $this->adyenHelper->getAdyenCcConfigDataFlag('enable_moto', $storeId);
if ($this->appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE &&
$enableMoto) {
$request['shopperInteraction'] = "Moto";
}
// if installments is set add it into the request
if ($payment->getAdditionalInformation('number_of_installments') &&
$payment->getAdditionalInformation('number_of_installments') > 0) {
$request['installments']['value'] = $payment->getAdditionalInformation('number_of_installments');
}
return $request;
}
}
\ No newline at end of file
...@@ -48,13 +48,11 @@ class CustomerDataBuilder implements BuilderInterface ...@@ -48,13 +48,11 @@ class CustomerDataBuilder implements BuilderInterface
$order = $paymentDataObject->getOrder(); $order = $paymentDataObject->getOrder();
$billingAddress = $order->getBillingAddress(); $billingAddress = $order->getBillingAddress();
$customerEmail = $billingAddress->getEmail(); $customerEmail = $billingAddress->getEmail();
$shopperIp = $order->getRemoteIp();
$realOrderId = $order->getOrderIncrementId(); $realOrderId = $order->getOrderIncrementId();
$customerId = $order->getCustomerId(); $customerId = $order->getCustomerId();
$shopperReference = (!empty($customerId)) ? $customerId : self::GUEST_ID . $realOrderId; $shopperReference = (!empty($customerId)) ? $customerId : self::GUEST_ID . $realOrderId;
return [ return [
"shopperIP" => $shopperIp,
"shopperEmail" => $customerEmail, "shopperEmail" => $customerEmail,
"shopperReference" => $shopperReference "shopperReference" => $shopperReference
]; ];
......
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Gateway\Request;
use Magento\Payment\Gateway\Request\BuilderInterface;
/**
* Class CustomerDataBuilder
*/
class CustomerIpDataBuilder implements BuilderInterface
{
/**
* @param array $buildSubject
* @return array
*/
public function build(array $buildSubject)
{
/** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$order = $paymentDataObject->getOrder();
return ['shopperIP' => $order->getRemoteIp()];
}
}
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Gateway\Request;
use Magento\Payment\Gateway\Request\BuilderInterface;
class OneclickAuthorizationBuilder implements BuilderInterface
{
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
/**
* CaptureDataBuilder constructor.
*
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(\Adyen\Payment\Helper\Data $adyenHelper)
{
$this->adyenHelper = $adyenHelper;
}
/**
* @param array $buildSubject
* @return mixed
*/
public function build(array $buildSubject)
{
$request = [];
/** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
$paymentDataObject = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($buildSubject);
$payment = $paymentDataObject->getPayment();
$recurringDetailReference = $payment->getAdditionalInformation("recurring_detail_reference");
if ($payment->getAdditionalInformation('customer_interaction')) {
$shopperInteraction = "Ecommerce";
} else {
$shopperInteraction = "ContAuth";
}
$request['selectedRecurringDetailReference'] = $recurringDetailReference;
$request['shopperInteraction'] = $shopperInteraction;
/*
* For recurring Ideal and Sofort needs to be converted to SEPA
* for this it is mandatory to set selectBrand to sepadirectdebit
*/
if (!$payment->getAdditionalInformation('customer_interaction')) {
if ($payment->getCcType() == "directEbanking" || $payment->getCcType() == "ideal") {
$request['selectedBrand'] = "sepadirectdebit";
}
}
return $request;
}
}
\ No newline at end of file
...@@ -57,16 +57,13 @@ class PaymentDataBuilder implements BuilderInterface ...@@ -57,16 +57,13 @@ class PaymentDataBuilder implements BuilderInterface
$orderCurrencyCode = $order->getCurrencyCode(); $orderCurrencyCode = $order->getCurrencyCode();
$amount = $order->getGrandTotalAmount(); $amount = $order->getGrandTotalAmount();
$browserInfo = ['userAgent' => $_SERVER['HTTP_USER_AGENT'], 'acceptHeader' => $_SERVER['HTTP_ACCEPT']];
$amount = ['currency' => $orderCurrencyCode, $amount = ['currency' => $orderCurrencyCode,
'value' => $this->adyenHelper->formatAmount($amount, $orderCurrencyCode)]; 'value' => $this->adyenHelper->formatAmount($amount, $orderCurrencyCode)];
return [ return [
"amount" => $amount, "amount" => $amount,
"reference" => $order->getOrderIncrementId(), "reference" => $order->getOrderIncrementId(),
"fraudOffset" => "0", "fraudOffset" => "0"
"browserInfo" => $browserInfo
]; ];
} }
} }
\ No newline at end of file
...@@ -73,7 +73,7 @@ class RecurringDataBuilder implements BuilderInterface ...@@ -73,7 +73,7 @@ class RecurringDataBuilder implements BuilderInterface
// set the recurring type // set the recurring type
$recurringContractType = null; $recurringContractType = null;
if ($recurringType) { if ($recurringType) {
if ($paymentMethodCode == \Adyen\Payment\Model\Method\Oneclick::METHOD_CODE) { if ($paymentMethodCode == \Adyen\Payment\Model\Ui\AdyenOneclickConfigProvider::CODE) {
/* /*
* For ONECLICK look at the recurringPaymentType that the merchant * For ONECLICK look at the recurringPaymentType that the merchant
* has selected in Adyen ONECLICK settings * has selected in Adyen ONECLICK settings
...@@ -83,7 +83,7 @@ class RecurringDataBuilder implements BuilderInterface ...@@ -83,7 +83,7 @@ class RecurringDataBuilder implements BuilderInterface
} else { } else {
$recurringContractType = \Adyen\Payment\Model\RecurringType::RECURRING; $recurringContractType = \Adyen\Payment\Model\RecurringType::RECURRING;
} }
} else if ($paymentMethodCode == \Adyen\Payment\Model\Method\Cc::METHOD_CODE) { } else if ($paymentMethodCode == \Adyen\Payment\Model\Ui\AdyenCcConfigProvider::CODE) {
if ($payment->getAdditionalInformation("store_cc") == "" && if ($payment->getAdditionalInformation("store_cc") == "" &&
($recurringType == "ONECLICK,RECURRING" || $recurringType == "RECURRING")) { ($recurringType == "ONECLICK,RECURRING" || $recurringType == "RECURRING")) {
$recurringContractType = \Adyen\Payment\Model\RecurringType::RECURRING; $recurringContractType = \Adyen\Payment\Model\RecurringType::RECURRING;
......
...@@ -36,6 +36,7 @@ class SepaAuthorizationBuilder implements BuilderInterface ...@@ -36,6 +36,7 @@ class SepaAuthorizationBuilder 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);
$payment = $paymentDataObject->getPayment(); $payment = $paymentDataObject->getPayment();
$request = [];
// set brand to sepa // set brand to sepa
$request['selectedBrand'] = "sepadirectdebit"; $request['selectedBrand'] = "sepadirectdebit";
......
...@@ -43,8 +43,14 @@ class PaymentCommentHistoryHandler implements HandlerInterface ...@@ -43,8 +43,14 @@ class PaymentCommentHistoryHandler implements HandlerInterface
if (isset($response['resultCode'])) { if (isset($response['resultCode'])) {
$responseCode = $response['resultCode']; $responseCode = $response['resultCode'];
} else { } else {
// try to get response from response key (used for modifications
if (isset($response['response'])) {
$responseCode = $response['response'];
} else {
$responseCode = ""; $responseCode = "";
} }
}
if (isset($response['pspReference'])) { if (isset($response['pspReference'])) {
$pspReference = $response['pspReference']; $pspReference = $response['pspReference'];
......
...@@ -27,6 +27,24 @@ use Magento\Payment\Gateway\Validator\AbstractValidator; ...@@ -27,6 +27,24 @@ use Magento\Payment\Gateway\Validator\AbstractValidator;
class GeneralResponseValidator extends AbstractValidator class GeneralResponseValidator extends AbstractValidator
{ {
/**
* @var Psr\Log\LoggerInterface
*/
private $logger;
/**
* GeneralResponseValidator constructor.
* @param ResultInterfaceFactory $resultFactory
* @param \Psr\Log\LoggerInterface $loggerInterface
*/
public function __construct(
\Magento\Payment\Gateway\Validator\ResultInterfaceFactory $resultFactory,
\Psr\Log\LoggerInterface $loggerInterface
) {
$this->logger = $loggerInterface;
parent::__construct($resultFactory);
}
/** /**
* @param array $validationSubject * @param array $validationSubject
* @return \Magento\Payment\Gateway\Validator\ResultInterface * @return \Magento\Payment\Gateway\Validator\ResultInterface
...@@ -37,6 +55,7 @@ class GeneralResponseValidator extends AbstractValidator ...@@ -37,6 +55,7 @@ class GeneralResponseValidator extends AbstractValidator
$paymentDataObjectInterface = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($validationSubject); $paymentDataObjectInterface = \Magento\Payment\Gateway\Helper\SubjectReader::readPayment($validationSubject);
$payment = $paymentDataObjectInterface->getPayment(); $payment = $paymentDataObjectInterface->getPayment();
$payment->setAdditionalInformation('3dActive', false);
$isValid = true; $isValid = true;
$errorMessages = []; $errorMessages = [];
...@@ -46,20 +65,73 @@ class GeneralResponseValidator extends AbstractValidator ...@@ -46,20 +65,73 @@ class GeneralResponseValidator extends AbstractValidator
case "Authorised": case "Authorised":
$payment->setAdditionalInformation('pspReference', $response['pspReference']); $payment->setAdditionalInformation('pspReference', $response['pspReference']);
break; break;
case "RedirectShopper":
$payment->setAdditionalInformation('3dActive', true);
$payment->setAdditionalInformation('pspReference', $response['pspReference']);
$issuerUrl = $response['issuerUrl'];
$paReq = $response['paRequest'];
$md = $response['md'];
if (!empty($paReq) && !empty($md) && !empty($issuerUrl)) {
$payment->setAdditionalInformation('issuerUrl', $response['issuerUrl']);
$payment->setAdditionalInformation('paRequest', $response['paRequest']);
$payment->setAdditionalInformation('md', $response['md']);
} else {
$isValid = false;
$errorMsg = __('3D secure is not valid.');
$this->logger->error($errorMsg);;
$errorMessages[] = $errorMsg;
}
break;
case "Refused": case "Refused":
$isValid = false;
if ($response['refusalReason']) {
$refusalReason = $response['refusalReason'];
switch($refusalReason) {
case "Transaction Not Permitted":
$errorMsg = __('The transaction is not permitted.');
break;
case "CVC Declined":
$errorMsg = __('Declined due to the Card Security Code(CVC) being incorrect. Please check your CVC code!');
break;
case "Restricted Card":
$errorMsg = __('The card is restricted.');
break;
case "803 PaymentDetail not found":
$errorMsg = __('The payment is REFUSED because the saved card is removed. Please try an other payment method.');
break;
case "Expiry month not set":
$errorMsg = __('The expiry month is not set. Please check your expiry month!');
break;
default:
$errorMsg = __('The payment is REFUSED.'); $errorMsg = __('The payment is REFUSED.');
$this->_logger->critical($errorMsg); break;
$errorMessages[] = $errorMsg; }
} else {
$errorMsg = __('The payment is REFUSED.');
}
// exeption is to general
// $this->logger->critical($errorMsg);
// $errorMessages[] = $errorMsg;
// this will result the specific error
throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
break; break;
default: default:
$isValid = false;
$errorMsg = __('Error with payment method please select different payment method.'); $errorMsg = __('Error with payment method please select different payment method.');
$this->_logger->critical($errorMsg); $this->logger->critical($errorMsg);
$errorMessages[] = $errorMsg; $errorMessages[] = $errorMsg;
break; break;
} }
} else { } else {
$errorMsg = __('Error with payment method please select different payment method.'); $errorMsg = __('Error with payment method please select different payment method.');
$this->_logger->critical($errorMsg); $this->logger->critical($errorMsg);
$errorMessages[] = $errorMsg; $errorMessages[] = $errorMsg;
} }
......
...@@ -139,9 +139,11 @@ class PaymentMethods extends AbstractHelper ...@@ -139,9 +139,11 @@ class PaymentMethods extends AbstractHelper
{ {
$paymentMethods = []; $paymentMethods = [];
$ccEnabled = $this->_config->getValue('payment/'.\Adyen\Payment\Model\Method\Cc::METHOD_CODE.'/active'); $ccEnabled = $this->_config->getValue('payment/'.\Adyen\Payment\Model\Ui\AdyenCcConfigProvider::CODE.'/active');
$ccTypes = array_keys($this->_adyenHelper->getCcTypesAltData()); $ccTypes = array_keys($this->_adyenHelper->getCcTypesAltData());
$sepaEnabled = $this->_config->getValue('payment/'.\Adyen\Payment\Model\Method\Sepa::METHOD_CODE.'/active'); $sepaEnabled = $this->_config->getValue(
'payment/'.\Adyen\Payment\Model\Ui\AdyenSepaConfigProvider::CODE.'/active'
);
foreach ($this->_fetchHppMethods($store, $country) as $methodCode => $methodData) { foreach ($this->_fetchHppMethods($store, $country) as $methodCode => $methodData) {
/* /*
...@@ -162,6 +164,7 @@ class PaymentMethods extends AbstractHelper ...@@ -162,6 +164,7 @@ class PaymentMethods extends AbstractHelper
/** /**
* @param $store * @param $store
* @param $country
* @return array * @return array
*/ */
protected function _fetchHppMethods($store, $country) protected function _fetchHppMethods($store, $country)
...@@ -240,6 +243,7 @@ class PaymentMethods extends AbstractHelper ...@@ -240,6 +243,7 @@ class PaymentMethods extends AbstractHelper
return 10; return 10;
} }
/** /**
* @param $store * @param $store
* @return mixed * @return mixed
......
...@@ -47,11 +47,8 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface ...@@ -47,11 +47,8 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface
* @var string[] * @var string[]
*/ */
protected $_methodCodes = [ protected $_methodCodes = [
\Adyen\Payment\Model\Method\Cc::METHOD_CODE,
\Adyen\Payment\Model\Method\Hpp::METHOD_CODE, \Adyen\Payment\Model\Method\Hpp::METHOD_CODE,
\Adyen\Payment\Model\Method\Oneclick::METHOD_CODE,
\Adyen\Payment\Model\Method\Pos::METHOD_CODE, \Adyen\Payment\Model\Method\Pos::METHOD_CODE,
// \Adyen\Payment\Model\Method\Sepa::METHOD_CODE,
\Adyen\Payment\Model\Method\Boleto::METHOD_CODE \Adyen\Payment\Model\Method\Boleto::METHOD_CODE
]; ];
......
...@@ -151,27 +151,8 @@ class PaymentRequest extends DataObject ...@@ -151,27 +151,8 @@ class PaymentRequest extends DataObject
// set the recurring type // set the recurring type
$recurringContractType = null; $recurringContractType = null;
if ($recurringType) { if ($recurringType) {
if ($paymentMethodCode == \Adyen\Payment\Model\Method\Oneclick::METHOD_CODE) {
/*
* For ONECLICK look at the recurringPaymentType that the merchant
* has selected in Adyen ONECLICK settings
*/
if ($payment->getAdditionalInformation('customer_interaction')) {
$recurringContractType = \Adyen\Payment\Model\RecurringType::ONECLICK;
} else {
$recurringContractType = \Adyen\Payment\Model\RecurringType::RECURRING;
}
} else if ($paymentMethodCode == \Adyen\Payment\Model\Method\Cc::METHOD_CODE) {
if ($payment->getAdditionalInformation("store_cc") == "" &&
($recurringType == "ONECLICK,RECURRING" || $recurringType == "RECURRING")) {
$recurringContractType = \Adyen\Payment\Model\RecurringType::RECURRING;
} elseif ($payment->getAdditionalInformation("store_cc") == "1") {
$recurringContractType = $recurringType;
}
} else {
$recurringContractType = $recurringType; $recurringContractType = $recurringType;
} }
}
if ($recurringContractType) { if ($recurringContractType) {
$recurring = ['contract' => $recurringContractType]; $recurring = ['contract' => $recurringContractType];
...@@ -225,31 +206,8 @@ class PaymentRequest extends DataObject ...@@ -225,31 +206,8 @@ class PaymentRequest extends DataObject
$recurringDetailReference = null; $recurringDetailReference = null;
// define the shopper interaction // define the shopper interaction
if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE &&
$paymentMethodCode == \Adyen\Payment\Model\Method\Cc::METHOD_CODE &&
$enableMoto) {
// if MOTO for backend is enabled use MOTO as shopper interaction type
$shopperInteraction = "Moto";
} else if ($paymentMethodCode == \Adyen\Payment\Model\Method\Oneclick::METHOD_CODE) {
$recurringDetailReference = $payment->getAdditionalInformation("recurring_detail_reference");
if ($payment->getAdditionalInformation('customer_interaction')) {
$shopperInteraction = "Ecommerce"; $shopperInteraction = "Ecommerce";
} else {
$shopperInteraction = "ContAuth";
}
/*
* For recurring Ideal and Sofort needs to be converted to SEPA
* for this it is mandatory to set selectBrand to sepadirectdebit
*/
if (!$payment->getAdditionalInformation('customer_interaction')) {
if ($payment->getCcType() == "directEbanking" || $payment->getCcType() == "ideal") {
$request['selectedBrand'] = "sepadirectdebit";
}
}
} else {
$shopperInteraction = "Ecommerce";
}
if ($shopperInteraction) { if ($shopperInteraction) {
$request['shopperInteraction'] = $shopperInteraction; $request['shopperInteraction'] = $shopperInteraction;
...@@ -264,43 +222,7 @@ class PaymentRequest extends DataObject ...@@ -264,43 +222,7 @@ class PaymentRequest extends DataObject
$request['selectedBrand'] = "sepadirectdebit"; $request['selectedBrand'] = "sepadirectdebit";
} }
if ($paymentMethodCode == \Adyen\Payment\Model\Method\Cc::METHOD_CODE || if ($paymentMethodCode == \Adyen\Payment\Model\Method\Boleto::METHOD_CODE) {
$paymentMethodCode == \Adyen\Payment\Model\Method\Oneclick::METHOD_CODE) {
// If cse is enabled add encrypted card date into request
if ($this->_adyenHelper->getAdyenCcConfigDataFlag('cse_enabled', $storeId)) {
$request['additionalData']['card.encrypted.json'] =
$payment->getAdditionalInformation("encrypted_data");
} else {
$requestCreditCardDetails = [
"expiryMonth" => $payment->getCcExpMonth(),
"expiryYear" => $payment->getCcExpYear(),
"holderName" => $payment->getCcOwner(),
"number" => $payment->getCcNumber(),
"cvc" => $payment->getCcCid(),
];
$cardDetails['card'] = $requestCreditCardDetails;
$request = array_merge($request, $cardDetails);
}
// if installments is set add it into the request
if ($payment->getAdditionalInformation('number_of_installments') &&
$payment->getAdditionalInformation('number_of_installments') > 0) {
$request['installments']['value'] = $payment->getAdditionalInformation('number_of_installments');
}
} elseif ($paymentMethodCode == \Adyen\Payment\Model\Method\Sepa::METHOD_CODE) {
// set brand to sepa
$request['selectedBrand'] = "sepadirectdebit";
// add bankDetails into request
$bankAccount = [
'iban' => $payment->getAdditionalInformation("iban"),
'ownerName' => $payment->getAdditionalInformation("account_name"),
'countryCode' => $payment->getAdditionalInformation("country")
];
$request['bankAccount'] = $bankAccount;
} elseif ($paymentMethodCode == \Adyen\Payment\Model\Method\Boleto::METHOD_CODE) {
$request['socialSecurityNumber'] = $payment->getAdditionalInformation("social_security_number"); $request['socialSecurityNumber'] = $payment->getAdditionalInformation("social_security_number");
......
This diff is collapsed.
...@@ -331,7 +331,11 @@ class Pos extends \Magento\Payment\Model\Method\AbstractMethod implements Gatewa ...@@ -331,7 +331,11 @@ class Pos extends \Magento\Payment\Model\Method\AbstractMethod implements Gatewa
"&currency=".$currencyCode."&merchantReference=".$merchantReference. $recurringParams . "&currency=".$currencyCode."&merchantReference=".$merchantReference. $recurringParams .
$receiptOrderLines . "&callback=".$callbackUrl . $extraParamaters; $receiptOrderLines . "&callback=".$callbackUrl . $extraParamaters;
$this->_adyenLogger->debug(print_r($launchlink, true)); // cash not working see ticket
// https://youtrack.is.adyen.com/issue/IOS-130#comment=102-20285
// . "&transactionType=CASH";
$this->_adyenLogger->addAdyenDebug(print_r($launchlink, true));
return $launchlink; return $launchlink;
} }
......
...@@ -21,21 +21,17 @@ ...@@ -21,21 +21,17 @@
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
namespace Adyen\Payment\Model; namespace Adyen\Payment\Model\Ui;
use Magento\Payment\Model\CcGenericConfigProvider; use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Payment\Helper\Data as PaymentHelper; use Magento\Payment\Helper\Data as PaymentHelper;
use Magento\Framework\View\Asset\Source as Source; use Magento\Framework\View\Asset\Source as Source;
use \Magento\Payment\Gateway\Config\Config as Config;
class AdyenCcConfigProvider extends CcGenericConfigProvider class AdyenCcConfigProvider implements ConfigProviderInterface
{ {
/** const CODE = 'adyen_cc';
* @var string[]
*/
protected $_methodCodes = [
\Adyen\Payment\Model\Method\Cc::METHOD_CODE
];
/** /**
* @var PaymentHelper * @var PaymentHelper
...@@ -52,24 +48,49 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider ...@@ -52,24 +48,49 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider
*/ */
protected $_assetSource; protected $_assetSource;
/**
* Request object
*
* @var \Magento\Framework\App\RequestInterface
*/
protected $_request;
/**
* @var \Magento\Framework\UrlInterface
*/
protected $_urlBuilder;
/**
* @var \Magento\Payment\Model\CcConfig
*/
private $ccConfig;
/** /**
* AdyenCcConfigProvider constructor. * AdyenCcConfigProvider constructor.
* *
* @param \Magento\Payment\Model\CcConfig $ccConfig
* @param PaymentHelper $paymentHelper * @param PaymentHelper $paymentHelper
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Framework\App\RequestInterface $request
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param Source $assetSource * @param Source $assetSource
* @param \Magento\Payment\Model\CcConfig $ccConfig
* @param Config $config
*/ */
public function __construct( public function __construct(
\Magento\Payment\Model\CcConfig $ccConfig,
PaymentHelper $paymentHelper, PaymentHelper $paymentHelper,
\Adyen\Payment\Helper\Data $adyenHelper, \Adyen\Payment\Helper\Data $adyenHelper,
Source $assetSource \Magento\Framework\App\RequestInterface $request,
\Magento\Framework\UrlInterface $urlBuilder,
Source $assetSource,
\Magento\Payment\Model\CcConfig $ccConfig
) { ) {
parent::__construct($ccConfig, $paymentHelper, $this->_methodCodes);
$this->_paymentHelper = $paymentHelper; $this->_paymentHelper = $paymentHelper;
$this->_adyenHelper = $adyenHelper; $this->_adyenHelper = $adyenHelper;
$this->_request = $request;
$this->_urlBuilder = $urlBuilder;
$this->_assetSource = $assetSource; $this->_assetSource = $assetSource;
$this->ccConfig = $ccConfig;
} }
/** /**
...@@ -77,10 +98,30 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider ...@@ -77,10 +98,30 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider
*/ */
public function getConfig() public function getConfig()
{ {
$config = parent::getConfig(); // set to active
$config = [
'payment' => [
self::CODE => [
'isActive' => true,
'redirectUrl' => $this->_urlBuilder->getUrl(
'adyen/process/validate3d/', ['_secure' => $this->_getRequest()->isSecure()])
]
]
];
$methodCode = self::CODE;
foreach ($this->_methodCodes as $code) { $config = array_merge_recursive($config, [
if ($this->methods[$code]->isAvailable()) { 'payment' => [
'ccform' => [
'availableTypes' => [$methodCode => $this->getCcAvailableTypes($methodCode)],
'months' => [$methodCode => $this->getCcMonths()],
'years' => [$methodCode => $this->getCcYears()],
'hasVerification' => [$methodCode => $this->hasVerification($methodCode)],
'cvvImageUrl' => [$methodCode => $this->getCvvImageUrl()]
]
]
]);
$demoMode = $this->_adyenHelper->getAdyenAbstractConfigDataFlag('demo_mode'); $demoMode = $this->_adyenHelper->getAdyenAbstractConfigDataFlag('demo_mode');
...@@ -117,8 +158,6 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider ...@@ -117,8 +158,6 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider
} else { } else {
$config['payment']['adyenCc']['installments'] = []; $config['payment']['adyenCc']['installments'] = [];
} }
}
}
return $config; return $config;
} }
...@@ -133,7 +172,7 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider ...@@ -133,7 +172,7 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider
{ {
$types = []; $types = [];
$ccTypes = $this->_adyenHelper->getAdyenCcTypes(); $ccTypes = $this->_adyenHelper->getAdyenCcTypes();
$availableTypes = $this->methods[$methodCode]->getConfigData('cctypes'); $availableTypes = $this->_adyenHelper->getAdyenCcConfigData('cctypes');
if ($availableTypes) { if ($availableTypes) {
$availableTypes = explode(',', $availableTypes); $availableTypes = explode(',', $availableTypes);
foreach (array_keys($ccTypes) as $code) { foreach (array_keys($ccTypes) as $code) {
...@@ -171,4 +210,55 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider ...@@ -171,4 +210,55 @@ class AdyenCcConfigProvider extends CcGenericConfigProvider
} }
return $icons; return $icons;
} }
/**
* Retrieve credit card expire months
*
* @return array
*/
protected function getCcMonths()
{
return $this->ccConfig->getCcMonths();
}
/**
* Retrieve credit card expire years
*
* @return array
*/
protected function getCcYears()
{
return $this->ccConfig->getCcYears();
}
/**
* Has verification is always true
*
* @return bool
*/
protected function hasVerification()
{
return $this->_adyenHelper->getAdyenCcConfigData('useccv');
}
/**
* Retrieve CVV tooltip image url
*
* @return string
*/
protected function getCvvImageUrl()
{
return $this->ccConfig->getCvvImageUrl();
}
/**
* Retrieve request object
*
* @return \Magento\Framework\App\RequestInterface
*/
protected function _getRequest()
{
return $this->_request;
}
} }
\ No newline at end of file
...@@ -21,40 +21,31 @@ ...@@ -21,40 +21,31 @@
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
namespace Adyen\Payment\Model; namespace Adyen\Payment\Model\Ui;
use Magento\Payment\Model\CcGenericConfigProvider; use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Payment\Helper\Data as PaymentHelper; use Magento\Payment\Helper\Data as PaymentHelper;
class AdyenOneclickConfigProvider extends CcGenericConfigProvider class AdyenOneclickConfigProvider implements ConfigProviderInterface
{ {
const CODE = 'adyen_oneclick';
/** /**
* @var Config * @var Config
*/ */
protected $config; protected $config;
/**
* @var string[]
*/
protected $_methodCodes = [
\Adyen\Payment\Model\Method\Oneclick::METHOD_CODE
];
/** /**
* @var \Magento\Payment\Model\Method\AbstractMethod[] * @var \Adyen\Payment\Helper\Data
*/
protected $methods = [];
/**
* @var PaymentHelper
*/ */
protected $_paymentHelper; protected $_adyenHelper;
/** /**
* @var \Adyen\Payment\Helper\Data * @var \Magento\Framework\App\RequestInterface
*/ */
protected $_adyenHelper; protected $_request;
/** /**
* @var \Magento\Customer\Model\Session * @var \Magento\Customer\Model\Session
...@@ -67,42 +58,46 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider ...@@ -67,42 +58,46 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
protected $_session; protected $_session;
/** /**
* @var \Magento\Framework\App\State * @var \Magento\Store\Model\StoreManagerInterface
*/ */
protected $_appState; protected $_storeManager;
/** /**
* @var \Magento\Store\Model\StoreManagerInterface * @var \Magento\Framework\UrlInterface
*/ */
protected $_storeManager; protected $_urlBuilder;
/**
* @var \Magento\Payment\Model\CcConfig
*/
private $ccConfig;
/** /**
* AdyenOneclickConfigProvider constructor. * AdyenOneclickConfigProvider constructor.
* *
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Payment\Model\CcConfig $ccConfig
* @param PaymentHelper $paymentHelper
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Framework\App\RequestInterface $request
* @param \Magento\Customer\Model\Session $customerSession * @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Checkout\Model\Session $session * @param \Magento\Checkout\Model\Session $session
* @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\UrlInterface $urlBuilder
*/ */
public function __construct( public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Payment\Model\CcConfig $ccConfig,
PaymentHelper $paymentHelper,
\Adyen\Payment\Helper\Data $adyenHelper, \Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\App\RequestInterface $request,
\Magento\Customer\Model\Session $customerSession, \Magento\Customer\Model\Session $customerSession,
\Magento\Checkout\Model\Session $session, \Magento\Checkout\Model\Session $session,
\Magento\Store\Model\StoreManagerInterface $storeManager \Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Payment\Model\CcConfig $ccConfig
) { ) {
parent::__construct($ccConfig, $paymentHelper, $this->_methodCodes);
$this->_paymentHelper = $paymentHelper;
$this->_adyenHelper = $adyenHelper; $this->_adyenHelper = $adyenHelper;
$this->_request = $request;
$this->_customerSession = $customerSession; $this->_customerSession = $customerSession;
$this->_session = $session; $this->_session = $session;
$this->_appState = $context->getAppState();
$this->_storeManager = $storeManager; $this->_storeManager = $storeManager;
$this->_urlBuilder = $urlBuilder;
$this->ccConfig = $ccConfig;
} }
/** /**
...@@ -110,7 +105,30 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider ...@@ -110,7 +105,30 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
*/ */
public function getConfig() public function getConfig()
{ {
$config = parent::getConfig(); // set to active
$config = [
'payment' => [
self::CODE => [
'isActive' => true,
'redirectUrl' => $this->_urlBuilder->getUrl(
'adyen/process/validate3d/', ['_secure' => $this->_getRequest()->isSecure()])
]
]
];
$methodCode = self::CODE;
$config = array_merge_recursive($config, [
'payment' => [
'ccform' => [
'availableTypes' => [$methodCode => $this->getCcAvailableTypes($methodCode)],
'months' => [$methodCode => $this->getCcMonths()],
'years' => [$methodCode => $this->getCcYears()],
'hasVerification' => [$methodCode => $this->hasVerification($methodCode)],
'cvvImageUrl' => [$methodCode => $this->getCvvImageUrl()]
]
]
]);
$demoMode = $this->_adyenHelper->getAdyenAbstractConfigDataFlag('demo_mode'); $demoMode = $this->_adyenHelper->getAdyenAbstractConfigDataFlag('demo_mode');
...@@ -134,9 +152,6 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider ...@@ -134,9 +152,6 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
$config['payment']['adyenOneclick']['generationTime'] = date("c"); $config['payment']['adyenOneclick']['generationTime'] = date("c");
$config['payment']['adyenOneclick']['canCreateBillingAgreement'] = $canCreateBillingAgreement; $config['payment']['adyenOneclick']['canCreateBillingAgreement'] = $canCreateBillingAgreement;
foreach ($this->_methodCodes as $code) {
if ($this->methods[$code]->isAvailable()) {
$recurringContractType = $this->_getRecurringContractType(); $recurringContractType = $this->_getRecurringContractType();
$config['payment'] ['adyenOneclick']['billingAgreements'] = $this->getAdyenOneclickPaymentMethods(); $config['payment'] ['adyenOneclick']['billingAgreements'] = $this->getAdyenOneclickPaymentMethods();
...@@ -145,8 +160,7 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider ...@@ -145,8 +160,7 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
} else { } else {
$config['payment'] ['adyenOneclick']['hasCustomerInteraction'] = false; $config['payment'] ['adyenOneclick']['hasCustomerInteraction'] = false;
} }
}
}
return $config; return $config;
} }
...@@ -163,7 +177,12 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider ...@@ -163,7 +177,12 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
$grandTotal = $this->_getQuote()->getGrandTotal(); $grandTotal = $this->_getQuote()->getGrandTotal();
$recurringType = $this->_getRecurringContractType(); $recurringType = $this->_getRecurringContractType();
$billingAgreements = $this->_adyenHelper->getOneClickPaymentMethods($customerId, $storeId, $grandTotal, $recurringType); $billingAgreements = $this->_adyenHelper->getOneClickPaymentMethods(
$customerId,
$storeId,
$grandTotal,
$recurringType
);
} }
return $billingAgreements; return $billingAgreements;
} }
...@@ -183,4 +202,80 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider ...@@ -183,4 +202,80 @@ class AdyenOneclickConfigProvider extends CcGenericConfigProvider
{ {
return $this->_session->getQuote(); return $this->_session->getQuote();
} }
/**
* Retrieve availables credit card types
*
* @param string $methodCode
* @return array
*/
protected function getCcAvailableTypes($methodCode)
{
$types = [];
$ccTypes = $this->_adyenHelper->getAdyenCcTypes();
$availableTypes = $this->_adyenHelper->getAdyenCcConfigData('cctypes');
if ($availableTypes) {
$availableTypes = explode(',', $availableTypes);
foreach (array_keys($ccTypes) as $code) {
if (in_array($code, $availableTypes)) {
$types[$code] = $ccTypes[$code]['name'];
}
}
}
return $types;
}
/**
* Retrieve credit card expire months
*
* @return array
*/
protected function getCcMonths()
{
return $this->ccConfig->getCcMonths();
}
/**
* Retrieve credit card expire years
*
* @return array
*/
protected function getCcYears()
{
return $this->ccConfig->getCcYears();
}
/**
* Has verification is always true
*
* @return bool
*/
protected function hasVerification()
{
return $this->_adyenHelper->getAdyenCcConfigData('useccv');
}
/**
* Retrieve CVV tooltip image url
*
* @return string
*/
protected function getCvvImageUrl()
{
return $this->ccConfig->getCvvImageUrl();
}
/**
* Retrieve request object
*
* @return \Magento\Framework\App\RequestInterface
*/
protected function _getRequest()
{
return $this->_request;
}
} }
\ No newline at end of file
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Observer;
use Magento\Framework\Event\Observer;
use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Quote\Api\Data\PaymentInterface;
/**
* Class DataAssignObserver
*/
class AdyenCcDataAssignObserver extends AbstractDataAssignObserver
{
const CC_TYPE = 'cc_type';
const ENCRYPTED_DATA = 'encrypted_data';
const NUMBER_OF_INSTALLMENTS = 'number_of_installments';
const STORE_CC = 'store_cc';
/**
* @var array
*/
protected $additionalInformationList = [
self::CC_TYPE,
self::ENCRYPTED_DATA,
self::NUMBER_OF_INSTALLMENTS,
self::STORE_CC
];
/**
* @param Observer $observer
* @return void
*/
public function execute(Observer $observer)
{
$data = $this->readDataArgument($observer);
$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
if (!is_array($additionalData)) {
return;
}
$paymentInfo = $this->readPaymentModelArgument($observer);
// set ccType
$paymentInfo->setCcType($additionalData['cc_type']);
foreach ($this->additionalInformationList as $additionalInformationKey) {
if (isset($additionalData[$additionalInformationKey])) {
$paymentInfo->setAdditionalInformation(
$additionalInformationKey,
$additionalData[$additionalInformationKey]
);
}
}
}
}
...@@ -20,87 +20,95 @@ ...@@ -20,87 +20,95 @@
* *
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
namespace Adyen\Payment\Observer;
namespace Adyen\Payment\Model\Method; use Magento\Framework\Event\Observer;
use Magento\Framework\Webapi\Exception; use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Quote\Api\Data\PaymentInterface;
/** /**
* Adyen CreditCard payment method * Class DataAssignObserver
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/ */
class Oneclick extends \Adyen\Payment\Model\Method\Cc class AdyenOneclickDataAssignObserver extends AbstractDataAssignObserver
{ {
const METHOD_CODE = 'adyen_oneclick'; const RECURRING_DETAIL_REFERENCE = 'recurring_detail_reference';
const ENCRYPTED_DATA = 'encrypted_data';
const NUMBER_OF_INSTALLMENTS = 'number_of_installments';
/** /**
* @var string * @var array
*/ */
protected $_code = self::METHOD_CODE; protected $additionalInformationList = [
self::RECURRING_DETAIL_REFERENCE,
self::ENCRYPTED_DATA,
self::NUMBER_OF_INSTALLMENTS
];
/** /**
* @var string * @var \Adyen\Payment\Helper\Data
*/ */
protected $_formBlockType = 'Adyen\Payment\Block\Form\Oneclick'; private $adyenHelper;
/** /**
* @var string * @var \Magento\Framework\App\State
*/ */
protected $_infoBlockType = 'Adyen\Payment\Block\Info\Oneclick'; private $appState;
/** /**
* Assign data to info model instance * AdyenCcDataAssignObserver constructor.
* * @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Framework\DataObject|mixed $data
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/ */
public function assignData(\Magento\Framework\DataObject $data) public function __construct(
{ \Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\Model\Context $context
) {
$this->adyenHelper = $adyenHelper;
$this->appState = $context->getAppState();
if (!$data instanceof \Magento\Framework\DataObject) {
$data = new \Magento\Framework\DataObject($data);
} }
$additionalData = $data->getAdditionalData(); /**
$infoInstance = $this->getInfoInstance(); * @param Observer $observer
* @return void
*/
// get from variant magento code for creditcard type and set this in ccType public function execute(Observer $observer)
$variant = $additionalData['variant']; {
$ccType = $this->_adyenHelper->getMagentoCreditCartType($variant); $data = $this->readDataArgument($observer);
$infoInstance->setCcType($ccType);
// save value remember details checkbox $additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
$infoInstance->setAdditionalInformation('recurring_detail_reference', if (!is_array($additionalData)) {
$additionalData['recurring_detail_reference']); return;
}
$recurringPaymentType = $this->getRecurringPaymentType(); $paymentInfo = $this->readPaymentModelArgument($observer);
if ($recurringPaymentType == \Adyen\Payment\Model\RecurringType::ONECLICK) {
$customerInteraction = true;
// retrieve cse key // set ccType
if ($this->_adyenHelper->getAdyenCcConfigDataFlag('cse_enabled')) { $variant = $additionalData['variant'];
if (isset($additionalData['encrypted_data'])) { $ccType = $this->adyenHelper->getMagentoCreditCartType($variant);
$infoInstance->setAdditionalInformation('encrypted_data', $additionalData['encrypted_data']); $paymentInfo->setCcType($ccType);
} else {
throw new \Magento\Framework\Exception\LocalizedException(__('Card encryption failed')); foreach ($this->additionalInformationList as $additionalInformationKey) {
if (isset($additionalData[$additionalInformationKey])) {
$paymentInfo->setAdditionalInformation(
$additionalInformationKey,
$additionalData[$additionalInformationKey]
);
} }
} }
// set customerInteraction
$recurringContractType = $this->getRecurringPaymentType();
if ($recurringContractType == \Adyen\Payment\Model\RecurringType::ONECLICK) {
$paymentInfo->setAdditionalInformation('customer_interaction', true);
} else { } else {
$customerInteraction = false; $paymentInfo->setAdditionalInformation('customer_interaction', false);
} }
$infoInstance->setAdditionalInformation('customer_interaction', $customerInteraction); // set ccType
$variant = $additionalData['variant'];
// set number of installements $ccType = $this->adyenHelper->getMagentoCreditCartType($variant);
if (isset($additionalData['number_of_installments'])) { $paymentInfo->setAdditionalInformation('cc_type', $ccType);
$infoInstance->setAdditionalInformation('number_of_installments',
$additionalData['number_of_installments']);
}
return $this;
} }
/** /**
...@@ -112,33 +120,10 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc ...@@ -112,33 +120,10 @@ class Oneclick extends \Adyen\Payment\Model\Method\Cc
public function getRecurringPaymentType() public function getRecurringPaymentType()
{ {
// For admin always use Recurring // For admin always use Recurring
if ($this->_appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) { if ($this->appState->getAreaCode() === \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE) {
return \Adyen\Payment\Model\RecurringType::RECURRING; return \Adyen\Payment\Model\RecurringType::RECURRING;
} else { } else {
return $this->_adyenHelper->getAdyenOneclickConfigData('recurring_payment_type'); return $this->adyenHelper->getAdyenOneclickConfigData('recurring_payment_type');
}
}
/**
* @param \Adyen\Payment\Model\Billing\Agreement $agreement
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function updateBillingAgreementStatus(\Adyen\Payment\Model\Billing\Agreement $agreement)
{
$targetStatus = $agreement->getStatus();
if ($targetStatus == \Magento\Paypal\Model\Billing\Agreement::STATUS_CANCELED) {
try {
$this->_paymentRequest->disableRecurringContract(
$agreement->getReferenceId(),
$agreement->getCustomerReference(),
$agreement->getStoreId()
);
} catch(Exception $e) {
throw new \Magento\Framework\Exception\LocalizedException(__('Failed to disable this contract'));
}
} }
return $this;
} }
} }
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
</adyen_abstract> </adyen_abstract>
<adyen_cc> <adyen_cc>
<active>1</active> <active>1</active>
<model>Adyen\Payment\Model\Method\Cc</model> <model>AdyenPaymentCcFacade</model>
<title>Adyen CreditCard</title> <title>Adyen CreditCard</title>
<allowspecific>0</allowspecific> <allowspecific>0</allowspecific>
<sort_order>2</sort_order> <sort_order>2</sort_order>
...@@ -47,17 +47,43 @@ ...@@ -47,17 +47,43 @@
<cse_enabled>1</cse_enabled> <cse_enabled>1</cse_enabled>
<enable_moto>0</enable_moto> <enable_moto>0</enable_moto>
<payment_action>authorize</payment_action> <payment_action>authorize</payment_action>
<is_gateway>1</is_gateway>
<can_use_checkout>1</can_use_checkout>
<can_authorize>1</can_authorize>
<can_authorize_3d>1</can_authorize_3d>
<can_capture>1</can_capture>
<can_capture_partial>1</can_capture_partial>
<can_use_internal>1</can_use_internal>
<can_refund_partial_per_invoice>1</can_refund_partial_per_invoice>
<can_refund>1</can_refund>
<can_void>1</can_void>
<can_cancel>1</can_cancel>
<group>adyen</group> <group>adyen</group>
</adyen_cc> </adyen_cc>
<adyen_oneclick> <adyen_oneclick>
<active>1</active> <active>1</active>
<model>Adyen\Payment\Model\Method\Oneclick</model> <model>AdyenPaymentOneclickFacade</model>
<title>Adyen OneClick</title> <title>Adyen OneClick</title>
<allowspecific>0</allowspecific> <allowspecific>0</allowspecific>
<sort_order>1</sort_order> <sort_order>1</sort_order>
<cctypes>AE,VI,MC,DI</cctypes> <!-- important to show the payment method isAvailabe()--> <cctypes>AE,VI,MC,DI</cctypes> <!-- important to show the payment method isAvailabe()-->
<recurring_payment_type>ONECLICK</recurring_payment_type> <recurring_payment_type>ONECLICK</recurring_payment_type>
<payment_action>authorize</payment_action> <payment_action>authorize</payment_action>
<useccv>1</useccv>
<cse_enabled>1</cse_enabled>
<enable_moto>0</enable_moto>
<payment_action>authorize</payment_action>
<is_gateway>1</is_gateway>
<can_use_checkout>1</can_use_checkout>
<can_authorize>1</can_authorize>
<can_authorize_3d>1</can_authorize_3d>
<can_capture>1</can_capture>
<can_capture_partial>1</can_capture_partial>
<can_use_internal>1</can_use_internal>
<can_refund_partial_per_invoice>1</can_refund_partial_per_invoice>
<can_refund>1</can_refund>
<can_void>1</can_void>
<can_cancel>1</can_cancel>
<group>adyen</group> <group>adyen</group>
</adyen_oneclick> </adyen_oneclick>
<adyen_hpp> <adyen_hpp>
...@@ -77,7 +103,7 @@ ...@@ -77,7 +103,7 @@
</adyen_hpp> </adyen_hpp>
<adyen_sepa> <adyen_sepa>
<active>0</active> <active>0</active>
<model>AdyenSepaFacade</model> <model>AdyenPaymentSepaFacade</model>
<title>Sepa Direct Debit</title> <title>Sepa Direct Debit</title>
<allowspecific>0</allowspecific> <allowspecific>0</allowspecific>
<sort_order>4</sort_order> <sort_order>4</sort_order>
......
This diff is collapsed.
...@@ -23,6 +23,12 @@ ...@@ -23,6 +23,12 @@
*/ */
--> -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="payment_method_assign_data_adyen_cc">
<observer name="adyen_cc_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenCcDataAssignObserver" />
</event>
<event name="payment_method_assign_data_adyen_oneclick">
<observer name="adyen_cc_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenOneclickDataAssignObserver" />
</event>
<event name="payment_method_assign_data_adyen_sepa"> <event name="payment_method_assign_data_adyen_sepa">
<observer name="adyen_sepa_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenSepaDataAssignObserver" /> <observer name="adyen_sepa_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenSepaDataAssignObserver" />
</event> </event>
......
...@@ -28,8 +28,8 @@ ...@@ -28,8 +28,8 @@
<arguments> <arguments>
<argument name="configProviders" xsi:type="array"> <argument name="configProviders" xsi:type="array">
<item name="adyen_generic_config_provider" xsi:type="object">Adyen\Payment\Model\AdyenGenericConfigProvider</item> <item name="adyen_generic_config_provider" xsi:type="object">Adyen\Payment\Model\AdyenGenericConfigProvider</item>
<item name="adyen_cc_config_provider" xsi:type="object">Adyen\Payment\Model\AdyenCcConfigProvider</item> <item name="adyen_cc_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenCcConfigProvider</item>
<item name="adyen_oneclick_config_provider" xsi:type="object">Adyen\Payment\Model\AdyenOneclickConfigProvider</item> <item name="adyen_oneclick_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenOneclickConfigProvider</item>
<item name="adyen_hpp_config_provider" xsi:type="object">Adyen\Payment\Model\AdyenHppConfigProvider</item> <item name="adyen_hpp_config_provider" xsi:type="object">Adyen\Payment\Model\AdyenHppConfigProvider</item>
<item name="adyen_sepa_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenSepaConfigProvider</item> <item name="adyen_sepa_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\AdyenSepaConfigProvider</item>
<item name="adyen_boleto_config_provider" xsi:type="object">Adyen\Payment\Model\AdyenBoletoConfigProvider</item> <item name="adyen_boleto_config_provider" xsi:type="object">Adyen\Payment\Model\AdyenBoletoConfigProvider</item>
......
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