Skip to content

Commit

Permalink
Remove electronic signature from SEPA method
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennelandais committed Jun 19, 2018
1 parent 272fce0 commit b5dfbb2
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 294 deletions.
130 changes: 32 additions & 98 deletions Model/Method/Sdd.php
Expand Up @@ -17,12 +17,9 @@
namespace HiPay\FullserviceMagento\Model\Method;

use HiPay\FullserviceMagento\Model\FullserviceMethod;
use \HiPay\FullserviceMagento\Logger\Logger;
use Magento\Framework\Exception\LocalizedException;
use \HiPay\FullserviceMagento\Model\Gateway\Factory as GatewayManagerFactory;
use Zend\Validator;
use Magento\Directory\Model;
use Magento\Sales\Model\Order\Payment\Transaction\Repository as TransactionRepository;

/**
* SDD Method
Expand Down Expand Up @@ -82,29 +79,10 @@ class Sdd extends FullserviceMethod
];

/**
* Sdd constructor.
* @param TransactionRepository $transactionRepository
* @param Context $context
* @param \HiPay\FullserviceMagento\Model\PaymentProfileFactory $profileFactory
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
* @param array $data
* Get Additional Information Keys
*
* @return array|string[]
*/
public function __construct(
TransactionRepository $transactionRepository,
\HiPay\FullserviceMagento\Model\Method\Context $context,
\HiPay\FullserviceMagento\Model\PaymentProfileFactory $profileFactory,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
parent::__construct($transactionRepository, $context, $resource, $resourceCollection, $data);

if ($this->getConfigData('electronic_signature')) {
$this->setIsInitializeNeeded(true);
}
}

protected function getAddtionalInformationKeys()
{
return array_merge(['profile_id'], $this->_additionalInformationKeys);
Expand Down Expand Up @@ -134,87 +112,43 @@ public function _assignAdditionalInformation(\Magento\Framework\DataObject $addi
*/
public function validate()
{
/*
* calling parent validate function
*/
/**
* Calling parent validate function
*/
parent::validate();
$info = $this->getInfoInstance();

if (!$this->getConfigData('electronic_signature')) {
$errorMsg = '';
$errorMsg = '';

// Get iso code from order or quote ( Validate is called twice per magento core )
$order = $info->getQuote();
if ($info->getOrder()) {
$order = $info->getOrder();
}
// Get iso code from order or quote ( Validate is called twice per magento core )
$order = $info->getQuote();
if ($info->getOrder()) {
$order = $info->getOrder();
}

// Instantiate validators for the model
$validatorIban = new \Zend\Validator\Iban(
array('country_code' => $order->getBillingAddress()->getCountryId())
);
$validatorEmpty = new \Zend\Validator\NotEmpty();

if (!$validatorIban->isValid($info->getAdditionalInformation('sdd_iban'))) {
$errorMsg = __('Iban is not correct, please enter a valid Iban.');
} else {
if (!$validatorEmpty->isValid($info->getAdditionalInformation('sdd_firstname'))) {
$errorMsg = __('Firstname is mandatory.');
} elseif (!$validatorEmpty->isValid($info->getAdditionalInformation('sdd_lastname'))) {
$errorMsg = _('Lastname is mandatory.');
} elseif (!$validatorEmpty->isValid($info->getAdditionalInformation('sdd_code_bic'))) {
$errorMsg = __('Code BIC is not correct, please enter a valid Code BIC.');
} elseif (!$validatorEmpty->isValid($info->getAdditionalInformation('sdd_bank_name'))) {
$errorMsg = __('Bank name is not correct, please enter a valid Bank name.');
}
// Instantiate validators for the model
$validatorIban = new \Zend\Validator\Iban(
array('country_code' => $order->getBillingAddress()->getCountryId())
);
$validatorEmpty = new \Zend\Validator\NotEmpty();

if (!$validatorIban->isValid($info->getAdditionalInformation('sdd_iban'))) {
$errorMsg = __('Iban is not correct, please enter a valid Iban.');
} else {
if (!$validatorEmpty->isValid($info->getAdditionalInformation('sdd_firstname'))) {
$errorMsg = __('Firstname is mandatory.');
} elseif (!$validatorEmpty->isValid($info->getAdditionalInformation('sdd_lastname'))) {
$errorMsg = _('Lastname is mandatory.');
} elseif (!$validatorEmpty->isValid($info->getAdditionalInformation('sdd_code_bic'))) {
$errorMsg = __('Code BIC is not correct, please enter a valid Code BIC.');
} elseif (!$validatorEmpty->isValid($info->getAdditionalInformation('sdd_bank_name'))) {
$errorMsg = __('Bank name is not correct, please enter a valid Bank name.');
}
}

if ($errorMsg) {
throw new \Magento\Framework\Exception\LocalizedException($errorMsg);
}
if ($errorMsg) {
throw new \Magento\Framework\Exception\LocalizedException($errorMsg);
}
return $this;
}

/**
* Instantiate state and set it to state object
*
* @param string $paymentAction
* @param \Magento\Framework\DataObject $stateObject
* @return void
*/
public function initialize($paymentAction, $stateObject)
{
$payment = $this->getInfoInstance();
$order = $payment->getOrder();
$order->setCanSendNewEmailFlag(false);
$payment->setAmountAuthorized($order->getTotalDue());
$payment->setBaseAmountAuthorized($order->getBaseTotalDue());

$this->_setHostedUrl($order);

$stateObject->setState(\Magento\Sales\Model\Order::STATE_PENDING_PAYMENT);
$stateObject->setStatus('pending_payment');
$stateObject->setIsNotified(false);
}

protected function _setHostedUrl(\Magento\Sales\Model\Order $order)
{
$gateway = $this->_gatewayManagerFactory->create($order);

//Call fullservice api to get hosted page url
$hppModel = $gateway->requestNewOrder();
$order->getPayment()->setAdditionalInformation('redirectUrl', $hppModel->getForwardUrl());
}

/**
* Set initialization requirement state
*
* @param bool $isInitializeNeeded
* @return void
*/
public function setIsInitializeNeeded($isInitializeNeeded = true)
{
$this->_isInitializeNeeded = (bool)$isInitializeNeeded;
}
}
146 changes: 0 additions & 146 deletions Model/Method/SddConfigProvider.php

This file was deleted.

19 changes: 8 additions & 11 deletions Model/Request/PaymentMethod/SEPADirectDebitPayment.php
Expand Up @@ -13,6 +13,7 @@
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0 Licence
*
*/

namespace HiPay\FullserviceMagento\Model\Request\PaymentMethod;

use HiPay\Fullservice\Gateway\Request\PaymentMethod\SEPADirectDebitPaymentMethod;
Expand All @@ -38,18 +39,14 @@ protected function mapRequest()
{
$sddPaymentMethod = new SEPADirectDebitPaymentMethod();
$sddPaymentMethod->recurring_payment = 0;
$electronic_signature = $this->_config->getValue('electronic_signature');
$sddPaymentMethod->authentication_indicator = (int)$electronic_signature;

if (!$electronic_signature) {
/** @var HiPay\Fullservice\Gateway\Request\PaymentMethod\SEPADirectDebitPaymentMethod */
$sddPaymentMethod->bank_name = $this->_order->getPayment()->getAdditionalInformation('sdd_bank_name');
$sddPaymentMethod->issuer_bank_id = $this->_order->getPayment()->getAdditionalInformation('sdd_bic');
$sddPaymentMethod->iban = $this->_order->getPayment()->getAdditionalInformation('sdd_iban');
$sddPaymentMethod->firstname = $this->_order->getPayment()->getAdditionalInformation('sdd_firstname');
$sddPaymentMethod->lastname = $this->_order->getPayment()->getAdditionalInformation('sdd_lastname');
$sddPaymentMethod->gender = $this->_order->getPayment()->getAdditionalInformation('sdd_gender');
}
/** @var HiPay\Fullservice\Gateway\Request\PaymentMethod\SEPADirectDebitPaymentMethod */
$sddPaymentMethod->bank_name = $this->_order->getPayment()->getAdditionalInformation('sdd_bank_name');
$sddPaymentMethod->issuer_bank_id = $this->_order->getPayment()->getAdditionalInformation('sdd_bic');
$sddPaymentMethod->iban = $this->_order->getPayment()->getAdditionalInformation('sdd_iban');
$sddPaymentMethod->firstname = $this->_order->getPayment()->getAdditionalInformation('sdd_firstname');
$sddPaymentMethod->lastname = $this->_order->getPayment()->getAdditionalInformation('sdd_lastname');
$sddPaymentMethod->gender = $this->_order->getPayment()->getAdditionalInformation('sdd_gender');

return $sddPaymentMethod;
}
Expand Down
6 changes: 1 addition & 5 deletions etc/adminhtml/system/method/sdd.xml
Expand Up @@ -30,10 +30,6 @@
-->
<include path="HiPay_FullserviceMagento::system/method/base_top.xml"/>
<include path="HiPay_FullserviceMagento::system/method/base_country.xml"/>
<field id="electronic_signature" translate="label" type="select" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Enable the electronic signature of the mandate</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<include path="HiPay_FullserviceMagento::system/method/base_bottom.xml"/>
</group>
</include>
</include>
8 changes: 0 additions & 8 deletions etc/frontend/di.xml
Expand Up @@ -27,13 +27,6 @@
</argument>
</arguments>
</type>
<type name="HiPay\FullserviceMagento\Model\Method\SddConfigProvider">
<arguments>
<argument name="methodCodes" xsi:type="array">
<item name="hipay_sdd" xsi:type="const">HiPay\FullserviceMagento\Model\Method\Sdd::HIPAY_METHOD_CODE</item>
</argument>
</arguments>
</type>
<type name="HiPay\FullserviceMagento\Model\Method\SplitConfigProvider">
<arguments>
<argument name="methodCodes" xsi:type="array">
Expand Down Expand Up @@ -105,7 +98,6 @@
<item name="hipay_fullservice_generic_config_provider" xsi:type="object">HiPay\FullserviceMagento\Model\Method\GenericConfigProvider</item>
<item name="hipay_cc_config_provider" xsi:type="object">HiPay\FullserviceMagento\Model\CcConfigProvider</item>
<item name="hipay_split_config_provider" xsi:type="object">HiPay\FullserviceMagento\Model\Method\SplitConfigProvider</item>
<item name="hipay_sdd_config_provider" xsi:type="object">HiPay\FullserviceMagento\Model\Method\SddConfigProvider</item>
<item name="hipay_astropay_config_provider" xsi:type="object">HiPay\FullserviceMagento\Model\Method\Astropay\AstropayConfigProvider</item>
</argument>
</arguments>
Expand Down
1 change: 0 additions & 1 deletion i18n/fr_FR.csv
Expand Up @@ -305,7 +305,6 @@ Title,Title
"HiPay Enterprise Santander","HiPay Enterprise Santander"
"HiPay Enterprise Santander Cash","HiPay Enterprise Santander Cash"
"HiPay Enterprise SEPA Direct Debit","HiPay Enterprise SEPA Direct Debit"
"Enable the electronic signature of the mandate","Activer la signature électronique"
"HiPay Fullservice SISAL Hosted","HiPay Fullservice SISAL Hosted"
"Important, HTTPS protocol is required","Important, le protocole HTTPS est requis."
"Impossible to split the amount.","Impossible de diviser le montant."
Expand Down

0 comments on commit b5dfbb2

Please sign in to comment.