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
public function isBoletoPayment()
{
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 false;
......
......@@ -96,9 +96,8 @@ class TransactionAuthorization implements ClientInterface
try {
$response = $service->authorise($request);
} catch(\Adyen\AdyenException $e) {
$response = null;
$response['error'] = $e->getMessage();
}
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;
use Magento\Payment\Gateway\Request\BuilderInterface;
class OneclickAuthorizationBuilder implements BuilderInterface
class OneclickAuthorizationDataBuilder implements BuilderInterface
{
/**
* @var \Adyen\Payment\Helper\Data
......@@ -64,6 +64,11 @@ class OneclickAuthorizationBuilder implements BuilderInterface
$request['selectedRecurringDetailReference'] = $recurringDetailReference;
$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 this it is mandatory to set selectBrand to sepadirectdebit
......
......@@ -25,7 +25,7 @@ namespace Adyen\Payment\Gateway\Request;
use Magento\Payment\Gateway\Request\BuilderInterface;
class SepaAuthorizationBuilder implements BuilderInterface
class SepaAuthorizationDataBuilder implements BuilderInterface
{
/**
* @param array $buildSubject
......
......@@ -54,5 +54,6 @@ class PaymentAuthorisationDetailsHandler implements HandlerInterface
// do not close transaction so you can do a cancel() and void
$payment->setIsTransactionClosed(false);
$payment->setShouldCloseParentTransaction(false);
}
}
\ No newline at end of file
......@@ -60,11 +60,39 @@ class GeneralResponseValidator extends AbstractValidator
$errorMessages = [];
// validate result
if ($response) {
if ($response && isset($response['resultCode'])) {
switch ($response['resultCode']) {
case "Authorised":
$payment->setAdditionalInformation('pspReference', $response['pspReference']);
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":
$payment->setAdditionalInformation('3dActive', true);
$payment->setAdditionalInformation('pspReference', $response['pspReference']);
......@@ -85,10 +113,7 @@ class GeneralResponseValidator extends AbstractValidator
}
break;
case "Refused":
$isValid = false;
if ($response['refusalReason']) {
$refusalReason = $response['refusalReason'];
switch($refusalReason) {
case "Transaction Not Permitted":
......@@ -113,26 +138,17 @@ class GeneralResponseValidator extends AbstractValidator
} 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;
default:
$isValid = false;
$errorMsg = __('Error with payment method please select different payment method.');
$this->logger->critical($errorMsg);
$errorMessages[] = $errorMsg;
throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
break;
}
} else {
$errorMsg = __('Error with payment method please select different payment method.');
$this->logger->critical($errorMsg);
$errorMessages[] = $errorMsg;
throw new \Magento\Framework\Exception\LocalizedException(__($errorMsg));
}
return $this->createResult($isValid, $errorMessages);
......
......@@ -49,7 +49,6 @@ class AdyenGenericConfigProvider implements ConfigProviderInterface
protected $_methodCodes = [
\Adyen\Payment\Model\Method\Hpp::METHOD_CODE,
\Adyen\Payment\Model\Method\Pos::METHOD_CODE,
\Adyen\Payment\Model\Method\Boleto::METHOD_CODE
];
/**
......
......@@ -202,7 +202,6 @@ class PaymentRequest extends DataObject
$request = array_merge($request, $requestDelivery);
}
$enableMoto = $this->_adyenHelper->getAdyenCcConfigDataFlag('enable_moto', $storeId);
$recurringDetailReference = null;
// define the shopper interaction
......@@ -222,33 +221,6 @@ class PaymentRequest extends DataObject
$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);
return $result;
......
This diff is collapsed.
......@@ -21,13 +21,15 @@
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model;
namespace Adyen\Payment\Model\Ui;
use Magento\Checkout\Model\ConfigProviderInterface;
class AdyenBoletoConfigProvider implements ConfigProviderInterface
{
const CODE = 'adyen_boleto';
/**
* @var PaymentHelper
*/
......@@ -39,34 +41,35 @@ class AdyenBoletoConfigProvider implements ConfigProviderInterface
protected $_adyenHelper;
/**
* @var string[]
* @var \Magento\Framework\UrlInterface
*/
protected $_methodCodes = [
\Adyen\Payment\Model\Method\Boleto::METHOD_CODE
];
protected $_urlBuilder;
/**
* @var \Magento\Payment\Model\Method\AbstractMethod[]
* Request object
*
* @var \Magento\Framework\App\RequestInterface
*/
protected $_methods = [];
protected $_request;
/**
* AdyenBoletoConfigProvider constructor.
*
* @param \Magento\Payment\Helper\Data $paymentHelper
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Magento\Framework\UrlInterface $urlBuilder
* @param \Magento\Framework\App\RequestInterface $request
*/
public function __construct(
\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->_adyenHelper = $adyenHelper;
foreach ($this->_methodCodes as $code) {
$this->_methods[$code] = $this->_paymentHelper->getMethodInstance($code);
}
$this->_urlBuilder = $urlBuilder;
$this->_request = $request;
}
/**
......@@ -74,20 +77,28 @@ class AdyenBoletoConfigProvider implements ConfigProviderInterface
*/
public function getConfig()
{
$config = [];
foreach ($this->_methodCodes as $code) {
if ($this->_methods[$code]->isAvailable()) {
$config = [
// set to active
return [
'payment' => [
self::CODE => [
'isActive' => true,
'redirectUrl' => $this->_urlBuilder->getUrl(
'checkout/onepage/success/', ['_secure' => $this->_getRequest()->isSecure()])
],
'adyenBoleto' => [
'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
return $this->ccConfig->getCvvImageUrl();
}
/**
* 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 @@
</adyen_pay_by_mail>
<adyen_boleto>
<active>0</active>
<model>Adyen\Payment\Model\Method\Boleto</model>
<model>AdyenPaymentBoletoFacade</model>
<title>Boleto</title>
<allowspecific>0</allowspecific>
<sort_order>7</sort_order>
<payment_action>authorize</payment_action>
<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>
</adyen_boleto>
</payment>
......
This diff is collapsed.
......@@ -32,4 +32,7 @@
<event name="payment_method_assign_data_adyen_sepa">
<observer name="adyen_sepa_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenSepaDataAssignObserver" />
</event>
<event name="payment_method_assign_data_adyen_boleto">
<observer name="adyen_sepa_gateway_data_assign" instance="Adyen\Payment\Observer\AdyenBoletoDataAssignObserver" />
</event>
</config>
......@@ -32,7 +32,7 @@
<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_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>
</arguments>
</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