diff --git a/Block/Customer/Bankdata.php b/Block/Customer/Bankdata.php new file mode 100644 index 0000000..0c18b63 --- /dev/null +++ b/Block/Customer/Bankdata.php @@ -0,0 +1,73 @@ +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->getBankDataForAllIbanProfiles($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..00bd246 --- /dev/null +++ b/Block/Customer/DataLink.php @@ -0,0 +1,50 @@ +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/Block/System/Config/BamsOauthCheck.php b/Block/System/Config/BamsOauthCheck.php new file mode 100644 index 0000000..96ea27a --- /dev/null +++ b/Block/System/Config/BamsOauthCheck.php @@ -0,0 +1,86 @@ +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/Bankdata.php b/Controller/Customer/Bankdata.php new file mode 100644 index 0000000..53dd8a2 --- /dev/null +++ b/Controller/Customer/Bankdata.php @@ -0,0 +1,59 @@ +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..587e279 --- /dev/null +++ b/Controller/Customer/Delete.php @@ -0,0 +1,74 @@ +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->getBankDataForAllIbanProfiles($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 9e2cbdb..1227c8d 100644 --- a/Helper/Content/Customer/BankAccount.php +++ b/Helper/Content/Customer/BankAccount.php @@ -23,10 +23,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..72778bf --- /dev/null +++ b/Model/BamsApi/Base.php @@ -0,0 +1,178 @@ +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 + */ + public function getAuthToken() + { + if ($this->aAuthToken === null) { + $aRequest = [ + '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' + ]; + $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..6a78a49 --- /dev/null +++ b/Model/BamsApi/DeleteBankAccount.php @@ -0,0 +1,39 @@ + $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..9147004 --- /dev/null +++ b/Model/BamsApi/GetStoredBankAccounts.php @@ -0,0 +1,136 @@ + $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; + } + + /** + * 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 getBankDataForAllIbanProfiles($iCustomerNr) + { + $aDebitProfiles = $this->getAvailableDebitProfiles(); + $aReturn = []; + foreach ($aDebitProfiles as $sDebitProfile) { + $aBankAccounts = $this->sendRequest($iCustomerNr, $sDebitProfile); + if (!empty($aBankAccounts)) { + $aReturn = array_merge($aReturn, $aBankAccounts); + } + } + $aReturn = $this->removeDuplicateData($aReturn); + 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..25d8a6f --- /dev/null +++ b/Model/BamsApi/StoreBankAccount.php @@ -0,0 +1,46 @@ + $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 d52062c..cc4288c 100644 --- a/Model/Method/AbstractMethod.php +++ b/Model/Method/AbstractMethod.php @@ -14,6 +14,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\Handler\Cancel; use RatePAY\Payment\Model\Handler\Capture; @@ -152,6 +153,13 @@ abstract class AbstractMethod extends \Magento\Payment\Model\Method\AbstractMeth */ protected $hidePaymentType; + /** + * BAMS StoreBankAccount request model + * + * @var StoreBankAccount + */ + protected $storeBankAccount; + /** * Ratepay capture handler * @@ -207,6 +215,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 \RatePAY\Payment\Model\Handler\Capture $captureHandler * @param \RatePAY\Payment\Model\Handler\Refund $refundHandler * @param \RatePAY\Payment\Model\Handler\Cancel $cancelHandler @@ -234,6 +243,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, \RatePAY\Payment\Model\Handler\Capture $captureHandler, \RatePAY\Payment\Model\Handler\Refund $refundHandler, \RatePAY\Payment\Model\Handler\Cancel $cancelHandler, @@ -266,6 +276,7 @@ function __construct( $this->customerSession = $customerSession; $this->libraryController = $libraryController; $this->hidePaymentType = $hidePaymentType; + $this->storeBankAccount = $storeBankAccount; $this->captureHandler = $captureHandler; $this->refundHandler = $refundHandler; $this->cancelHandler = $cancelHandler; @@ -688,7 +699,22 @@ public function assignData(\Magento\Framework\DataObject $data) $sIban = $additionalData->getRpIban(); if ($this instanceof Directdebit || !empty($sIban) || $additionalData->getRpDirectdebit() == "1") { // getRpIban used for installments $this->rpValidator->validateIban($additionalData); - $infoInstance->setAdditionalInformation('rp_iban', $sIban); + $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) { diff --git a/Model/RechnungConfigProvider.php b/Model/RechnungConfigProvider.php index a435400..8d8c8c8 100644 --- a/Model/RechnungConfigProvider.php +++ b/Model/RechnungConfigProvider.php @@ -9,6 +9,8 @@ namespace RatePAY\Payment\Model; +use RatePAY\Payment\Model\Method\Directdebit; +use RatePAY\Payment\Model\Method\Installment; use RatePAY\Payment\Model\Method\AbstractMethod; use RatePAY\Payment\Model\Method\Invoice; @@ -36,6 +38,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; + /** * @var AbstractMethod[] */ @@ -63,22 +82,42 @@ class RechnungConfigProvider implements \Magento\Checkout\Model\ConfigProviderIn \RatePAY\Payment\Model\Method\Installment0::METHOD_CODE, ]; + /** + * Array with all ratepay iban payment methods + * + * @var array + */ + protected $rememberIbanPaymentTypes = [ + \RatePAY\Payment\Model\Method\Directdebit::METHOD_CODE, + \RatePAY\Payment\Model\Method\Installment::METHOD_CODE, + \RatePAY\Payment\Model\Method\Installment0::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,10 +128,28 @@ public function getConfig() $config = array_merge_recursive([], $this->getInstallmentConfig()); $config = array_merge_recursive($config, $this->getB2BConfig()); $config = array_merge_recursive($config, $this->getRatepaySandboxConfig()); - + $config = array_merge_recursive($config, $this->getRatepayGeneralConfig()); + + if ($this->isRememberIbanAllowed()) { + $config = array_merge_recursive($config, $this->getRememberIbanConfig($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; + } + /** * @param string $sMethodCode * @return AbstractMethod @@ -137,6 +194,21 @@ protected function getB2BConfig() return $config; } + protected function getRatepayGeneralConfig() + { + return [ + 'payment' => [ + 'ratepay' => [ + 'manageBankdataUrl' => $this->urlBuilder->getUrl("ratepay/customer/bankdata"), + 'rememberIbanEnabled' => $this->isRememberIbanAllowed(), + ], + ], + ]; + } + + /** + * @return array + */ protected function getRatepaySandboxConfig() { $config = []; @@ -174,6 +246,43 @@ protected function getSingleInstallmentConfig($sMethodCode) ] : []; } + /** + * @param string $sMethodCode + * @param int $iCustomerId + * @return array + */ + protected function getSingleRememberIbanConfig($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->getMethod($sMethodCode)->getMatchingProfile()->getData("profile_id"); + $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 @@ -195,6 +304,19 @@ protected function getInstallmentConfig() return $config; } + /** + * @param int $iCustomerId + * @return array + */ + protected function getRememberIbanConfig($iCustomerId) + { + $config = []; + foreach ($this->rememberIbanPaymentTypes as $debitPaymentType) { + $config = array_merge_recursive($config, $this->getSingleRememberIbanConfig($debitPaymentType, $iCustomerId)); + } + return $config; + } + /** * @param string $sMethodCode * @return array diff --git a/Observer/SystemConfigChangedPayment.php b/Observer/SystemConfigChangedPayment.php index ef7dc10..9a174a7 100644 --- a/Observer/SystemConfigChangedPayment.php +++ b/Observer/SystemConfigChangedPayment.php @@ -16,6 +16,16 @@ class SystemConfigChangedPayment implements ObserverInterface { + /** + * @var \Magento\Backend\Model\Session + */ + protected $backendSession; + + /** + * @var \RatePAY\Payment\Model\BamsApi\GetStoredBankAccounts + */ + protected $getStoredBankAccounts; + /** * @var \RatePAY\Payment\Helper\ProfileConfig */ @@ -25,11 +35,17 @@ class SystemConfigChangedPayment implements ObserverInterface * Constructor * * @param \RatePAY\Payment\Helper\ProfileConfig $profileConfigHelper + * @param \Magento\Backend\Model\Session $backendSession + * @param \RatePAY\Payment\Model\BamsApi\GetStoredBankAccounts $getStoredBankAccounts */ public function __construct( - \RatePAY\Payment\Helper\ProfileConfig $profileConfigHelper + \RatePAY\Payment\Helper\ProfileConfig $profileConfigHelper, + \Magento\Backend\Model\Session $backendSession, + \RatePAY\Payment\Model\BamsApi\GetStoredBankAccounts $getStoredBankAccounts ) { $this->profileConfigHelper = $profileConfigHelper; + $this->backendSession = $backendSession; + $this->getStoredBankAccounts = $getStoredBankAccounts; } /** @@ -40,7 +56,7 @@ public function __construct( protected function handleProfileConfigurationUpdate($sChangedPath) { $sPseudoMethodCode = Invoice::METHOD_CODE; - if (stripos($sChangedPath, Invoice::BACKEND_SUFFIX) !== false) { ///@TODO: testen + if (stripos($sChangedPath, Invoice::BACKEND_SUFFIX) !== false) { $sPseudoMethodCode = $sPseudoMethodCode.Invoice::BACKEND_SUFFIX; } $this->profileConfigHelper->refreshProfileConfigurations($sPseudoMethodCode); @@ -56,6 +72,13 @@ 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); + } + } if (stripos($sChangedPath, "profile_config") !== false && stripos($sChangedPath, "ratepay") !== false) { $this->handleProfileConfigurationUpdate($sChangedPath); } diff --git a/etc/adminhtml/events.xml b/etc/adminhtml/events.xml index c1d2967..90830e7 100644 --- a/etc/adminhtml/events.xml +++ b/etc/adminhtml/events.xml @@ -11,4 +11,7 @@ + + + diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 0d594dd..b4f9488 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -38,6 +38,37 @@ Enable this option to interpret the HTTP_X_FORWARDED_FOR and HTTP_X_REAL_IP headers. Should be activated if your shop is behind a Proxy server. ratepay/general/proxy_mode + + + 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 + + + + RatePAY\Payment\Block\System\Config\BamsOauthCheck + + + + Magento\Config\Model\Config\Source\Yesno + ratepay/general/bams_sandbox + + 1 + + RatePAY\Payment\Model\Source\StreetFieldUsage diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv index 10e10cb..2513a16 100644 --- a/i18n/de_DE.csv +++ b/i18n/de_DE.csv @@ -160,6 +160,8 @@ ratepay_terms_block_6, "einverstanden." ,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 +"Connection could not be established.","Verbindung konnte nicht aufgebaut werden.",module,RatePAY_Payment "Maximum Order Total B2B","Maximalwert für Gesamtbestellung B2B",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..6e54cee --- /dev/null +++ b/view/adminhtml/templates/system/config/bamsoauthcheck.phtml @@ -0,0 +1,13 @@ + +getStatus() === true): ?> +
+getStatus() === false): ?> +
+ diff --git a/view/frontend/layout/customer_account.xml b/view/frontend/layout/customer_account.xml new file mode 100644 index 0000000..7ce1982 --- /dev/null +++ b/view/frontend/layout/customer_account.xml @@ -0,0 +1,21 @@ + + + + + + + + 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..0cf7c3c --- /dev/null +++ b/view/frontend/layout/ratepay_customer_bankdata.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + diff --git a/view/frontend/templates/customer/bankdata.phtml b/view/frontend/templates/customer/bankdata.phtml new file mode 100644 index 0000000..a61a80a --- /dev/null +++ b/view/frontend/templates/customer/bankdata.phtml @@ -0,0 +1,35 @@ + +getSavedBankData(); ?> + +
+ + + + + + + + + + + + + + + + + +
 
+ +
+
+ +
+ \ No newline at end of file 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 0715d10..d3f81c8 100644 --- a/view/frontend/web/js/view/payment/method-renderer/base.js +++ b/view/frontend/web/js/view/payment/method-renderer/base.js @@ -107,6 +107,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 e8dcc50..fb7db09 100644 --- a/view/frontend/web/js/view/payment/method-renderer/directdebit.js +++ b/view/frontend/web/js/view/payment/method-renderer/directdebit.js @@ -28,8 +28,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(); @@ -58,12 +60,25 @@ 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(); - } + }, + initialize: function () { + this._super(); + 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 ea82af8..f7f251e 100644 --- a/view/frontend/web/js/view/payment/method-renderer/installment.js +++ b/view/frontend/web/js/view/payment/method-renderer/installment.js @@ -32,7 +32,9 @@ define( isInstallmentPlanSet: false, useDirectDebit: true, sepaAccepted: false, - b2b_accountholder: '' + b2b_accountholder: '', + rp_reference: '', + rememberIban: false }, initialize: function () { @@ -42,6 +44,9 @@ define( } else { this.updateInstallmentPlan('time', this.getAllowedMonths()[0], this.getCode(), false); } + if (this.isRememberIBANEnabled()) { + this.rp_iban = this.getDefaultIban(); + } return this; }, isDirectDebitDefault: function () { @@ -160,11 +165,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.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; } diff --git a/view/frontend/web/template/payment/directdebit.html b/view/frontend/web/template/payment/directdebit.html index 72d1bb5..24c0630 100644 --- a/view/frontend/web/template/payment/directdebit.html +++ b/view/frontend/web/template/payment/directdebit.html @@ -146,6 +146,7 @@ id: getCode() + '_iban', autocomplete: off, title: $t('IBAN')}, + event: {keyup:onChangeIban}, value: rp_iban"> @@ -163,7 +164,33 @@ - + + + + + + + +
+ + +
+ +
+ +
+
+ +

diff --git a/view/frontend/web/template/payment/installment.html b/view/frontend/web/template/payment/installment.html index d390c16..a698326 100644 --- a/view/frontend/web/template/payment/installment.html +++ b/view/frontend/web/template/payment/installment.html @@ -210,7 +210,7 @@

:
- +
@@ -228,6 +228,31 @@

+ + + + + +
+ + +
+ +
+ +
+
+ +