From 1c4f693c09c5f5089ca941bbf698af13c40fb87a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Wed, 18 Nov 2020 12:06:31 +0100 Subject: [PATCH 1/7] M2-52 - Added integration of the Bank Account Management Service --- Block/Customer/Bankdata.php | 66 +++++++ Block/Customer/DataLink.php | 43 +++++ Controller/Customer/Bankdata.php | 52 ++++++ Controller/Customer/Delete.php | 67 +++++++ Helper/Content/Customer/BankAccount.php | 9 +- Model/BamsApi/Base.php | 172 ++++++++++++++++++ Model/BamsApi/DeleteBankAccount.php | 33 ++++ Model/BamsApi/GetStoredBankAccounts.php | 106 +++++++++++ Model/BamsApi/StoreBankAccount.php | 41 +++++ Model/Method/AbstractMethod.php | 42 ++++- Model/RechnungConfigProvider.php | 124 ++++++++++++- composer.json | 2 +- etc/adminhtml/system.xml | 38 +++- i18n/de_DE.csv | 9 + i18n/en_GB.csv | 5 + i18n/en_US.csv | 5 + view/base/web/css/ratepay.css | 51 +++++- view/frontend/layout/customer_account.xml | 12 ++ .../layout/ratepay_customer_bankdata.xml | 11 ++ .../templates/customer/bankdata.phtml | 27 +++ .../payment/method-renderer/directdebit.js | 62 ++++++- .../web/template/payment/directdebit.html | 73 +++++--- 22 files changed, 1013 insertions(+), 37 deletions(-) create mode 100644 Block/Customer/Bankdata.php create mode 100644 Block/Customer/DataLink.php create mode 100644 Controller/Customer/Bankdata.php create mode 100644 Controller/Customer/Delete.php create mode 100644 Model/BamsApi/Base.php create mode 100644 Model/BamsApi/DeleteBankAccount.php create mode 100644 Model/BamsApi/GetStoredBankAccounts.php create mode 100644 Model/BamsApi/StoreBankAccount.php create mode 100644 view/frontend/layout/customer_account.xml create mode 100644 view/frontend/layout/ratepay_customer_bankdata.xml create mode 100644 view/frontend/templates/customer/bankdata.phtml diff --git a/Block/Customer/Bankdata.php b/Block/Customer/Bankdata.php new file mode 100644 index 0000000..6887f5c --- /dev/null +++ b/Block/Customer/Bankdata.php @@ -0,0 +1,66 @@ +getStoredBankAccounts = $getStoredBankAccounts; + $this->customerSession = $customerSession; + } + + /** + * Generate action url + * + * @param string $sHash + * @param string $sAction + * @return string + */ + public function getActionUrl($sHash, $sAction) + { + return $this->getUrl('ratepay/customer/'.$sAction, ['hash' => $sHash]); + } + + /** + * Retrieve bank data from Ratepay + * + * @return array|bool + */ + public function getSavedBankData() + { + $iCustomerId = $this->customerSession->getCustomerId(); + $aBankAccounts = $this->getStoredBankAccounts->getBankDataForAllDebitProfiles($iCustomerId); + if (empty($aBankAccounts)) { + return false; + } + return $aBankAccounts; + } +} \ No newline at end of file diff --git a/Block/Customer/DataLink.php b/Block/Customer/DataLink.php new file mode 100644 index 0000000..ece7809 --- /dev/null +++ b/Block/Customer/DataLink.php @@ -0,0 +1,43 @@ +rpDataHelper = $rpDataHelper; + } + + /** + * Render block HTML + * + * @return string + */ + public function toHtml() + { + if ((bool)$this->rpDataHelper->getRpConfigDataByPath('ratepay/general/bams_enabled') === true) { + return parent::toHtml(); + } + return ''; + } +} diff --git a/Controller/Customer/Bankdata.php b/Controller/Customer/Bankdata.php new file mode 100644 index 0000000..bcc7f45 --- /dev/null +++ b/Controller/Customer/Bankdata.php @@ -0,0 +1,52 @@ +pageFactory = $pageFactory; + $this->rpDataHelper = $rpDataHelper; + } + + /** + * Dispatch request + * + * @return \Magento\Framework\Controller\ResultInterface|ResponseInterface + * @throws \Magento\Framework\Exception\NotFoundException + */ + public function execute() + { + if ((bool)$this->rpDataHelper->getRpConfigDataByPath('ratepay/general/bams_enabled') === true) { + $resultPage = $this->pageFactory->create(); + $resultPage->getConfig()->getTitle()->set(__('Bank data management')); + + return $resultPage; + } + return $this->resultRedirectFactory->create()->setPath('customer/account'); + } +} \ No newline at end of file diff --git a/Controller/Customer/Delete.php b/Controller/Customer/Delete.php new file mode 100644 index 0000000..4b7ec83 --- /dev/null +++ b/Controller/Customer/Delete.php @@ -0,0 +1,67 @@ +customerSession = $customerSession; + $this->getStoredBankAccounts = $getStoredBankAccounts; + $this->deleteBankAccount = $deleteBankAccount; + } + + /** + * Dispatch request + * + * @return \Magento\Framework\Controller\Result\Redirect + */ + public function execute() + { + $sDeleteHash = $this->getRequest()->getParam('hash'); + + $iCustomerId = $this->customerSession->getCustomerId(); + $aBankAccounts = $this->getStoredBankAccounts->getBankDataForAllDebitProfiles($iCustomerId); + foreach ($aBankAccounts as $aBankData) { + if ($aBankData['hash'] == $sDeleteHash) { + $this->deleteBankAccount->sendRequest($iCustomerId, $aBankData['profile'], $aBankData['bank_account_reference']); + break; + } + } + return $this->resultRedirectFactory->create()->setPath('ratepay/customer/bankdata'); + } +} \ No newline at end of file diff --git a/Helper/Content/Customer/BankAccount.php b/Helper/Content/Customer/BankAccount.php index 3f8e58f..ae1dced 100644 --- a/Helper/Content/Customer/BankAccount.php +++ b/Helper/Content/Customer/BankAccount.php @@ -41,10 +41,17 @@ public function getBankAccount($quoteOrOrder) { $return = false; + $ibanReference = $quoteOrOrder->getPayment()->getAdditionalInformation('rp_iban_reference'); + if (!empty($ibanReference)) { + return [ + 'Reference' => $ibanReference, + ]; + } + $iban = $quoteOrOrder->getPayment()->getAdditionalInformation('rp_iban'); $accountHolder = $quoteOrOrder->getPayment()->getAdditionalInformation('rp_accountholder'); if (!empty($iban)) { - $return =[ + $return = [ 'Owner' => $quoteOrOrder->getBillingAddress()->getFirstname() . ' ' . $quoteOrOrder->getBillingAddress()->getLastname(), //'BankName' => //'BankAccountNumber' => '1234567891', diff --git a/Model/BamsApi/Base.php b/Model/BamsApi/Base.php new file mode 100644 index 0000000..49663a4 --- /dev/null +++ b/Model/BamsApi/Base.php @@ -0,0 +1,172 @@ +rpDataHelper = $rpDataHelper; + } + + /** + * Generates url parameter string + * + * @param array|bool $aUrlParameters + * @return string + */ + protected function getUrlParameterString($aUrlParameters = false) + { + $sUrlParams = ''; + if ($aUrlParameters !== false) { + foreach ($aUrlParameters as $sParamName => $sParamValue) { + $sUrlParams .= '/'.$sParamName; + if (!empty($sParamValue)) { + $sUrlParams .= '/'.$sParamValue; + } + } + } + return $sUrlParams; + } + + /** + * Returns BAMS api url based on configuration + * + * @param array|false $aUrlParameters + * @return string + */ + protected function getBamsApiUrl($aUrlParameters = false) + { + $sUrlParams = $this->getUrlParameterString($aUrlParameters); + if ((bool)$this->rpDataHelper->getRpConfigDataByPath("ratepay/general/bams_sandbox") === true) { + return $this->sBamsSandboxUrl.$sUrlParams; + } + return $this->sBamsProductionUrl.$sUrlParams; + } + + /** + * Returns HTTP response code + * + * @return int|null + */ + public function getHttpResponseCode() + { + return $this->iHttpResponseCode; + } + + /** + * Generates a auth token by requesting it from the oauth service + * Returns token if already received + * + * @return array|false + */ + protected function getAuthToken() + { + if ($this->aAuthToken === null) { + $aRequest = [ + 'client_id' => 'snbFcxD4Rxt2O4YqeGqDls9yrGWYhmQ0', + 'client_secret' => 'IHa7jiW0hMlH0VsoxDTZ03XH76NED7RwFvJLsmmUXg9fkowhiVQqp7EA84WoYT1Q', + 'audience' => $this->getBamsApiUrl(), + 'grant_type' => 'client_credentials' + ]; + $aResponse = $this->sendCurlRequest($this->sOauthUrl, 'POST', $aRequest, false); + + if (!isset($aResponse['access_token'])) { + return false; + } + + $this->aAuthToken = $aResponse; + } + return $this->aAuthToken; + } + + /** + * Sends json post request to given url + * + * @param string $sUrl + * @param string $sRequestType + * @param array $aPostBody + * @param bool $blNeedsAuthToken + * @return array|mixed + */ + protected function sendCurlRequest($sUrl, $sRequestType, $aPostBody = false, $blNeedsAuthToken = true) + { + $aHeaders = []; + if ($blNeedsAuthToken === true) { + $aAuthToken = $this->getAuthToken(); + if ($aAuthToken !== false) { + $aHeaders[] = 'Authorization: Bearer '.$aAuthToken['access_token']; + } + } + + $oCurl = curl_init($sUrl); + if ($aPostBody !== false) { + $aHeaders[] = 'Content-Type: application/json'; + curl_setopt($oCurl, CURLOPT_POST, 1); + curl_setopt($oCurl, CURLOPT_POSTFIELDS, json_encode($aPostBody)); + } + curl_setopt($oCurl, CURLOPT_CUSTOMREQUEST, $sRequestType); + curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, 0); + curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($oCurl, CURLOPT_HTTPHEADER, $aHeaders); + $sResult = curl_exec($oCurl); + + $this->iHttpResponseCode = curl_getinfo($oCurl, CURLINFO_HTTP_CODE); + curl_close($oCurl); + + if (!empty($sResult)) { + $aResponse = json_decode($sResult, true); + return $aResponse; + } + return []; + } +} diff --git a/Model/BamsApi/DeleteBankAccount.php b/Model/BamsApi/DeleteBankAccount.php new file mode 100644 index 0000000..d65509d --- /dev/null +++ b/Model/BamsApi/DeleteBankAccount.php @@ -0,0 +1,33 @@ + $sProfileId, + 'consumer' => $sCustomerNr, + 'bank-accounts' => $sBankAccountReference + ]; + + $this->sendCurlRequest($this->getBamsApiUrl($aUrlParameters), 'DELETE'); + + $iHttpResponseCode = $this->getHttpResponseCode(); + if ($iHttpResponseCode == 204) { + return true; + } + return false; + } +} diff --git a/Model/BamsApi/GetStoredBankAccounts.php b/Model/BamsApi/GetStoredBankAccounts.php new file mode 100644 index 0000000..7b475e9 --- /dev/null +++ b/Model/BamsApi/GetStoredBankAccounts.php @@ -0,0 +1,106 @@ + $aBankData) { + if (isset($aBankData['bank_account_reference'])) { + $aReponse[$iKey]['hash'] = $this->getBankDataHash($aBankData); + $aReponse[$iKey]['profile'] = $sProfileId; + } + } + return $aReponse; + } + + /** + * Collects all debit profile ids + * + * @return array + */ + protected function getAvailableDebitProfiles() + { + $aReturn = []; + foreach ($this->aDebitMethods as $sMethodCode) { + $aReturn[] = $this->rpDataHelper->getRpConfigData($sMethodCode, 'profileId'); + } + return $aReturn; + } + + /** + * Requests bank data for all debit profiles + * + * @param int $iCustomerNr + * @return array + */ + public function getBankDataForAllDebitProfiles($iCustomerNr) + { + $aDebitProfiles = $this->getAvailableDebitProfiles(); + $aReturn = []; + foreach ($aDebitProfiles as $sDebitProfile) { + $aBankAccounts = $this->sendRequest($iCustomerNr, $sDebitProfile); + if (!empty($aBankAccounts)) { + $aReturn = array_merge($aReturn, $aBankAccounts); + } + } + return $aReturn; + } + + /** + * Sends GetStoredBankAccounts request to BAMS api and returns saved bank accounts of the customer + * + * @param string $sCustomerNr + * @param string $sProfileId + * @return array|bool + */ + public function sendRequest($sCustomerNr, $sProfileId) + { + $aUrlParameters = [ + 'partners' => $sProfileId, + 'consumer' => $sCustomerNr, + 'bank-accounts' => null + ]; + + $aResponse = $this->sendCurlRequest($this->getBamsApiUrl($aUrlParameters), 'GET'); + if (is_array($aResponse) && !isset($aResponse['error'])) { + $aResponse = $this->addDataToResponse($aResponse, $sProfileId); + return $aResponse; + } + return false; + } +} diff --git a/Model/BamsApi/StoreBankAccount.php b/Model/BamsApi/StoreBankAccount.php new file mode 100644 index 0000000..2abe7e1 --- /dev/null +++ b/Model/BamsApi/StoreBankAccount.php @@ -0,0 +1,41 @@ + $sOwner, + "iban" => $sIban, + ]; + if ($sBic !== false) { + $aRequest['bic'] = $sBic; + } + + $aUrlParameters = [ + 'partners' => $sProfileId, + 'consumer' => $sCustomerNr, + 'bank-accounts' => null + ]; + + $aResponse = $this->sendCurlRequest($this->getBamsApiUrl($aUrlParameters), 'POST', $aRequest); + if (isset($aResponse['bank_account_reference'])) { + return $aResponse['bank_account_reference']; + } + return false; + } +} diff --git a/Model/Method/AbstractMethod.php b/Model/Method/AbstractMethod.php index c12fb32..b536e95 100644 --- a/Model/Method/AbstractMethod.php +++ b/Model/Method/AbstractMethod.php @@ -13,6 +13,7 @@ use RatePAY\Payment\Controller\LibraryController; use RatePAY\Payment\Helper\Validator; use Magento\Framework\Exception\PaymentException; +use RatePAY\Payment\Model\BamsApi\StoreBankAccount; use RatePAY\Payment\Model\Exception\DisablePaymentMethodException; use RatePAY\Payment\Model\ResourceModel\HidePaymentType; @@ -130,6 +131,13 @@ abstract class AbstractMethod extends \Magento\Payment\Model\Method\AbstractMeth */ protected $hidePaymentType; + /** + * BAMS StoreBankAccount request model + * + * @var StoreBankAccount + */ + protected $storeBankAccount; + /** * AbstractMethod constructor. * @param \Magento\Framework\Model\Context $context @@ -148,6 +156,7 @@ abstract class AbstractMethod extends \Magento\Payment\Model\Method\AbstractMeth * @param \Magento\Customer\Model\Session $customerSession * @param \RatePAY\Payment\Controller\LibraryController $libraryController * @param \RatePAY\Payment\Model\ResourceModel\HidePaymentType $hidePaymentType + * @param \RatePAY\Payment\Model\BamsApi\StoreBankAccount $storeBankAccount * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection * @param array $data @@ -169,6 +178,7 @@ function __construct( \Magento\Customer\Model\Session $customerSession, \RatePAY\Payment\Controller\LibraryController $libraryController, \RatePAY\Payment\Model\ResourceModel\HidePaymentType $hidePaymentType, + \RatePAY\Payment\Model\BamsApi\StoreBankAccount $storeBankAccount, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = []) @@ -194,6 +204,7 @@ function __construct( $this->customerSession = $customerSession; $this->libraryController = $libraryController; $this->hidePaymentType = $hidePaymentType; + $this->storeBankAccount = $storeBankAccount; } /** @@ -435,9 +446,25 @@ public function assignData(\Magento\Framework\DataObject $data) $methodCode = $infoInstance->getMethod(); $debitMethods = ['ratepay_de_directdebit', 'ratepay_at_directdebit', 'ratepay_nl_directdebit', 'ratepay_be_directdebit']; - if (in_array($methodCode, $debitMethods) || !empty($additionalData->getRpIban())) { // getRpIban used for installments + $sIban = $additionalData->getRpIban(); + if (in_array($methodCode, $debitMethods) || !empty($sIban)) { // getRpIban used for installments $this->rpValidator->validateIban($additionalData); - $infoInstance->setAdditionalInformation('rp_iban', $additionalData->getRpIban()); + $sIbanReference = false; + if ((bool)$this->rpDataHelper->getRpConfigDataByPath('ratepay/general/bams_enabled') === true) { + if ($additionalData->getRpRememberiban()) { + $sOwner = $order->getBillingAddress()->getFirstname() . ' ' . $order->getBillingAddress()->getLastname(); + $sIbanReference = $this->storeBankAccount->sendRequest($order->getCustomerId(), $this->getProfileId(), $sOwner, $sIban); + } + + if ($additionalData->getRpIbanReference()) { + $sIbanReference = $additionalData->getRpIbanReference(); + } + } + if ($sIbanReference !== false) { + $infoInstance->setAdditionalInformation('rp_iban_reference', $sIbanReference); + } else { + $infoInstance->setAdditionalInformation('rp_iban', $sIban); + } } if ($additionalData->getRpDirectdebit() !== null) { @@ -469,6 +496,17 @@ public function assignData(\Magento\Framework\DataObject $data) return $this; } + /** + * Returns profile id for current payment method + * + * @param string|null $storeCode + * @return string + */ + protected function getProfileId($storeCode = null) + { + return $this->rpDataHelper->getRpConfigData($this->getCode(), 'profileId', $storeCode); + } + /** * @param $message * @param $order diff --git a/Model/RechnungConfigProvider.php b/Model/RechnungConfigProvider.php index fcf3513..fcbded8 100644 --- a/Model/RechnungConfigProvider.php +++ b/Model/RechnungConfigProvider.php @@ -2,6 +2,7 @@ namespace RatePAY\Payment\Model; +use RatePAY\Payment\Model\Method\DE\Directdebit; use RatePAY\Payment\Model\Method\DE\Invoice; use RatePAY\Payment\Model\Method\DE\Installment; use RatePAY\Payment\Model\Method\AbstractMethod; @@ -30,6 +31,23 @@ class RechnungConfigProvider implements \Magento\Checkout\Model\ConfigProviderIn */ protected $checkoutSession; + /** + * Customer session + * + * @var \Magento\Customer\Model\Session + */ + protected $customerSession; + + /** + * @var \RatePAY\Payment\Model\BamsApi\GetStoredBankAccounts + */ + protected $getStoredBankAccounts; + + /** + * @var \Magento\Framework\UrlInterface + */ + protected $urlBuilder; + /** * Array with all ratepay payment methods * @@ -63,22 +81,43 @@ class RechnungConfigProvider implements \Magento\Checkout\Model\ConfigProviderIn \RatePAY\Payment\Model\Method\AT\Installment0::METHOD_CODE ]; + /** + * Array with all ratepay debit payment methods + * + * @var array + */ + protected $debitPaymentTypes = [ + \RatePAY\Payment\Model\Method\DE\Directdebit::METHOD_CODE, + \RatePAY\Payment\Model\Method\AT\Directdebit::METHOD_CODE, + \RatePAY\Payment\Model\Method\NL\Directdebit::METHOD_CODE, + \RatePAY\Payment\Model\Method\BE\Directdebit::METHOD_CODE, + ]; + /** * @param \Magento\Payment\Helper\Data $paymentHelper * @param \Magento\Framework\Escaper $escaper * @param \RatePAY\Payment\Helper\Data $rpDataHelper * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Customer\Model\Session $customerSession + * @param \RatePAY\Payment\Model\BamsApi\GetStoredBankAccounts $getStoredBankAccounts + * @param \Magento\Framework\UrlInterface $urlBuilder */ public function __construct( \Magento\Payment\Helper\Data $paymentHelper, \Magento\Framework\Escaper $escaper, \RatePAY\Payment\Helper\Data $rpDataHelper, - \Magento\Checkout\Model\Session $checkoutSession + \Magento\Checkout\Model\Session $checkoutSession, + \Magento\Customer\Model\Session $customerSession, + \RatePAY\Payment\Model\BamsApi\GetStoredBankAccounts $getStoredBankAccounts, + \Magento\Framework\UrlInterface $urlBuilder ) { $this->escaper = $escaper; $this->paymentHelper = $paymentHelper; $this->rpDataHelper = $rpDataHelper; $this->checkoutSession = $checkoutSession; + $this->customerSession = $customerSession; + $this->getStoredBankAccounts = $getStoredBankAccounts; + $this->urlBuilder = $urlBuilder; } /** @@ -89,9 +128,28 @@ public function getConfig() $config = array_merge_recursive([], $this->getInvoiceConfig()); $config = array_merge_recursive($config, $this->getInstallmentConfig()); $config = array_merge_recursive($config, $this->getB2BConfig()); + $config = array_merge_recursive($config, $this->getRatepayGeneralConfig()); + + if ($this->isRememberIbanAllowed()) { + $config = array_merge_recursive($config, $this->getDebitConfig($this->customerSession->getCustomerId())); + } return $config; } + /** + * Checks whether remember Iban feature is allowed or not + * + * @return bool + */ + protected function isRememberIbanAllowed() + { + $iCustomerId = $this->customerSession->getCustomerId(); + if ((bool)$this->rpDataHelper->getRpConfigDataByPath('ratepay/general/bams_enabled') === true && !empty($iCustomerId)) { + return true; + } + return false; + } + /** * Add b2b config for given payment method * @@ -104,7 +162,8 @@ protected function getSingleB2BConfig($sMethodCode) 'payment' => [ $sMethodCode => [ 'b2bActive' => (bool)$this->rpDataHelper->getRpConfigData($sMethodCode, 'b2b'), - 'differentShippingAddressAllowed' => $this->getIsDifferentShippingAddressAllowed($sMethodCode) + 'differentShippingAddressAllowed' => $this->getIsDifferentShippingAddressAllowed($sMethodCode), + 'rememberIbanEnabled' => $this->isRememberIbanAllowed(), ], ], ] : []; @@ -124,6 +183,17 @@ protected function getB2BConfig() return $config; } + protected function getRatepayGeneralConfig() + { + return [ + 'payment' => [ + 'ratepay' => [ + 'manageBankdataUrl' => $this->urlBuilder->getUrl("ratepay/customer/bankdata"), + ], + ], + ]; + } + /** * @return array */ @@ -155,6 +225,43 @@ protected function getSingleInstallmentConfig($sMethodCode) ] : []; } + /** + * @param string $sMethodCode + * @param int $iCustomerId + * @return array + */ + protected function getSingleDebitConfig($sMethodCode, $iCustomerId) + { + return ($this->isPaymentMethodActive($sMethodCode)) ? [ + 'payment' => [ + $sMethodCode => [ + 'savedBankData' => $this->getSavedBankData($sMethodCode, $iCustomerId), + ], + ], + ] : []; + } + + /** + * @param string $sMethodCode + * @param int $iCustomerId + * @return array|bool + */ + protected function getSavedBankData($sMethodCode, $iCustomerId) + { + $sProfileId = $this->rpDataHelper->getRpConfigData($sMethodCode, 'profileId'); + $aBankData = $this->getStoredBankAccounts->sendRequest($iCustomerId, $sProfileId); + if (!empty($aBankData)) { + $aBankData = reset($aBankData); // Returns first element + if (isset($aBankData['owner'])) { + unset($aBankData['owner']); + unset($aBankData['hash']); + unset($aBankData['profile']); + return $aBankData; + } + } + return false; + } + /** * @param string $sMethodCode * @return bool @@ -176,6 +283,19 @@ protected function getInstallmentConfig() return $config; } + /** + * @param int $iCustomerId + * @return array + */ + protected function getDebitConfig($iCustomerId) + { + $config = []; + foreach ($this->debitPaymentTypes as $debitPaymentType) { + $config = array_merge_recursive($config, $this->getSingleDebitConfig($debitPaymentType, $iCustomerId)); + } + return $config; + } + /** * @param string $sMethodCode * @return array diff --git a/composer.json b/composer.json index 6e161dd..27aad70 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "require": { "php": ">=5.6.0", "magento/framework": ">=100.1.0", - "ratepay/php-library": "*" + "ratepay/php-library": ">=1.2.0" }, "autoload": { diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 4fa3484..01324bb 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -23,7 +23,35 @@ ratepay/general/true_offline_mode With True Offline Mode being enabled, communication with Ratepay when creating an invoice or a creditmemo is disabled. This will make the module behave in the Magento2 standard way. With True Offline Mode being disabled (default) the module will continue to communicate to Ratepay like before, this happens because the module didnt have a differentiation between those modes in the beginning and the customers were not supposed to have to change their workflow later when it was introduced. - + + Magento\Config\Model\Config\Source\Yesno + ratepay/general/bams_enabled + BAMS is the Bank Account Management Service of Ratepay. This enables the customer to save have IBAN data so that he doesnt have to enter it every time. The data is not saved on your server. It is saved on a secure server by Ratepay and addressed via a reference id. + + + + ratepay/general/bams_client_id + + 1 + + + + + ratepay/general/bams_client_secret + + 1 + + + + + Magento\Config\Model\Config\Source\Yesno + ratepay/general/bams_sandbox + + 1 + + + - - - - + + + + + ratepay/customer/bankdata + Bank data management + + + + + diff --git a/view/frontend/layout/ratepay_customer_bankdata.xml b/view/frontend/layout/ratepay_customer_bankdata.xml new file mode 100644 index 0000000..b565c2d --- /dev/null +++ b/view/frontend/layout/ratepay_customer_bankdata.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/view/frontend/templates/customer/bankdata.phtml b/view/frontend/templates/customer/bankdata.phtml new file mode 100644 index 0000000..2882767 --- /dev/null +++ b/view/frontend/templates/customer/bankdata.phtml @@ -0,0 +1,27 @@ +getSavedBankData(); ?> + +
+ + + + + + + + + + + + + + + + + +
 
+ +
+
+ +
+ \ No newline at end of file diff --git a/view/frontend/web/js/view/payment/method-renderer/directdebit.js b/view/frontend/web/js/view/payment/method-renderer/directdebit.js index ac87de9..76e4d82 100644 --- a/view/frontend/web/js/view/payment/method-renderer/directdebit.js +++ b/view/frontend/web/js/view/payment/method-renderer/directdebit.js @@ -21,8 +21,10 @@ define( rp_dob_year: '', rp_vatid: '', rp_iban: '', + rp_reference: '', sepaAccepted: false, - b2b_accountholder: '' + b2b_accountholder: '', + rememberIban: false }, validate: function () { var blParentReturn = this._super(); @@ -51,12 +53,68 @@ define( if (this.isB2BModeUsable() === true) { parentReturn.additional_data.rp_accountholder = this.b2b_accountholder; } + parentReturn.additional_data.rp_rememberiban = false; + if (this.isSavedIbanSelected()) { + parentReturn.additional_data.rp_iban_reference = this.getSavedIbanReference(); + } else if (this.rememberIban === true) { + parentReturn.additional_data.rp_rememberiban = true; + } return parentReturn; }, showAgreement: function() { $('#ratepay_directdebit_sepa_agreement').show(); $('#ratepay_directdebit_sepa_agreement_link').hide(); - } + }, + isRememberIBANEnabled: function() { + return window.checkoutConfig.payment[this.getCode()].rememberIbanEnabled; + }, + getSavedMaskedIban: function() { + if (window.checkoutConfig.payment[this.getCode()].savedBankData !== undefined && window.checkoutConfig.payment[this.getCode()].savedBankData !== false) { + return window.checkoutConfig.payment[this.getCode()].savedBankData.iban; + } + return false; + }, + getSavedIbanReference: function() { + if (window.checkoutConfig.payment[this.getCode()].savedBankData !== undefined && window.checkoutConfig.payment[this.getCode()].savedBankData !== false) { + return window.checkoutConfig.payment[this.getCode()].savedBankData.bank_account_reference; + } + return false; + }, + isSavedIbanSelected: function() { + if (this.rp_iban == this.getSavedMaskedIban() && this.getSavedMaskedIban() != "") { + return true; + } + return false; + }, + getDefaultIban: function() { + var savedIban = this.getSavedMaskedIban(); + if (savedIban !== false) { + return savedIban; + } + return ''; + }, + onChangeIban: function(data, event) { + if (event.target.value == this.getSavedMaskedIban()) { + $('#' + this.getCode() + '_rememberIban').hide(); + } else { + $('#' + this.getCode() + '_rememberIban').show(); + } + return true; + }, + displaySaveBankdataOverlay: function() { + $('#' + this.getCode() + '_overlay').show(); + }, + removeSaveBankdataOverlay: function() { + $('#' + this.getCode() + '_overlay').hide(); + }, + getManageBankdataUrl: function() { + return window.checkoutConfig.payment.ratepay.manageBankdataUrl; + }, + initialize: function () { + this._super(); + this.rp_iban = this.getDefaultIban(); + return this; + }, }); } ); diff --git a/view/frontend/web/template/payment/directdebit.html b/view/frontend/web/template/payment/directdebit.html index bc0f9b8..ac5fffc 100644 --- a/view/frontend/web/template/payment/directdebit.html +++ b/view/frontend/web/template/payment/directdebit.html @@ -144,34 +144,61 @@ id: getCode() + '_iban', autocomplete: off, title: $t('IBAN')}, + event: {keyup:onChangeIban}, value: rp_iban" /> - - - - - - + + + + + + + + + + + + +
- - - - - - - - - -
-
- -
- -
- -
+ + + + + + + + + +
+ + +
+ +
+ +
+
+ +
+
+ +
+ +
+ +

From b0bf52622923ba69e50cc798274cca1bbc1170a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 19 Nov 2020 12:15:24 +0100 Subject: [PATCH 2/7] M2-52 - Fixed problem with OAuth connection --- Model/BamsApi/Base.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Model/BamsApi/Base.php b/Model/BamsApi/Base.php index 49663a4..1af0edc 100644 --- a/Model/BamsApi/Base.php +++ b/Model/BamsApi/Base.php @@ -112,8 +112,8 @@ protected function getAuthToken() { if ($this->aAuthToken === null) { $aRequest = [ - 'client_id' => 'snbFcxD4Rxt2O4YqeGqDls9yrGWYhmQ0', - 'client_secret' => 'IHa7jiW0hMlH0VsoxDTZ03XH76NED7RwFvJLsmmUXg9fkowhiVQqp7EA84WoYT1Q', + 'client_id' => $this->rpDataHelper->getRpConfigDataByPath("ratepay/general/bams_client_id"), + 'client_secret' => $this->rpDataHelper->getRpConfigDataByPath("ratepay/general/bams_client_secret"), 'audience' => $this->getBamsApiUrl(), 'grant_type' => 'client_credentials' ]; From cb5dd681ad264b0842dd5b970e1de29e4137cfd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 19 Nov 2020 17:16:05 +0100 Subject: [PATCH 3/7] M2-52 - Added remember Iban feature to installment payment types Added feature to display validity of oauth credentials to backend --- Block/Customer/Bankdata.php | 2 +- Block/System/Config/BamsOauthCheck.php | 80 +++++++++++++++++++ Controller/Customer/Delete.php | 2 +- Model/BamsApi/Base.php | 2 +- Model/BamsApi/GetStoredBankAccounts.php | 26 +++++- Model/RechnungConfigProvider.php | 20 +++-- Observer/SystemConfigChangedPayment.php | 55 +++++++++++++ etc/adminhtml/events.xml | 3 + etc/adminhtml/system.xml | 3 + i18n/de_DE.csv | 2 + .../system/config/bamsoauthcheck.phtml | 5 ++ .../js/view/payment/method-renderer/base.js | 45 +++++++++++ .../payment/method-renderer/directdebit.js | 49 +----------- .../payment/method-renderer/installment.js | 14 +++- .../web/template/payment/installment.html | 27 ++++++- 15 files changed, 275 insertions(+), 60 deletions(-) create mode 100644 Block/System/Config/BamsOauthCheck.php create mode 100644 Observer/SystemConfigChangedPayment.php create mode 100644 view/adminhtml/templates/system/config/bamsoauthcheck.phtml diff --git a/Block/Customer/Bankdata.php b/Block/Customer/Bankdata.php index 6887f5c..8a0847b 100644 --- a/Block/Customer/Bankdata.php +++ b/Block/Customer/Bankdata.php @@ -57,7 +57,7 @@ public function getActionUrl($sHash, $sAction) public function getSavedBankData() { $iCustomerId = $this->customerSession->getCustomerId(); - $aBankAccounts = $this->getStoredBankAccounts->getBankDataForAllDebitProfiles($iCustomerId); + $aBankAccounts = $this->getStoredBankAccounts->getBankDataForAllIbanProfiles($iCustomerId); if (empty($aBankAccounts)) { return false; } diff --git a/Block/System/Config/BamsOauthCheck.php b/Block/System/Config/BamsOauthCheck.php new file mode 100644 index 0000000..675051d --- /dev/null +++ b/Block/System/Config/BamsOauthCheck.php @@ -0,0 +1,80 @@ +backendSession = $backendSession; + } + + /** + * Unset some non-related element parameters + * + * @param \Magento\Framework\Data\Form\Element\AbstractElement $element + * @return string + */ + public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) + { + $this->blStatus = $this->backendSession->getRatepayBamsOauthChanged(); + if ($this->blStatus === null) { + return ''; + } + + $this->backendSession->unsRatepayBamsOauthChanged(); + + $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); + return parent::render($element); + } + + /** + * Initialise form fields + * + * @return void + */ + protected function _construct() + { + $this->addColumn('txaction', ['label' => __('Transactionstatus-message')]); + $this->_addAfter = false; + $this->_addButtonLabel = __('Add Minimum Qty'); + parent::_construct(); + } + + /** + * @return bool + */ + public function getStatus() + { + return $this->blStatus; + } +} diff --git a/Controller/Customer/Delete.php b/Controller/Customer/Delete.php index 4b7ec83..deb00bd 100644 --- a/Controller/Customer/Delete.php +++ b/Controller/Customer/Delete.php @@ -55,7 +55,7 @@ public function execute() $sDeleteHash = $this->getRequest()->getParam('hash'); $iCustomerId = $this->customerSession->getCustomerId(); - $aBankAccounts = $this->getStoredBankAccounts->getBankDataForAllDebitProfiles($iCustomerId); + $aBankAccounts = $this->getStoredBankAccounts->getBankDataForAllIbanProfiles($iCustomerId); foreach ($aBankAccounts as $aBankData) { if ($aBankData['hash'] == $sDeleteHash) { $this->deleteBankAccount->sendRequest($iCustomerId, $aBankData['profile'], $aBankData['bank_account_reference']); diff --git a/Model/BamsApi/Base.php b/Model/BamsApi/Base.php index 1af0edc..3a98e5d 100644 --- a/Model/BamsApi/Base.php +++ b/Model/BamsApi/Base.php @@ -108,7 +108,7 @@ public function getHttpResponseCode() * * @return array|false */ - protected function getAuthToken() + public function getAuthToken() { if ($this->aAuthToken === null) { $aRequest = [ diff --git a/Model/BamsApi/GetStoredBankAccounts.php b/Model/BamsApi/GetStoredBankAccounts.php index 7b475e9..73ff339 100644 --- a/Model/BamsApi/GetStoredBankAccounts.php +++ b/Model/BamsApi/GetStoredBankAccounts.php @@ -13,7 +13,11 @@ class GetStoredBankAccounts extends Base */ protected $aDebitMethods = [ 'ratepay_de_directdebit', + 'ratepay_de_installment', + 'ratepay_de_installment0', 'ratepay_at_directdebit', + 'ratepay_at_installment', + 'ratepay_at_installment0', 'ratepay_nl_directdebit', 'ratepay_be_directdebit', ]; @@ -62,13 +66,32 @@ protected function getAvailableDebitProfiles() return $aReturn; } + /** + * Removes duplicate entries + * + * @param array $aBankdata + * @return array + */ + protected function removeDuplicateData($aBankdata) + { + $aHashList = []; + $aReturn = []; + foreach ($aBankdata as $aData) { + if (!in_array($aData['hash'], $aHashList)) { + $aReturn[] = $aData; + $aHashList[] = $aData['hash']; + } + } + return $aReturn; + } + /** * Requests bank data for all debit profiles * * @param int $iCustomerNr * @return array */ - public function getBankDataForAllDebitProfiles($iCustomerNr) + public function getBankDataForAllIbanProfiles($iCustomerNr) { $aDebitProfiles = $this->getAvailableDebitProfiles(); $aReturn = []; @@ -78,6 +101,7 @@ public function getBankDataForAllDebitProfiles($iCustomerNr) $aReturn = array_merge($aReturn, $aBankAccounts); } } + $aReturn = $this->removeDuplicateData($aReturn); return $aReturn; } diff --git a/Model/RechnungConfigProvider.php b/Model/RechnungConfigProvider.php index fcbded8..a336ace 100644 --- a/Model/RechnungConfigProvider.php +++ b/Model/RechnungConfigProvider.php @@ -82,13 +82,17 @@ class RechnungConfigProvider implements \Magento\Checkout\Model\ConfigProviderIn ]; /** - * Array with all ratepay debit payment methods + * Array with all ratepay iban payment methods * * @var array */ - protected $debitPaymentTypes = [ + protected $rememberIbanPaymentTypes = [ \RatePAY\Payment\Model\Method\DE\Directdebit::METHOD_CODE, + \RatePAY\Payment\Model\Method\DE\Installment::METHOD_CODE, + \RatePAY\Payment\Model\Method\DE\Installment0::METHOD_CODE, \RatePAY\Payment\Model\Method\AT\Directdebit::METHOD_CODE, + \RatePAY\Payment\Model\Method\AT\Installment::METHOD_CODE, + \RatePAY\Payment\Model\Method\AT\Installment0::METHOD_CODE, \RatePAY\Payment\Model\Method\NL\Directdebit::METHOD_CODE, \RatePAY\Payment\Model\Method\BE\Directdebit::METHOD_CODE, ]; @@ -131,7 +135,7 @@ public function getConfig() $config = array_merge_recursive($config, $this->getRatepayGeneralConfig()); if ($this->isRememberIbanAllowed()) { - $config = array_merge_recursive($config, $this->getDebitConfig($this->customerSession->getCustomerId())); + $config = array_merge_recursive($config, $this->getRememberIbanConfig($this->customerSession->getCustomerId())); } return $config; } @@ -163,7 +167,6 @@ protected function getSingleB2BConfig($sMethodCode) $sMethodCode => [ 'b2bActive' => (bool)$this->rpDataHelper->getRpConfigData($sMethodCode, 'b2b'), 'differentShippingAddressAllowed' => $this->getIsDifferentShippingAddressAllowed($sMethodCode), - 'rememberIbanEnabled' => $this->isRememberIbanAllowed(), ], ], ] : []; @@ -189,6 +192,7 @@ protected function getRatepayGeneralConfig() 'payment' => [ 'ratepay' => [ 'manageBankdataUrl' => $this->urlBuilder->getUrl("ratepay/customer/bankdata"), + 'rememberIbanEnabled' => $this->isRememberIbanAllowed(), ], ], ]; @@ -230,7 +234,7 @@ protected function getSingleInstallmentConfig($sMethodCode) * @param int $iCustomerId * @return array */ - protected function getSingleDebitConfig($sMethodCode, $iCustomerId) + protected function getSingleRememberIbanConfig($sMethodCode, $iCustomerId) { return ($this->isPaymentMethodActive($sMethodCode)) ? [ 'payment' => [ @@ -287,11 +291,11 @@ protected function getInstallmentConfig() * @param int $iCustomerId * @return array */ - protected function getDebitConfig($iCustomerId) + protected function getRememberIbanConfig($iCustomerId) { $config = []; - foreach ($this->debitPaymentTypes as $debitPaymentType) { - $config = array_merge_recursive($config, $this->getSingleDebitConfig($debitPaymentType, $iCustomerId)); + foreach ($this->rememberIbanPaymentTypes as $debitPaymentType) { + $config = array_merge_recursive($config, $this->getSingleRememberIbanConfig($debitPaymentType, $iCustomerId)); } return $config; } diff --git a/Observer/SystemConfigChangedPayment.php b/Observer/SystemConfigChangedPayment.php new file mode 100644 index 0000000..5dc325a --- /dev/null +++ b/Observer/SystemConfigChangedPayment.php @@ -0,0 +1,55 @@ +backendSession = $backendSession; + $this->getStoredBankAccounts = $getStoredBankAccounts; + } + + /** + * Execute certain tasks after the payone_payment section is being saved in the backend + * + * @param Observer $observer + * @return void + */ + public function execute(Observer $observer) + { + $aChangedPaths = $observer->getChangedPaths(); + foreach ($aChangedPaths as $sChangedPath) { + if (stripos($sChangedPath, "bams_client_id") !== false || stripos($sChangedPath, "bams_client_secret") !== false) { + $sAuthToken = $this->getStoredBankAccounts->getAuthToken(); + $this->backendSession->setRatepayBamsOauthChanged(false); + if ($sAuthToken !== false) { + $this->backendSession->setRatepayBamsOauthChanged(true); + } + } + } + } +} diff --git a/etc/adminhtml/events.xml b/etc/adminhtml/events.xml index 647bd25..7d92985 100644 --- a/etc/adminhtml/events.xml +++ b/etc/adminhtml/events.xml @@ -9,4 +9,7 @@ + + + diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 01324bb..3ddb8b7 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -43,6 +43,9 @@ 1 + + RatePAY\Payment\Block\System\Config\BamsOauthCheck + Magento\Config\Model\Config\Source\Yesno diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv index 5437c34..f0288c0 100644 --- a/i18n/de_DE.csv +++ b/i18n/de_DE.csv @@ -148,3 +148,5 @@ ratepay_terms_block_6, "einverstanden." ,module,RatePAY_Payment "ratepay_directdebit_save_bankdata_overlay_3","vornehmen.",module,RatePAY_Payment "Save payment data","Zahlungsdaten merken",module,RatePAY_Payment "Close window","Fenster schließen",module,RatePAY_Payment +"Connection was established successfully.","Verbindung konnte erfolgreich aufgebaut werden.",module,RatePAY_Payment +"Connection could not be established.","Verbindung konnte nicht aufgebaut werden.",module,RatePAY_Payment diff --git a/view/adminhtml/templates/system/config/bamsoauthcheck.phtml b/view/adminhtml/templates/system/config/bamsoauthcheck.phtml new file mode 100644 index 0000000..2fa0c36 --- /dev/null +++ b/view/adminhtml/templates/system/config/bamsoauthcheck.phtml @@ -0,0 +1,5 @@ +getStatus() === true): ?> +
+getStatus() === false): ?> +
+ diff --git a/view/frontend/web/js/view/payment/method-renderer/base.js b/view/frontend/web/js/view/payment/method-renderer/base.js index 2459fad..71bf0f3 100644 --- a/view/frontend/web/js/view/payment/method-renderer/base.js +++ b/view/frontend/web/js/view/payment/method-renderer/base.js @@ -57,6 +57,51 @@ define( } return false; }, + getSavedMaskedIban: function() { + if (window.checkoutConfig.payment[this.getCode()].savedBankData !== undefined && window.checkoutConfig.payment[this.getCode()].savedBankData !== false) { + return window.checkoutConfig.payment[this.getCode()].savedBankData.iban; + } + return false; + }, + getSavedIbanReference: function() { + if (window.checkoutConfig.payment[this.getCode()].savedBankData !== undefined && window.checkoutConfig.payment[this.getCode()].savedBankData !== false) { + return window.checkoutConfig.payment[this.getCode()].savedBankData.bank_account_reference; + } + return false; + }, + isSavedIbanSelected: function() { + if (this.rp_iban == this.getSavedMaskedIban() && this.getSavedMaskedIban() != "") { + return true; + } + return false; + }, + getDefaultIban: function() { + var savedIban = this.getSavedMaskedIban(); + if (savedIban !== false) { + return savedIban; + } + return ''; + }, + onChangeIban: function(data, event) { + if (event.target.value == this.getSavedMaskedIban()) { + $('#' + this.getCode() + '_rememberIban').hide(); + } else { + $('#' + this.getCode() + '_rememberIban').show(); + } + return true; + }, + displaySaveBankdataOverlay: function() { + $('#' + this.getCode() + '_overlay').show(); + }, + removeSaveBankdataOverlay: function() { + $('#' + this.getCode() + '_overlay').hide(); + }, + isRememberIBANEnabled: function() { + return window.checkoutConfig.payment.ratepay.rememberIbanEnabled; + }, + getManageBankdataUrl: function() { + return window.checkoutConfig.payment.ratepay.manageBankdataUrl; + }, getData: function() { var returnData = { 'method': this.getCode(), diff --git a/view/frontend/web/js/view/payment/method-renderer/directdebit.js b/view/frontend/web/js/view/payment/method-renderer/directdebit.js index 76e4d82..f4633d0 100644 --- a/view/frontend/web/js/view/payment/method-renderer/directdebit.js +++ b/view/frontend/web/js/view/payment/method-renderer/directdebit.js @@ -65,54 +65,11 @@ define( $('#ratepay_directdebit_sepa_agreement').show(); $('#ratepay_directdebit_sepa_agreement_link').hide(); }, - isRememberIBANEnabled: function() { - return window.checkoutConfig.payment[this.getCode()].rememberIbanEnabled; - }, - getSavedMaskedIban: function() { - if (window.checkoutConfig.payment[this.getCode()].savedBankData !== undefined && window.checkoutConfig.payment[this.getCode()].savedBankData !== false) { - return window.checkoutConfig.payment[this.getCode()].savedBankData.iban; - } - return false; - }, - getSavedIbanReference: function() { - if (window.checkoutConfig.payment[this.getCode()].savedBankData !== undefined && window.checkoutConfig.payment[this.getCode()].savedBankData !== false) { - return window.checkoutConfig.payment[this.getCode()].savedBankData.bank_account_reference; - } - return false; - }, - isSavedIbanSelected: function() { - if (this.rp_iban == this.getSavedMaskedIban() && this.getSavedMaskedIban() != "") { - return true; - } - return false; - }, - getDefaultIban: function() { - var savedIban = this.getSavedMaskedIban(); - if (savedIban !== false) { - return savedIban; - } - return ''; - }, - onChangeIban: function(data, event) { - if (event.target.value == this.getSavedMaskedIban()) { - $('#' + this.getCode() + '_rememberIban').hide(); - } else { - $('#' + this.getCode() + '_rememberIban').show(); - } - return true; - }, - displaySaveBankdataOverlay: function() { - $('#' + this.getCode() + '_overlay').show(); - }, - removeSaveBankdataOverlay: function() { - $('#' + this.getCode() + '_overlay').hide(); - }, - getManageBankdataUrl: function() { - return window.checkoutConfig.payment.ratepay.manageBankdataUrl; - }, initialize: function () { this._super(); - this.rp_iban = this.getDefaultIban(); + if (this.isRememberIBANEnabled()) { + this.rp_iban = this.getDefaultIban(); + } return this; }, }); diff --git a/view/frontend/web/js/view/payment/method-renderer/installment.js b/view/frontend/web/js/view/payment/method-renderer/installment.js index 1018dd7..d6f2f62 100644 --- a/view/frontend/web/js/view/payment/method-renderer/installment.js +++ b/view/frontend/web/js/view/payment/method-renderer/installment.js @@ -25,7 +25,9 @@ define( isInstallmentPlanSet: false, useDirectDebit: true, sepaAccepted: false, - b2b_accountholder: '' + b2b_accountholder: '', + rp_reference: '', + rememberIban: false }, initialize: function () { @@ -35,6 +37,9 @@ define( } else if(this.hasSingleAllowedMonth()) { this.updateInstallmentPlan('time', this.getAllowedMonths()[0], this.getCode(), false); } + if (this.isRememberIBANEnabled()) { + this.rp_iban = this.getDefaultIban(); + } return this; }, validate: function () { @@ -127,6 +132,13 @@ define( if (this.isB2BModeUsable() === true) { parentReturn.additional_data.rp_accountholder = this.b2b_accountholder; } + + parentReturn.additional_data.rp_rememberiban = false; + if (this.isSavedIbanSelected()) { + parentReturn.additional_data.rp_iban_reference = this.getSavedIbanReference(); + } else if (this.rememberIban === true) { + parentReturn.additional_data.rp_rememberiban = true; + } return parentReturn; } }); diff --git a/view/frontend/web/template/payment/installment.html b/view/frontend/web/template/payment/installment.html index 98e20e5..d619ed3 100644 --- a/view/frontend/web/template/payment/installment.html +++ b/view/frontend/web/template/payment/installment.html @@ -206,7 +206,7 @@

:
- +
@@ -224,6 +224,31 @@

+ + + + + + From 174013d78f1eb445e0b3130925c98e77d1429819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 2 May 2022 12:08:37 +0200 Subject: [PATCH 6/7] M2-52 - Fixed BAMS integration for current master version --- Model/RechnungConfigProvider.php | 2 +- Observer/SystemConfigChangedPayment.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Model/RechnungConfigProvider.php b/Model/RechnungConfigProvider.php index 15e6485..42b3fd7 100644 --- a/Model/RechnungConfigProvider.php +++ b/Model/RechnungConfigProvider.php @@ -262,7 +262,7 @@ protected function getSingleRememberIbanConfig($sMethodCode, $iCustomerId) */ protected function getSavedBankData($sMethodCode, $iCustomerId) { - $sProfileId = $this->rpDataHelper->getRpConfigData($sMethodCode, 'profileId'); + $sProfileId = $this->getMethod($sMethodCode)->getMatchingProfile()->getData("profile_id"); $aBankData = $this->getStoredBankAccounts->sendRequest($iCustomerId, $sProfileId); if (!empty($aBankData)) { $aBankData = reset($aBankData); // Returns first element diff --git a/Observer/SystemConfigChangedPayment.php b/Observer/SystemConfigChangedPayment.php index c233a6f..2ff3bd6 100644 --- a/Observer/SystemConfigChangedPayment.php +++ b/Observer/SystemConfigChangedPayment.php @@ -23,7 +23,7 @@ class SystemConfigChangedPayment implements ObserverInterface /** * @var \RatePAY\Payment\Helper\ProfileConfig */ - protected $profileConfigHelper + protected $profileConfigHelper; /** * Constructor From 3f7f1bb2527f399f47098593a5827f54b4c64c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 13 Oct 2022 17:22:02 +0200 Subject: [PATCH 7/7] M2-92 - Added copyright headers to BAMS files --- Block/Customer/Bankdata.php | 7 +++++++ Block/Customer/DataLink.php | 7 +++++++ Block/System/Config/BamsOauthCheck.php | 6 ++++++ Controller/Customer/Bankdata.php | 7 +++++++ Controller/Customer/Delete.php | 7 +++++++ Model/BamsApi/Base.php | 6 ++++++ Model/BamsApi/DeleteBankAccount.php | 6 ++++++ Model/BamsApi/GetStoredBankAccounts.php | 6 ++++++ Model/BamsApi/StoreBankAccount.php | 7 ++++++- .../templates/system/config/bamsoauthcheck.phtml | 8 ++++++++ view/frontend/layout/customer_account.xml | 9 +++++++++ view/frontend/layout/ratepay_customer_bankdata.xml | 9 +++++++++ view/frontend/templates/customer/bankdata.phtml | 8 ++++++++ 13 files changed, 92 insertions(+), 1 deletion(-) diff --git a/Block/Customer/Bankdata.php b/Block/Customer/Bankdata.php index 8a0847b..0c18b63 100644 --- a/Block/Customer/Bankdata.php +++ b/Block/Customer/Bankdata.php @@ -1,5 +1,12 @@ getStatus() === true): ?>
getStatus() === false): ?> diff --git a/view/frontend/layout/customer_account.xml b/view/frontend/layout/customer_account.xml index 7b15cf0..7ce1982 100644 --- a/view/frontend/layout/customer_account.xml +++ b/view/frontend/layout/customer_account.xml @@ -1,3 +1,12 @@ + + diff --git a/view/frontend/layout/ratepay_customer_bankdata.xml b/view/frontend/layout/ratepay_customer_bankdata.xml index b565c2d..0cf7c3c 100644 --- a/view/frontend/layout/ratepay_customer_bankdata.xml +++ b/view/frontend/layout/ratepay_customer_bankdata.xml @@ -1,3 +1,12 @@ + + diff --git a/view/frontend/templates/customer/bankdata.phtml b/view/frontend/templates/customer/bankdata.phtml index 2ae7d04..a61a80a 100644 --- a/view/frontend/templates/customer/bankdata.phtml +++ b/view/frontend/templates/customer/bankdata.phtml @@ -1,3 +1,11 @@ + getSavedBankData(); ?>
+ + +
+ +
+ +
+
+ +

From e83abdbf05f3b5dbe22b61537fbd7a0a69b8e22d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Thu, 19 Nov 2020 18:38:18 +0100 Subject: [PATCH 4/7] M2-52 - Fixed problem with bank transfer installment payment --- .../payment/method-renderer/installment.js | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/view/frontend/web/js/view/payment/method-renderer/installment.js b/view/frontend/web/js/view/payment/method-renderer/installment.js index d6f2f62..6b85832 100644 --- a/view/frontend/web/js/view/payment/method-renderer/installment.js +++ b/view/frontend/web/js/view/payment/method-renderer/installment.js @@ -126,18 +126,19 @@ define( if (parentReturn.additional_data === null) { parentReturn.additional_data = {}; } - parentReturn.additional_data.rp_iban = this.rp_iban; parentReturn.additional_data.rp_directdebit = this.useDirectDebit; - parentReturn.additional_data.rp_accountholder = this.getCustomerName(); - if (this.isB2BModeUsable() === true) { - parentReturn.additional_data.rp_accountholder = this.b2b_accountholder; - } - parentReturn.additional_data.rp_rememberiban = false; - if (this.isSavedIbanSelected()) { - parentReturn.additional_data.rp_iban_reference = this.getSavedIbanReference(); - } else if (this.rememberIban === true) { - parentReturn.additional_data.rp_rememberiban = true; + if (this.useDirectDebit === true) { + parentReturn.additional_data.rp_iban = this.rp_iban; + parentReturn.additional_data.rp_accountholder = this.getCustomerName(); + if (this.isB2BModeUsable() === true) { + parentReturn.additional_data.rp_accountholder = this.b2b_accountholder; + } + if (this.isSavedIbanSelected()) { + parentReturn.additional_data.rp_iban_reference = this.getSavedIbanReference(); + } else if (this.rememberIban === true) { + parentReturn.additional_data.rp_rememberiban = true; + } } return parentReturn; } From 861d4ff06ba49b647a6d71d878cfc5f514f974dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 7 Dec 2020 16:58:28 +0100 Subject: [PATCH 5/7] M2-52 - Changed BAMS wording --- i18n/de_DE.csv | 6 +++--- i18n/en_GB.csv | 4 ++-- i18n/en_US.csv | 4 ++-- view/frontend/templates/customer/bankdata.phtml | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv index f0288c0..ac4e6cd 100644 --- a/i18n/de_DE.csv +++ b/i18n/de_DE.csv @@ -141,11 +141,11 @@ ratepay_terms_block_6, "einverstanden." ,module,RatePAY_Payment "Return previous adjustments","Vorherige Erstattungen/Gebühren retournieren",module,RatePAY_Payment "Bank data management","Zahlungsdaten-Verwaltung",module,RatePAY_Payment "You have no saved bank data.","Sie haben noch keine gespeicherten Zahlungsdaten",module,RatePAY_Payment -"ratepay_directdebit_save_bankdata_text","Mit Auswahl dieser Option kann Ihr nächster Kauf bei uns schneller und einfacher abgewickelt werden. Sie können Ihre Zahlungsdaten jederzeit ändern oder entfernen.",module,RatePAY_Payment +"ratepay_directdebit_save_bankdata_text","Mit Auswahl dieser Option kann Ihr nächster Kauf bei uns schneller und einfacher abgewickelt werden. Sie können Ihre Zahlungsdaten jederzeit entfernen.",module,RatePAY_Payment "ratepay_directdebit_save_bankdata_link","Weitere Informationen",module,RatePAY_Payment -"ratepay_directdebit_save_bankdata_overlay_1","Wenn Sie „Zahlungsdaten merken“ auswählen, werden Ihre Zahlungsinformationen für zukünftige Käufe bei uns gespeichert. So können Sie bei uns gekaufte Artikel schnell und einfach bezahlen, ohne Ihre Zahlungsdaten für Ihre nächsten Käufe bei uns erneut einzugeben. Bei der nächsten Kaufabwicklung können Sie die gespeicherten Zahlungsdaten jederzeit ändern oder entfernen. Diese Einstellungen können Sie auch in Ihrem",module,RatePAY_Payment +"ratepay_directdebit_save_bankdata_overlay_1","Wenn Sie „Zahlungsdaten merken“ auswählen, werden Ihre Zahlungsinformationen für zukünftige Käufe gespeichert. So können Sie gekaufte Artikel schnell und einfach bezahlen, ohne Ihre Zahlungsdaten für Ihre nächsten Käufe erneut einzugeben. Die gespeicherten Zahlungsdaten können Sie jederzeit in Ihrem",module,RatePAY_Payment "ratepay_directdebit_save_bankdata_overlay_2","Kundenkonto",module,RatePAY_Payment -"ratepay_directdebit_save_bankdata_overlay_3","vornehmen.",module,RatePAY_Payment +"ratepay_directdebit_save_bankdata_overlay_3","entfernen.",module,RatePAY_Payment "Save payment data","Zahlungsdaten merken",module,RatePAY_Payment "Close window","Fenster schließen",module,RatePAY_Payment "Connection was established successfully.","Verbindung konnte erfolgreich aufgebaut werden.",module,RatePAY_Payment diff --git a/i18n/en_GB.csv b/i18n/en_GB.csv index 1832b53..167c79e 100644 --- a/i18n/en_GB.csv +++ b/i18n/en_GB.csv @@ -133,8 +133,8 @@ ratepay_terms_block_6, "." ,module,RatePAY_Payment "The installment amount has been updated successfully.","The installment amount has been updated successfully.",module,RatePAY_Payment "Show details","Show details",module,RatePAY_Payment "Hide details","Hide details",module,RatePAY_Payment -"ratepay_directdebit_save_bankdata_text","Selecting this option will make your next purchase from us faster and easier. You can change or remove your payment details at any time.",module,RatePAY_Payment +"ratepay_directdebit_save_bankdata_text","Selecting this option will make your next purchase from us faster and easier. You can remove your payment details at any time.",module,RatePAY_Payment "ratepay_directdebit_save_bankdata_link","Further information",module,RatePAY_Payment -"ratepay_directdebit_save_bankdata_overlay_1","If you select „Save payment data“, your payment information will be saved for future purchases from us. This allows you to quickly and easily pay for items purchased from us without having to re-enter your payment data for your next purchases with us. During the next checkout you can change or remove the saved payment data at any time. You can also make these settings in your",module,RatePAY_Payment +"ratepay_directdebit_save_bankdata_overlay_1","If you select „Save payment data“, your payment information will be saved for future purchases. This allows you to quickly and easily pay for items purchased without having to re-enter your payment data for your next purchases. The saved payment data can be removed at any time in your",module,RatePAY_Payment "ratepay_directdebit_save_bankdata_overlay_2","customer account.",module,RatePAY_Payment "ratepay_directdebit_save_bankdata_overlay_3","",module,RatePAY_Payment diff --git a/i18n/en_US.csv b/i18n/en_US.csv index a1a9648..0c376df 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -133,8 +133,8 @@ ratepay_terms_block_6, "." ,module,RatePAY_Payment "The installment amount has been updated successfully.","The installment amount has been updated successfully.",module,RatePAY_Payment "Show details","Show details",module,RatePAY_Payment "Hide details","Hide details",module,RatePAY_Payment -"ratepay_directdebit_save_bankdata_text","Selecting this option will make your next purchase from us faster and easier. You can change or remove your payment details at any time.",module,RatePAY_Payment +"ratepay_directdebit_save_bankdata_text","Selecting this option will make your next purchase from us faster and easier. You can remove your payment details at any time.",module,RatePAY_Payment "ratepay_directdebit_save_bankdata_link","Further information",module,RatePAY_Payment -"ratepay_directdebit_save_bankdata_overlay_1","If you select „Save payment data“, your payment information will be saved for future purchases from us. This allows you to quickly and easily pay for items purchased from us without having to re-enter your payment data for your next purchases with us. During the next checkout you can change or remove the saved payment data at any time. You can also make these settings in your",module,RatePAY_Payment +"ratepay_directdebit_save_bankdata_overlay_1","If you select „Save payment data“, your payment information will be saved for future purchases. This allows you to quickly and easily pay for items purchased without having to re-enter your payment data for your next purchases. The saved payment data can be removed at any time in your",module,RatePAY_Payment "ratepay_directdebit_save_bankdata_overlay_2","customer account.",module,RatePAY_Payment "ratepay_directdebit_save_bankdata_overlay_3","",module,RatePAY_Payment diff --git a/view/frontend/templates/customer/bankdata.phtml b/view/frontend/templates/customer/bankdata.phtml index 2882767..2ae7d04 100644 --- a/view/frontend/templates/customer/bankdata.phtml +++ b/view/frontend/templates/customer/bankdata.phtml @@ -15,7 +15,7 @@
- +