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

#67 Adyen Boleto is now using the Facade implementation

parent eff192e4
...@@ -88,7 +88,7 @@ class Success extends \Magento\Framework\View\Element\Template ...@@ -88,7 +88,7 @@ class Success extends \Magento\Framework\View\Element\Template
public function isBoletoPayment() public function isBoletoPayment()
{ {
if ($this->getOrder()->getPayment() && if ($this->getOrder()->getPayment() &&
$this->getOrder()->getPayment()->getMethod() == \Adyen\Payment\Model\Method\Boleto::METHOD_CODE) { $this->getOrder()->getPayment()->getMethod() == \Adyen\Payment\Model\Ui\AdyenBoletoConfigProvider::CODE) {
return true; return true;
} }
return false; return false;
......
...@@ -96,9 +96,8 @@ class TransactionAuthorization implements ClientInterface ...@@ -96,9 +96,8 @@ class TransactionAuthorization implements ClientInterface
try { try {
$response = $service->authorise($request); $response = $service->authorise($request);
} catch(\Adyen\AdyenException $e) { } catch(\Adyen\AdyenException $e) {
$response = null; $response['error'] = $e->getMessage();
} }
return $response; return $response;
} }
} }
<?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 BoletoAuthorizationDataBuilder 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)
{
/** @var \Magento\Payment\Gateway\Data\PaymentDataObject $paymentDataObject */
/** @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 = [];
$request['socialSecurityNumber'] = $payment->getAdditionalInformation("social_security_number");
$request['selectedBrand'] = $payment->getAdditionalInformation("boleto_type");
$shopperName = [
'firstName' => $payment->getAdditionalInformation("firstname"),
'lastName' => $payment->getAdditionalInformation("lastname"),
];
$request['shopperName'] = $shopperName;
$deliveryDays = (int) $this->adyenHelper->getAdyenBoletoConfigData("delivery_days", $storeId);
$deliveryDays = (!empty($deliveryDays)) ? $deliveryDays : 5;
$deliveryDate = date(
"Y-m-d\TH:i:s ",
mktime(date("H"),
date("i"),
date("s"),
date("m"),
date("j") + $deliveryDays,
date("Y"))
);
$request['deliveryDate'] = $deliveryDate;
return $request;
}
}
\ No newline at end of file
...@@ -25,7 +25,7 @@ namespace Adyen\Payment\Gateway\Request; ...@@ -25,7 +25,7 @@ namespace Adyen\Payment\Gateway\Request;
use Magento\Payment\Gateway\Request\BuilderInterface; use Magento\Payment\Gateway\Request\BuilderInterface;
class OneclickAuthorizationBuilder implements BuilderInterface class OneclickAuthorizationDataBuilder implements BuilderInterface
{ {
/** /**
* @var \Adyen\Payment\Helper\Data * @var \Adyen\Payment\Helper\Data
...@@ -64,6 +64,11 @@ class OneclickAuthorizationBuilder implements BuilderInterface ...@@ -64,6 +64,11 @@ class OneclickAuthorizationBuilder implements BuilderInterface
$request['selectedRecurringDetailReference'] = $recurringDetailReference; $request['selectedRecurringDetailReference'] = $recurringDetailReference;
$request['shopperInteraction'] = $shopperInteraction; $request['shopperInteraction'] = $shopperInteraction;
// if it is a sepadirectdebit set selectedBrand to sepadirectdebit in the case of oneclick
if ($payment->getCcType() == "sepadirectdebit") {
$request['selectedBrand'] = "sepadirectdebit";
}
/* /*
* For recurring Ideal and Sofort needs to be converted to SEPA * For recurring Ideal and Sofort needs to be converted to SEPA
* for this it is mandatory to set selectBrand to sepadirectdebit * for this it is mandatory to set selectBrand to sepadirectdebit
......
...@@ -25,7 +25,7 @@ namespace Adyen\Payment\Gateway\Request; ...@@ -25,7 +25,7 @@ namespace Adyen\Payment\Gateway\Request;
use Magento\Payment\Gateway\Request\BuilderInterface; use Magento\Payment\Gateway\Request\BuilderInterface;
class SepaAuthorizationBuilder implements BuilderInterface class SepaAuthorizationDataBuilder implements BuilderInterface
{ {
/** /**
* @param array $buildSubject * @param array $buildSubject
......
...@@ -54,5 +54,6 @@ class PaymentAuthorisationDetailsHandler implements HandlerInterface ...@@ -54,5 +54,6 @@ class PaymentAuthorisationDetailsHandler implements HandlerInterface
// do not close transaction so you can do a cancel() and void // do not close transaction so you can do a cancel() and void
$payment->setIsTransactionClosed(false); $payment->setIsTransactionClosed(false);
$payment->setShouldCloseParentTransaction(false); $payment->setShouldCloseParentTransaction(false);
} }
} }
\ No newline at end of file
...@@ -60,11 +60,39 @@ class GeneralResponseValidator extends AbstractValidator ...@@ -60,11 +60,39 @@ class GeneralResponseValidator extends AbstractValidator
$errorMessages = []; $errorMessages = [];
// validate result // validate result
if ($response) { if ($response && isset($response['resultCode'])) {
switch ($response['resultCode']) { switch ($response['resultCode']) {
case "Authorised": case "Authorised":
$payment->setAdditionalInformation('pspReference', $response['pspReference']); $payment->setAdditionalInformation('pspReference', $response['pspReference']);
break; break;
case "Received":
$payment->setAdditionalInformation('pspReference', $response['pspReference']);
// set additionalData
if (isset($response['additionalData']) && is_array($response['additionalData'])) {
$additionalData = $response['additionalData'];
if (isset($additionalData['boletobancario.dueDate'])) {
$payment->setAdditionalInformation(
'dueDate',
$additionalData['boletobancario.dueDate']
);
}
if (isset($additionalData['boletobancario.expirationDate'])) {
$payment->setAdditionalInformation(
'expirationDate',
$additionalData['boletobancario.expirationDate']
);
}
if (isset($additionalData['boletobancario.url'])) {
$payment->setAdditionalInformation(
'url',
$additionalData['boletobancario.url']
);
}
}
break;
case "RedirectShopper": case "RedirectShopper":
$payment->setAdditionalInformation('3dActive', true); $payment->setAdditionalInformation('3dActive', true);
$payment->setAdditionalInformation('pspReference', $response['pspReference']); $payment->setAdditionalInformation('pspReference', $response['pspReference']);
...@@ -85,10 +113,7 @@ class GeneralResponseValidator extends AbstractValidator ...@@ -85,10 +113,7 @@ class GeneralResponseValidator extends AbstractValidator
} }
break; break;
case "Refused": case "Refused":
$isValid = false;
if ($response['refusalReason']) { if ($response['refusalReason']) {
$refusalReason = $response['refusalReason']; $refusalReason = $response['refusalReason'];
switch($refusalReason) { switch($refusalReason) {
case "Transaction Not Permitted": case "Transaction Not Permitted":
...@@ -113,26 +138,17 @@ class GeneralResponseValidator extends AbstractValidator ...@@ -113,26 +138,17 @@ class GeneralResponseValidator extends AbstractValidator
} else { } else {
$errorMsg = __('The payment is REFUSED.'); $errorMsg = __('The payment is REFUSED.');
} }
// exeption is to general
// $this->logger->critical($errorMsg);
// $errorMessages[] = $errorMsg;
// this will result the specific error // this will result the specific error
throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg)); 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); throw new \Magento\Framework\Exception\LocalizedException(__($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); throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
$errorMessages[] = $errorMsg;
} }
return $this->createResult($isValid, $errorMessages); return $this->createResult($isValid, $errorMessages);
......
...@@ -49,7 +49,6 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface ...@@ -49,7 +49,6 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface
protected $_methodCodes = [ protected $_methodCodes = [
\Adyen\Payment\Model\Method\Hpp::METHOD_CODE, \Adyen\Payment\Model\Method\Hpp::METHOD_CODE,
\Adyen\Payment\Model\Method\Pos::METHOD_CODE, \Adyen\Payment\Model\Method\Pos::METHOD_CODE,
\Adyen\Payment\Model\Method\Boleto::METHOD_CODE
]; ];
/** /**
......
...@@ -202,7 +202,6 @@ class PaymentRequest extends DataObject ...@@ -202,7 +202,6 @@ class PaymentRequest extends DataObject
$request = array_merge($request, $requestDelivery); $request = array_merge($request, $requestDelivery);
} }
$enableMoto = $this->_adyenHelper->getAdyenCcConfigDataFlag('enable_moto', $storeId);
$recurringDetailReference = null; $recurringDetailReference = null;
// define the shopper interaction // define the shopper interaction
...@@ -222,33 +221,6 @@ class PaymentRequest extends DataObject ...@@ -222,33 +221,6 @@ class PaymentRequest extends DataObject
$request['selectedBrand'] = "sepadirectdebit"; $request['selectedBrand'] = "sepadirectdebit";
} }
if ($paymentMethodCode == \Adyen\Payment\Model\Method\Boleto::METHOD_CODE) {
$request['socialSecurityNumber'] = $payment->getAdditionalInformation("social_security_number");
$request['selectedBrand'] = $payment->getAdditionalInformation("boleto_type");
$shopperName = [
'firstName' => $payment->getAdditionalInformation("firstname"),
'lastName' => $payment->getAdditionalInformation("lastname"),
];
$request['shopperName'] = $shopperName;
$deliveryDays = (int) $this->_adyenHelper->getAdyenBoletoConfigData("delivery_days", $storeId);
$deliveryDays = (!empty($deliveryDays)) ? $deliveryDays : 5;
$deliveryDate = date(
"Y-m-d\TH:i:s ",
mktime(date("H"),
date("i"),
date("s"),
date("m"),
date("j") + $deliveryDays,
date("Y"))
);
$request['deliveryDate'] = $deliveryDate;
}
$result = $service->authorise($request); $result = $service->authorise($request);
return $result; return $result;
......
This diff is collapsed.
...@@ -21,13 +21,15 @@ ...@@ -21,13 +21,15 @@
* Author: Adyen <magento@adyen.com> * Author: Adyen <magento@adyen.com>
*/ */
namespace Adyen\Payment\Model; namespace Adyen\Payment\Model\Ui;
use Magento\Checkout\Model\ConfigProviderInterface; use Magento\Checkout\Model\ConfigProviderInterface;
class AdyenBoletoConfigProvider implements ConfigProviderInterface class AdyenBoletoConfigProvider implements ConfigProviderInterface
{ {
const CODE = 'adyen_boleto';
/** /**
* @var PaymentHelper * @var PaymentHelper
*/ */
...@@ -39,34 +41,35 @@ class AdyenBoletoConfigProvider implements ConfigProviderInterface ...@@ -39,34 +41,35 @@ class AdyenBoletoConfigProvider implements ConfigProviderInterface
protected $_adyenHelper; protected $_adyenHelper;
/** /**
* @var string[] * @var \Magento\Framework\UrlInterface
*/ */
protected $_methodCodes = [ protected $_urlBuilder;
\Adyen\Payment\Model\Method\Boleto::METHOD_CODE
];
/** /**
* @var \Magento\Payment\Model\Method\AbstractMethod[] * Request object
*
* @var \Magento\Framework\App\RequestInterface
*/ */
protected $_methods = []; protected $_request;
/** /**
* AdyenBoletoConfigProvider constructor. * AdyenBoletoConfigProvider constructor.
* *
* @param \Magento\Payment\Helper\Data $paymentHelper * @param \Magento\Payment\Helper\Data $paymentHelper
* @param \Adyen\Payment\Helper\Data $adyenHelper * @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param \Magento\Framework\App\RequestInterface $request
*/ */
public function __construct( public function __construct(
\Magento\Payment\Helper\Data $paymentHelper, \Magento\Payment\Helper\Data $paymentHelper,
\Adyen\Payment\Helper\Data $adyenHelper \Adyen\Payment\Helper\Data $adyenHelper,
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Framework\App\RequestInterface $request
) { ) {
$this->_paymentHelper = $paymentHelper; $this->_paymentHelper = $paymentHelper;
$this->_adyenHelper = $adyenHelper; $this->_adyenHelper = $adyenHelper;
$this->_urlBuilder = $urlBuilder;
foreach ($this->_methodCodes as $code) { $this->_request = $request;
$this->_methods[$code] = $this->_paymentHelper->getMethodInstance($code);
}
} }
/** /**
...@@ -74,20 +77,28 @@ class AdyenBoletoConfigProvider implements ConfigProviderInterface ...@@ -74,20 +77,28 @@ class AdyenBoletoConfigProvider implements ConfigProviderInterface
*/ */
public function getConfig() public function getConfig()
{ {
$config = []; // set to active
return [
foreach ($this->_methodCodes as $code) {
if ($this->_methods[$code]->isAvailable()) {
$config = [
'payment' => [ 'payment' => [
self::CODE => [
'isActive' => true,
'redirectUrl' => $this->_urlBuilder->getUrl(
'checkout/onepage/success/', ['_secure' => $this->_getRequest()->isSecure()])
],
'adyenBoleto' => [ 'adyenBoleto' => [
'boletoTypes' => $this->_adyenHelper->getBoletoTypes() 'boletoTypes' => $this->_adyenHelper->getBoletoTypes()
] ]
] ]
]; ];
} }
}
return $config; /**
* Retrieve request object
*
* @return \Magento\Framework\App\RequestInterface
*/
protected function _getRequest()
{
return $this->_request;
} }
} }
\ No newline at end of file
...@@ -251,7 +251,6 @@ class AdyenCcConfigProvider implements ConfigProviderInterface ...@@ -251,7 +251,6 @@ class AdyenCcConfigProvider implements ConfigProviderInterface
return $this->ccConfig->getCvvImageUrl(); return $this->ccConfig->getCvvImageUrl();
} }
/** /**
* Retrieve request object * Retrieve request 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\Observer;
use Magento\Framework\Event\Observer;
use Magento\Payment\Observer\AbstractDataAssignObserver;
use Magento\Quote\Api\Data\PaymentInterface;
/**
* Class DataAssignObserver
*/
class AdyenBoletoDataAssignObserver extends AbstractDataAssignObserver
{
const SOCIAL_SECURITY_NUMBER = 'social_security_number';
const BOLETO_TYPE = 'boleto_type';
const FIRSTNAME = 'firstname';
const LASTNAME = 'lastname';
/**
* @var array
*/
protected $additionalInformationList = [
self::SOCIAL_SECURITY_NUMBER,
self::BOLETO_TYPE,
self::FIRSTNAME,
self::LASTNAME
];
/**
* @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);
foreach ($this->additionalInformationList as $additionalInformationKey) {
if (isset($additionalData[$additionalInformationKey])) {
$paymentInfo->setAdditionalInformation(
$additionalInformationKey,
$additionalData[$additionalInformationKey]
);
}
}
}
}
...@@ -145,12 +145,22 @@ ...@@ -145,12 +145,22 @@
</adyen_pay_by_mail> </adyen_pay_by_mail>
<adyen_boleto> <adyen_boleto>
<active>0</active> <active>0</active>
<model>Adyen\Payment\Model\Method\Boleto</model> <model>AdyenPaymentBoletoFacade</model>
<title>Boleto</title> <title>Boleto</title>
<allowspecific>0</allowspecific> <allowspecific>0</allowspecific>
<sort_order>7</sort_order> <sort_order>7</sort_order>
<payment_action>authorize</payment_action> <payment_action>authorize</payment_action>
<delivery_days>5</delivery_days> <delivery_days>5</delivery_days>
<is_gateway>1</is_gateway>
<can_use_checkout>1</can_use_checkout>
<can_authorize>1</can_authorize>
<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_boleto> </adyen_boleto>
</payment> </payment>
......
This diff is collapsed.
...@@ -32,4 +32,7 @@ ...@@ -32,4 +32,7 @@
<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>
<event name="payment_method_assign_data_adyen_boleto">
<observer name="adyen_sepa_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenBoletoDataAssignObserver" />
</event>
</config> </config>
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<item name="adyen_oneclick_config_provider" xsi:type="object">Adyen\Payment\Model\Ui\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\Ui\AdyenBoletoConfigProvider</item>
</argument> </argument>
</arguments> </arguments>
</type> </type>
......
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