From 65bee368d7b5cab91bfde1f5ef9a973d362eb96c Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Thu, 13 Sep 2018 13:44:58 +0200 Subject: [PATCH 1/7] [feature](MAGE2-86) integration-iDeal: Set up first working version of iDeal. --- .gitignore | 3 +- Controller/Index/InitializePayment.php | 180 ++++++++++++++++++ Gateway/Config/HgwIDealPaymentConfig.php | 13 ++ .../Config/HgwIDealPaymentConfigInterface.php | 13 ++ Model/Config/IDealConfigProvider.php | 46 +++++ .../HeidelpayAbstractPaymentMethod.php | 22 ++- .../HeidelpayIDealPaymentMethod.php | 130 +++++++++++++ etc/adminhtml/system.xml | 39 ++++ etc/config.xml | 12 ++ etc/di.xml | 6 + etc/frontend/di.xml | 12 ++ i18n/de_DE.csv | 1 + i18n/en_US.csv | 2 + view/frontend/layout/checkout_index_index.xml | 3 + .../web/js/view/payment/hgw-payments.js | 4 + .../view/payment/method-renderer/hgw-ideal.js | 110 +++++++++++ .../payment/heidelpay-ideal-form.html | 80 ++++++++ 17 files changed, 669 insertions(+), 7 deletions(-) create mode 100644 Controller/Index/InitializePayment.php create mode 100644 Gateway/Config/HgwIDealPaymentConfig.php create mode 100644 Gateway/Config/HgwIDealPaymentConfigInterface.php create mode 100644 Model/Config/IDealConfigProvider.php create mode 100644 PaymentMethods/HeidelpayIDealPaymentMethod.php create mode 100644 etc/frontend/di.xml create mode 100644 view/frontend/web/js/view/payment/method-renderer/hgw-ideal.js create mode 100644 view/frontend/web/template/payment/heidelpay-ideal-form.html diff --git a/.gitignore b/.gitignore index c3c6f290615..3caf4b3c474 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /.project /composer.phar /composer.lock -/auth.json \ No newline at end of file +/auth.json +/.idea \ No newline at end of file diff --git a/Controller/Index/InitializePayment.php b/Controller/Index/InitializePayment.php new file mode 100644 index 00000000000..39db1aae680 --- /dev/null +++ b/Controller/Index/InitializePayment.php @@ -0,0 +1,180 @@ +resultJsonFactory = $resultJsonFactory; + $this->logger = $logger; + $this->checkoutSession = $checkoutSession; + $this->escaper = $escaper; + parent::__construct($context); + } + + /** + * {@inheritDoc} + * @throws \Magento\Framework\Exception\NotFoundException + * @throws \RuntimeException + * @throws CommandException + */ + public function execute() + { + /** @noinspection PhpUndefinedFunctionInspection */ + $error_message = __('An unexpected error occurred. Please contact us to get further information.'); + + $session = $this->getCheckoutSession(); + $quote = $session->getQuote(); + + $this->logger->debug('Heidelpay: Issue initial payment request...'); + + if (!$quote->getId()) { + $this->logger->error('Heidelpay: Quote not found in session.'); + throw new NotFoundException(new Phrase($this->escaper->escapeHtml($error_message))); + } + + // create result object for this request + $result = $this->resultJsonFactory->create(); + + // if there is no post request, just do nothing and return the redirectUrl instantly, so an + // error message can be shown to the customer (which will be created in the redirect controller) + if (!$this->getRequest()->isPost()) { + $this->logger->warning('Heidelpay - Response: Request is not POST.'); + + // return the result now, no further processing. + return $result; + } + + $postData = $this->getRequest()->getParams(); + $this->logger->debug('Heidelpay: postData - ' . print_r($postData, 1)); + + if (!isset($postData['method'])) { + throw new CommandException(new Phrase('Heidelpay: ')); + } + $payment = $quote->getPayment()->setMethod($postData['method']); + $paymentMethodInstance = $payment->getMethodInstance(); + + // get the response object from the initial request. + try { + // todo-simon: payment methods wieder abstrahieren und dann hier die abstrakte klasse type hinten + /** @var PaymentApiResponse $response */ + $response = $paymentMethodInstance->initMethod($quote); + $this->logger->debug('initialResponse ' . print_r($response, 1)); + } catch (CommandException $e) { + $postData = [ + $e->getLogMessage() + ]; + $this->logger->debug('Request failed: '); + return $result->setData($postData)->setHttpResponseCode(500); + } + + //TODO: remove brand-check when initial request for iDeal is async. + if ((!$response instanceof PaymentApiResponse || !$response->isSuccess()) && empty($response->getConfig()->getBrands())) { + $this->logger->error('Heidelpay: Initial request did not succeed.'); + throw new \RuntimeException($this->escaper->escapeHtml($error_message)); + } + + // todo-simon: what to do. if not redirect? +// // redirect to payment url, if it uses redirecting +// if ($paymentMethodInstance->activeRedirect() === true) { +// return $this->_redirect($response->getPaymentFormUrl()); +// } +// +// $resultPage = $this->_resultPageFactory->create(); +// $resultPage->getConfig()->getTitle()->prepend(__('Please confirm your payment:')); +// $resultPage->getLayout()->getBlock('heidelpay_gateway')->setHgwUrl( +// $response->getPaymentFormUrl() +// ); +// $resultPage->getLayout()->getBlock('heidelpay_gateway')->setHgwCode($payment->getCode()); +// +// return $resultPage; + + $brands = $response->getConfig()->getBrands(); + $this->logger->debug('brand origin: ' . print_r($brands, 1)); + + $bankNamesList = []; + $bankValueList = []; + + foreach ($brands as $brandValue => $brandName) { + $bankValueList[] = $brandValue; + $bankNamesList[] = $brandName; + } + + $this->logger->debug('brand values: ' . print_r($bankValueList, 1)); + $this->logger->debug('brand names: ' . print_r($bankNamesList, 1)); + + $postData = [ + 'brandValues' => $bankValueList, + 'brandNames' => $bankNamesList + ]; + $this->logger->debug('postData: ' . print_r($postData, 1)); + $this->logger->debug('postData: json' . print_r(json_encode($postData), 1)); + + return $result->setData(json_encode($postData)); + } + + /** + * @return Session + */ + private function getCheckoutSession() + { + return $this->checkoutSession; + } +} diff --git a/Gateway/Config/HgwIDealPaymentConfig.php b/Gateway/Config/HgwIDealPaymentConfig.php new file mode 100644 index 00000000000..535ea2e271b --- /dev/null +++ b/Gateway/Config/HgwIDealPaymentConfig.php @@ -0,0 +1,13 @@ +config = $config; + } + + /** + * {@inheritDoc} + */ + public function getConfig() + { + //TODO david: ConfigProvider is not yet available in frontend. + $config = [ + 'payment' => [ + HeidelpayIDealPaymentMethod::CODE => [ + 'needs_external_info_in_checkout' => $this->config->getNeedsExternalInfoInCheckout() + ], + ] + ]; + + return $config; + } +} \ No newline at end of file diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index 32fbcbd47ad..4a84d371b8e 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -462,12 +462,7 @@ public function getHeidelpayUrl($quote) { $this->performAuthentication(); - $frontend = $this->getFrontend(); - - $this->_heidelpayPaymentMethod->getRequest()->async( - $frontend['LANGUAGE'], // Language code for the Frame - $frontend['RESPONSE_URL'] // Response url from your application - ); + $this->setAsync(); $user = $this->getUser($quote); $this->_heidelpayPaymentMethod->getRequest()->customerAddress( @@ -767,6 +762,11 @@ private function performAuthentication() ); } + public function setInitialRequest() + { + $this->performAuthentication(); + } + /** * will return the main configuration * @@ -786,4 +786,14 @@ public function getConfig() { return $this->paymentConfig; } + + public function setAsync() + { + $frontend = $this->getFrontend(); + + $this->_heidelpayPaymentMethod->getRequest()->async( + $frontend['LANGUAGE'], // Language code for the Frame + $frontend['RESPONSE_URL'] // Response url from your application + ); + } } diff --git a/PaymentMethods/HeidelpayIDealPaymentMethod.php b/PaymentMethods/HeidelpayIDealPaymentMethod.php new file mode 100644 index 00000000000..9edc6536ef9 --- /dev/null +++ b/PaymentMethods/HeidelpayIDealPaymentMethod.php @@ -0,0 +1,130 @@ +_heidelpayPaymentMethod = $iDealPaymentMethod; + } + + public function getHeidelpayUrl($quote) + { + // create the collection factory + $paymentInfoCollection = $this->paymentInformationCollectionFactory->create(); + + // load the payment information by store id, customer email address and payment method + /** @var \Heidelpay\Gateway\Model\PaymentInformation $paymentInfo */ + $paymentInfo = $paymentInfoCollection->loadByCustomerInformation( + $quote->getStoreId(), + $quote->getBillingAddress()->getEmail(), + $quote->getPayment()->getMethod() + ); + + // set some parameters inside the Abstract Payment method helper which are used for all requests, + // e.g. authentication, customer data, ... + parent::getHeidelpayUrl($quote); + + // add Bank selection to the request. + if (isset($paymentInfo->getAdditionalData()->hgw_bank_name)) { + $this->_heidelpayPaymentMethod + ->getRequest()->getAccount() + ->setBankName($paymentInfo->getAdditionalData()->hgw_bank_name); + } + + if (isset($paymentInfo->getAdditionalData()->hgw_holder)) { + $this->_heidelpayPaymentMethod + ->getRequest()->getAccount() + ->setHolder($paymentInfo->getAdditionalData()->hgw_holder); + } + + // send the init request with the debit method. + $this->_heidelpayPaymentMethod->authorize(); + + // return the response object + return $this->_heidelpayPaymentMethod->getResponse(); + } + + public function activeRedirect() + { + return true; + } + + public function initMethod() + { + $this->setInitialRequest(); + //$this->_heidelpayPaymentMethod->getRequest()->getFrontend()->setEnabled('FALSE'); + + return $this->_heidelpayPaymentMethod->authorize()->getResponse(); + } +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 5108e286f1b..093dc0ef43c 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -458,6 +458,45 @@ Insert 0 to disable limit. + + + + + Magento\Config\Model\Config\Source\Yesno + payment/hgwidl/active + + + + payment/hgwidl/title + + + + payment/hgwidl/channel + + + + payment/hgwidl/sort_order + + + + Magento\Payment\Model\Config\Source\Allspecificcountries + payment/hgwidl/allowspecific + + + + Magento\Directory\Model\Config\Source\Country + payment/hgwidl/specificcountry + + + + payment/hgwidl/min_order_total + + + + payment/hgwidl/max_order_total + Insert 0 to disable limit. + + diff --git a/etc/config.xml b/etc/config.xml index b8b40c19181..27c9dc6cba3 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -120,6 +120,18 @@ 0 Heidelpay\Gateway\PaymentMethods\HeidelpayInvoiceSecuredPaymentMethod + + 0 + authorize + <![CDATA[iDeal]]> + 31HA07BC8142C5A171749A60D979B6E4 + 1 + never + NL + 0 + 0 + Heidelpay\Gateway\PaymentMethods\HeidelpayIDealPaymentMethod + \ No newline at end of file diff --git a/etc/di.xml b/etc/di.xml index fa73fdfda79..904e6db6169 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -64,6 +64,11 @@ Heidelpay\Gateway\PaymentMethods\HeidelpayPayPalPaymentMethod::CODE + + + Heidelpay\Gateway\PaymentMethods\HeidelpayIDealPaymentMethod::CODE + + @@ -80,4 +85,5 @@ + \ No newline at end of file diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml new file mode 100644 index 00000000000..595bd55cbed --- /dev/null +++ b/etc/frontend/di.xml @@ -0,0 +1,12 @@ + + + + + + + Heidelpay\Gateway\Model\Config\IDealConfigProvider + + + + + \ No newline at end of file diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv index 38188e74e79..66b4c4ded66 100755 --- a/i18n/de_DE.csv +++ b/i18n/de_DE.csv @@ -10,6 +10,7 @@ "HGWDDS","Gesicherte Lastschrift (B2C)" "HGWIV","Rechnungskauf" "HGWIVS","Gesicherter Rechnungskauf (B2C)" +"HGWIDL","iDeal" "HGW_ABOUT_US","Die heidelpay GmbH, kurz: heidelpay, ist ein führendes, von der BaFin zugelassenes und beaufsichtigtes Zahlungsinstitut für Online-Paymentverfahren, welches das komplette Leistungsspektrum in Sachen elektronische Zahlungsabwicklung abdeckt: vom Processing der Transaktionen über die Vergabe der Akzeptanzstellenverträge bis hin zum Monitoring und Risk Management.

Mehr Informationen finden Sie auf www.heidelpay.de" diff --git a/i18n/en_US.csv b/i18n/en_US.csv index 4cd5cd5172f..f3cfaad3f05 100755 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -10,6 +10,7 @@ "HGWDDS","Direct Debit Secured (B2C)" "HGWIV","Invoice" "HGWIVS","Invoice Secured (B2C)" +"HGWIDL","iDeal" "HGW_ABOUT_US","heidelpay GmbH, shortly: heidelpay, is a leading payment institution for online payment methods authorized and regulated by BaFin, which offers the full range of services for an electronic payment processing from one single source: from processing of transactions and providing of acceptance contracts to monitoring and risk management.

For more information please visit www.heidelpay.de" @@ -36,6 +37,7 @@ "IBAN","IBAN" "BIC","BIC" "Bank Account Holder", "Bank Account Holder" +"Bank", "Bank" "Account Holder","Account Holder" "Salutation", "Salutation" "Mr.", "Mr." diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml index 6b460ebe489..e0c74392d53 100644 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -56,6 +56,9 @@ false + + false + diff --git a/view/frontend/web/js/view/payment/hgw-payments.js b/view/frontend/web/js/view/payment/hgw-payments.js index 39317af94d1..27a49694994 100644 --- a/view/frontend/web/js/view/payment/hgw-payments.js +++ b/view/frontend/web/js/view/payment/hgw-payments.js @@ -48,6 +48,10 @@ define( { type: 'hgwivs', component: 'Heidelpay_Gateway/js/view/payment/method-renderer/hgw-invoicesecured' + }, + { + type: 'hgwidl', + component: 'Heidelpay_Gateway/js/view/payment/method-renderer/hgw-ideal' } ); return Component.extend({}); diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-ideal.js b/view/frontend/web/js/view/payment/method-renderer/hgw-ideal.js new file mode 100644 index 00000000000..d6bdde581b4 --- /dev/null +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-ideal.js @@ -0,0 +1,110 @@ +define( + [ + 'jquery', + 'Heidelpay_Gateway/js/view/payment/method-renderer/hgw-abstract', + 'Heidelpay_Gateway/js/action/place-order', + 'Magento_Checkout/js/model/url-builder', + 'mage/storage', + 'Magento_Checkout/js/model/payment/additional-validators', + 'Magento_Customer/js/model/customer', + 'Magento_Checkout/js/model/quote', + 'mage/url' + ], + function ($, Component, placeOrderAction, urlBuilder, storage, additionalValidators, customer, quote, url) { + 'use strict'; + + return Component.extend({ + + /** + * Property that indicates, if the payment method is storing + * additional data. + */ + savesAdditionalData: true, + + defaults: { + template: 'Heidelpay_Gateway/payment/heidelpay-ideal-form', + hgwBankSelection: 'INGBNL2A', + hgwBrandValues: [null], + hgwBrandNames: [null], + hgwHolder: '' + }, + + // set observers to update values in frontend when variable is changed. + initObservable: function() { + this._super() + .observe([ + 'hgwBrandValues', 'hgwBrandNames', 'hgwBankSelection', 'hgwHolder' + ]); + + return this; + }, + + getData: function () { + console.log(this.hgwBankSelection) + return { + 'method': this.item.method, + 'additional_data': { + 'hgw_bank_name': this.hgwBankSelection(), + 'hgw_holder': this.hgwHolder() + } + }; + }, + + initialize: function () { + this._super(); + //this.getAdditionalPaymentInformation(); + this.hgwHolder(this.getFullName()); + this.setAvailableBanks(); + + console.log(this.hgwBrandNames); + + $( document ).ajaxStop(function() { + return this; + }); + }, + + + getCode: function () { + return 'hgwidl'; + }, + + setAvailableBanks: function () { + var method = this.item.method; + var payment = window.checkoutConfig.payment; + console.log(method); + console.log(payment); + + //if (payment !== undefined) { + $.ajax({ + showLoader: true, + url: url.build('hgw/index/initializepayment'), + data: { + method: method + }, + type: 'POST', + dataType: 'json', + context: this + }).done(function (data) { + var response = JSON.parse(data); + // set the iDeal brand information, which comes from the payment + if (response !== null) { + this.hgwBrandValues(response.brandValues); + this.hgwBrandNames(response.brandNames); + console.log('json done'); + console.log(response.brandValues); + console.log(response.brandNames); + return this; + } + return this; + }).fail(function (response) { + console.log('response fail: ' + response); + // errorProcessor.process(response, this.messageContainer); + // fullScreenLoader.stopLoader(); + // alert ("Error"); + // window.location.replace(url.build('checkout/')); + }); + //} + } + }); + } +); \ No newline at end of file diff --git a/view/frontend/web/template/payment/heidelpay-ideal-form.html b/view/frontend/web/template/payment/heidelpay-ideal-form.html new file mode 100644 index 00000000000..4279a4a17e8 --- /dev/null +++ b/view/frontend/web/template/payment/heidelpay-ideal-form.html @@ -0,0 +1,80 @@ +
+
+ + +
+ + +
+ + + +
+ + + +
+
+
+
+ +
+
+
+ +
+ +
+
+
+
+
+ +
+
+
+
+
+ + +
+
+
+
+
+
+
+
+
+ +
+
+
+
\ No newline at end of file From ab177097d14cab66d9d74e49d72845d89bd2c216 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Thu, 13 Sep 2018 20:27:16 +0200 Subject: [PATCH 2/7] [feature](MAGE2-86) integration-iDeal: remove debug-logs. - set the correct text vor bank options. - remove IDealconfigProvider --- Controller/Index/InitializePayment.php | 42 +---------------- Model/Config/IDealConfigProvider.php | 46 ------------------- .../HeidelpayAbstractPaymentMethod.php | 19 +++++++- .../HeidelpayIDealPaymentMethod.php | 40 +++++++++++++--- etc/frontend/di.xml | 12 ----- .../view/payment/method-renderer/hgw-ideal.js | 23 +++------- .../payment/heidelpay-ideal-form.html | 10 +++- 7 files changed, 68 insertions(+), 124 deletions(-) delete mode 100644 Model/Config/IDealConfigProvider.php delete mode 100644 etc/frontend/di.xml diff --git a/Controller/Index/InitializePayment.php b/Controller/Index/InitializePayment.php index 39db1aae680..0c6cfcfb8aa 100644 --- a/Controller/Index/InitializePayment.php +++ b/Controller/Index/InitializePayment.php @@ -83,8 +83,6 @@ public function execute() $session = $this->getCheckoutSession(); $quote = $session->getQuote(); - $this->logger->debug('Heidelpay: Issue initial payment request...'); - if (!$quote->getId()) { $this->logger->error('Heidelpay: Quote not found in session.'); throw new NotFoundException(new Phrase($this->escaper->escapeHtml($error_message))); @@ -113,59 +111,21 @@ public function execute() // get the response object from the initial request. try { - // todo-simon: payment methods wieder abstrahieren und dann hier die abstrakte klasse type hinten /** @var PaymentApiResponse $response */ $response = $paymentMethodInstance->initMethod($quote); - $this->logger->debug('initialResponse ' . print_r($response, 1)); } catch (CommandException $e) { $postData = [ $e->getLogMessage() ]; - $this->logger->debug('Request failed: '); return $result->setData($postData)->setHttpResponseCode(500); } - //TODO: remove brand-check when initial request for iDeal is async. if ((!$response instanceof PaymentApiResponse || !$response->isSuccess()) && empty($response->getConfig()->getBrands())) { $this->logger->error('Heidelpay: Initial request did not succeed.'); throw new \RuntimeException($this->escaper->escapeHtml($error_message)); } - // todo-simon: what to do. if not redirect? -// // redirect to payment url, if it uses redirecting -// if ($paymentMethodInstance->activeRedirect() === true) { -// return $this->_redirect($response->getPaymentFormUrl()); -// } -// -// $resultPage = $this->_resultPageFactory->create(); -// $resultPage->getConfig()->getTitle()->prepend(__('Please confirm your payment:')); -// $resultPage->getLayout()->getBlock('heidelpay_gateway')->setHgwUrl( -// $response->getPaymentFormUrl() -// ); -// $resultPage->getLayout()->getBlock('heidelpay_gateway')->setHgwCode($payment->getCode()); -// -// return $resultPage; - - $brands = $response->getConfig()->getBrands(); - $this->logger->debug('brand origin: ' . print_r($brands, 1)); - - $bankNamesList = []; - $bankValueList = []; - - foreach ($brands as $brandValue => $brandName) { - $bankValueList[] = $brandValue; - $bankNamesList[] = $brandName; - } - - $this->logger->debug('brand values: ' . print_r($bankValueList, 1)); - $this->logger->debug('brand names: ' . print_r($bankNamesList, 1)); - - $postData = [ - 'brandValues' => $bankValueList, - 'brandNames' => $bankNamesList - ]; - $this->logger->debug('postData: ' . print_r($postData, 1)); - $this->logger->debug('postData: json' . print_r(json_encode($postData), 1)); + $postData = $paymentMethodInstance->prepareAdditionalFormData($response); return $result->setData(json_encode($postData)); } diff --git a/Model/Config/IDealConfigProvider.php b/Model/Config/IDealConfigProvider.php deleted file mode 100644 index 6a879554db2..00000000000 --- a/Model/Config/IDealConfigProvider.php +++ /dev/null @@ -1,46 +0,0 @@ -config = $config; - } - - /** - * {@inheritDoc} - */ - public function getConfig() - { - //TODO david: ConfigProvider is not yet available in frontend. - $config = [ - 'payment' => [ - HeidelpayIDealPaymentMethod::CODE => [ - 'needs_external_info_in_checkout' => $this->config->getNeedsExternalInfoInCheckout() - ], - ] - ]; - - return $config; - } -} \ No newline at end of file diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index 4a84d371b8e..07d9ece0da1 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -762,9 +762,23 @@ private function performAuthentication() ); } - public function setInitialRequest() + /** + * Function to provide additional formDate. + * Should be overwritten by child classes if needed. + * @param Response $response + * @return array + */ + public function prepareAdditionalFormData(Response $response) + { + } + + /* + * Setup initialreques without customer data. + */ + public function setupInitialRequest() { $this->performAuthentication(); + $this->setAsync(); } /** @@ -787,6 +801,9 @@ public function getConfig() return $this->paymentConfig; } + /** + * Set the parameter for async modus. + */ public function setAsync() { $frontend = $this->getFrontend(); diff --git a/PaymentMethods/HeidelpayIDealPaymentMethod.php b/PaymentMethods/HeidelpayIDealPaymentMethod.php index 9edc6536ef9..59eb3a29e9a 100644 --- a/PaymentMethods/HeidelpayIDealPaymentMethod.php +++ b/PaymentMethods/HeidelpayIDealPaymentMethod.php @@ -8,10 +8,11 @@ namespace Heidelpay\Gateway\PaymentMethods; -use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; use Heidelpay\Gateway\Gateway\Config\HgwIDealPaymentConfigInterface; +use Heidelpay\Gateway\Gateway\Config\HgwMainConfigInterface; use Heidelpay\Gateway\Model\ResourceModel\PaymentInformation\CollectionFactory as PaymentInformationCollectionFactory; use Heidelpay\Gateway\Model\ResourceModel\Transaction\CollectionFactory as HeidelpayTransactionCollectionFactory; +use Heidelpay\PhpPaymentApi\Response; class HeidelpayIDealPaymentMethod extends HeidelpayAbstractPaymentMethod { @@ -23,6 +24,7 @@ class HeidelpayIDealPaymentMethod extends HeidelpayAbstractPaymentMethod protected $_isGateway = true; + public function __construct( \Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, @@ -48,7 +50,8 @@ public function __construct( \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [] - ) { + ) + { parent::__construct( $context, $registry, @@ -78,6 +81,30 @@ public function __construct( $this->_heidelpayPaymentMethod = $iDealPaymentMethod; } + /** + * Provide necessary information for bank selection + * @param Response $response + * @return array + */ + public function prepareAdditionalFormData(Response $response) + { + $brands = $response->getConfig()->getBrands(); + $bankList = []; + + /** + * build array object for javascript frontend + */ + foreach ($brands as $brandValue => $brandName) { + $bank = []; + $bank['value'] = $brandValue; + $bank['name'] = $brandName; + + $bankList[] = $bank; + } + + return $bankList; + } + public function getHeidelpayUrl($quote) { // create the collection factory @@ -108,7 +135,7 @@ public function getHeidelpayUrl($quote) ->setHolder($paymentInfo->getAdditionalData()->hgw_holder); } - // send the init request with the debit method. + // send the init request with the authorize method. $this->_heidelpayPaymentMethod->authorize(); // return the response object @@ -120,11 +147,12 @@ public function activeRedirect() return true; } + /* + * Send an authorize request to get a response which contains list of available banks. + */ public function initMethod() { - $this->setInitialRequest(); - //$this->_heidelpayPaymentMethod->getRequest()->getFrontend()->setEnabled('FALSE'); - + $this->setupInitialRequest(); return $this->_heidelpayPaymentMethod->authorize()->getResponse(); } } diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml deleted file mode 100644 index 595bd55cbed..00000000000 --- a/etc/frontend/di.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - Heidelpay\Gateway\Model\Config\IDealConfigProvider - - - - - \ No newline at end of file diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-ideal.js b/view/frontend/web/js/view/payment/method-renderer/hgw-ideal.js index d6bdde581b4..fb736edbe39 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-ideal.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-ideal.js @@ -23,13 +23,13 @@ define( defaults: { template: 'Heidelpay_Gateway/payment/heidelpay-ideal-form', - hgwBankSelection: 'INGBNL2A', + hgwBankSelection: '', hgwBrandValues: [null], hgwBrandNames: [null], hgwHolder: '' }, - // set observers to update values in frontend when variable is changed. + // set observers to update values in frontend when values are changed. initObservable: function() { this._super() .observe([ @@ -40,7 +40,6 @@ define( }, getData: function () { - console.log(this.hgwBankSelection) return { 'method': this.item.method, 'additional_data': { @@ -56,25 +55,19 @@ define( this.hgwHolder(this.getFullName()); this.setAvailableBanks(); - console.log(this.hgwBrandNames); $( document ).ajaxStop(function() { return this; }); }, - getCode: function () { return 'hgwidl'; }, setAvailableBanks: function () { var method = this.item.method; - var payment = window.checkoutConfig.payment; - console.log(method); - console.log(payment); - //if (payment !== undefined) { $.ajax({ showLoader: true, url: url.build('hgw/index/initializepayment'), @@ -86,22 +79,18 @@ define( context: this }).done(function (data) { var response = JSON.parse(data); + + // set the iDeal brand information, which comes from the payment if (response !== null) { - this.hgwBrandValues(response.brandValues); + this.hgwBrandValues(response); this.hgwBrandNames(response.brandNames); - console.log('json done'); - console.log(response.brandValues); - console.log(response.brandNames); + return this; } return this; }).fail(function (response) { console.log('response fail: ' + response); - // errorProcessor.process(response, this.messageContainer); - // fullScreenLoader.stopLoader(); - // alert ("Error"); - // window.location.replace(url.build('checkout/')); }); //} } diff --git a/view/frontend/web/template/payment/heidelpay-ideal-form.html b/view/frontend/web/template/payment/heidelpay-ideal-form.html index 4279a4a17e8..a7b3839f429 100644 --- a/view/frontend/web/template/payment/heidelpay-ideal-form.html +++ b/view/frontend/web/template/payment/heidelpay-ideal-form.html @@ -49,7 +49,15 @@ From 88d46c041be74a8c0ce8b572e0741dab3edf716e Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Thu, 27 Sep 2018 18:50:10 +0200 Subject: [PATCH 3/7] [feature](MAGE2-86) integration-iDeal: fix js error when brands are null. --- .../payment/heidelpay-ideal-form.html | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/view/frontend/web/template/payment/heidelpay-ideal-form.html b/view/frontend/web/template/payment/heidelpay-ideal-form.html index a7b3839f429..7aed3eac399 100644 --- a/view/frontend/web/template/payment/heidelpay-ideal-form.html +++ b/view/frontend/web/template/payment/heidelpay-ideal-form.html @@ -39,7 +39,7 @@ - +
@@ -52,11 +52,16 @@ data-bind="attr: {title: hgwBankSelection}, value: hgwBankSelection, options: hgwBrandValues, - optionsValue: function(item) { - return item.value + optionsCaption: '', + optionsValue: function(brands) { + if(brands) { + return brands.value + } }, optionsText: function(brands) { - return brands.name + if(brands) { + return brands.name + } }" data-validate="{required: true}" > @@ -68,18 +73,17 @@
-
+
-
From 4ae5dd077e56d7e729fca8e4bb3e2de71521dd48 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Thu, 27 Sep 2018 18:55:10 +0200 Subject: [PATCH 4/7] [feature](MAGE2-86) cleanup code --- Controller/Index/InitializePayment.php | 4 +-- .../HeidelpayAbstractPaymentMethod.php | 3 ++- .../HeidelpayIDealPaymentMethod.php | 5 ++-- .../view/payment/method-renderer/hgw-ideal.js | 27 ++++++++++--------- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Controller/Index/InitializePayment.php b/Controller/Index/InitializePayment.php index 0c6cfcfb8aa..b505d52a4aa 100644 --- a/Controller/Index/InitializePayment.php +++ b/Controller/Index/InitializePayment.php @@ -113,14 +113,14 @@ public function execute() try { /** @var PaymentApiResponse $response */ $response = $paymentMethodInstance->initMethod($quote); - } catch (CommandException $e) { + } catch (\Exception $e) { $postData = [ $e->getLogMessage() ]; return $result->setData($postData)->setHttpResponseCode(500); } - if ((!$response instanceof PaymentApiResponse || !$response->isSuccess()) && empty($response->getConfig()->getBrands())) { + if ((!$response instanceof PaymentApiResponse || !$response->isSuccess())) { $this->logger->error('Heidelpay: Initial request did not succeed.'); throw new \RuntimeException($this->escaper->escapeHtml($error_message)); } diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index 456a7c87ac4..c04e619f513 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -772,13 +772,14 @@ private function performAuthentication() } /** - * Function to provide additional formDate. + * Function to provide additional form data. * Should be overwritten by child classes if needed. * @param Response $response * @return array */ public function prepareAdditionalFormData(Response $response) { + return []; } /* diff --git a/PaymentMethods/HeidelpayIDealPaymentMethod.php b/PaymentMethods/HeidelpayIDealPaymentMethod.php index 59eb3a29e9a..a7dd3f4b84a 100644 --- a/PaymentMethods/HeidelpayIDealPaymentMethod.php +++ b/PaymentMethods/HeidelpayIDealPaymentMethod.php @@ -82,9 +82,8 @@ public function __construct( } /** - * Provide necessary information for bank selection - * @param Response $response - * @return array + * @inheritdoc + * Prepare necessary information for bank selection */ public function prepareAdditionalFormData(Response $response) { diff --git a/view/frontend/web/js/view/payment/method-renderer/hgw-ideal.js b/view/frontend/web/js/view/payment/method-renderer/hgw-ideal.js index fb736edbe39..479d145e661 100644 --- a/view/frontend/web/js/view/payment/method-renderer/hgw-ideal.js +++ b/view/frontend/web/js/view/payment/method-renderer/hgw-ideal.js @@ -25,7 +25,6 @@ define( template: 'Heidelpay_Gateway/payment/heidelpay-ideal-form', hgwBankSelection: '', hgwBrandValues: [null], - hgwBrandNames: [null], hgwHolder: '' }, @@ -33,7 +32,7 @@ define( initObservable: function() { this._super() .observe([ - 'hgwBrandValues', 'hgwBrandNames', 'hgwBankSelection', 'hgwHolder' + 'hgwBrandValues', 'hgwBankSelection', 'hgwHolder' ]); return this; @@ -80,19 +79,21 @@ define( }).done(function (data) { var response = JSON.parse(data); + // set the iDeal brand information, which comes from the payment + if (response !== null) { + this.hgwBrandValues(response); + } - // set the iDeal brand information, which comes from the payment - if (response !== null) { - this.hgwBrandValues(response); - this.hgwBrandNames(response.brandNames); + return this; + }).fail(function (response) { + console.log('request failed: no banks available'); + }); + + }, + validate: function() { + var form = $('#hgw-ideal-form'); - return this; - } - return this; - }).fail(function (response) { - console.log('response fail: ' + response); - }); - //} + return form.validation() && form.validation('isValid'); } }); } From e7327d4aef4d4c7450e436590a93b3813ac850f2 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Fri, 28 Sep 2018 09:43:53 +0200 Subject: [PATCH 5/7] [feature](MAGE2-86) set version to 18.10.1 and update changelog as well as readme --- CHANGELOG.md | 5 +++++ README.md | 1 + etc/module.xml | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3086fe7989a..898e569333f 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ This project does not follow a versioning standard. Versions are crafted after the dates; for example, the version 17.7.25 was released on July, 25th in 2017 +## 18.10.1 + +### Added +- payment method iDeal + ## 18.9.20 ### Fixed diff --git a/README.md b/README.md index 17d16eb49e3..035d57653ca 100755 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Currently supported payment methods are: * Invoice * Invoice (Secured) (B2C) * giropay +* iDeal For more information please visit -http://dev.heidelpay.com/magento2/ diff --git a/etc/module.xml b/etc/module.xml index 74a43f66307..6aa82f855a0 100755 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,5 +1,5 @@ - + From c472c980001b771efff2671cc128ff3943ea1940 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 1 Oct 2018 14:53:54 +0200 Subject: [PATCH 6/7] [feature](MAGE2-86) set correct header for new files. --- Controller/Index/InitializePayment.php | 6 +++--- Gateway/Config/HgwIDealPaymentConfig.php | 14 +++++++++---- .../Config/HgwIDealPaymentConfigInterface.php | 14 +++++++++---- .../HeidelpayIDealPaymentMethod.php | 20 +++++++++++++------ .../payment/heidelpay-ideal-form.html | 6 ++++++ 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/Controller/Index/InitializePayment.php b/Controller/Index/InitializePayment.php index b505d52a4aa..69969ceb3ba 100644 --- a/Controller/Index/InitializePayment.php +++ b/Controller/Index/InitializePayment.php @@ -3,9 +3,9 @@ * This controller calls the initialization transaction if existing and necessary for the selected payment method. * * @license Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. - * @copyright Copyright © 2016-present Heidelberger Payment GmbH. All rights reserved. - * @link https://dev.heidelpay.de/magento - * @author Simon Gabriel + * @copyright Copyright © 2016-present heidelpay GmbH. All rights reserved. + * @link https://dev.heidelpay.de/magento2 + * @author David Owusu * * @package heidelpay * @subpackage magento2 diff --git a/Gateway/Config/HgwIDealPaymentConfig.php b/Gateway/Config/HgwIDealPaymentConfig.php index 535ea2e271b..bea0a70dc84 100644 --- a/Gateway/Config/HgwIDealPaymentConfig.php +++ b/Gateway/Config/HgwIDealPaymentConfig.php @@ -1,9 +1,15 @@ + * + * @package heidelpay/magento2 */ namespace Heidelpay\Gateway\Gateway\Config; diff --git a/Gateway/Config/HgwIDealPaymentConfigInterface.php b/Gateway/Config/HgwIDealPaymentConfigInterface.php index 97df32e77cb..189a2fccccd 100644 --- a/Gateway/Config/HgwIDealPaymentConfigInterface.php +++ b/Gateway/Config/HgwIDealPaymentConfigInterface.php @@ -1,9 +1,15 @@ + * + * @package heidelpay/magento2 */ namespace Heidelpay\Gateway\Gateway\Config; diff --git a/PaymentMethods/HeidelpayIDealPaymentMethod.php b/PaymentMethods/HeidelpayIDealPaymentMethod.php index a7dd3f4b84a..0aca305512a 100644 --- a/PaymentMethods/HeidelpayIDealPaymentMethod.php +++ b/PaymentMethods/HeidelpayIDealPaymentMethod.php @@ -1,10 +1,4 @@
Date: Mon, 1 Oct 2018 15:17:02 +0200 Subject: [PATCH 7/7] [feature](MAGE2-86) Add a german translation. Add a log if brand list is empty. remove redundancy. --- PaymentMethods/HeidelpayAbstractPaymentMethod.php | 4 +--- PaymentMethods/HeidelpayIDealPaymentMethod.php | 4 ++++ i18n/de_DE.csv | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/PaymentMethods/HeidelpayAbstractPaymentMethod.php b/PaymentMethods/HeidelpayAbstractPaymentMethod.php index c04e619f513..68476c3dc37 100755 --- a/PaymentMethods/HeidelpayAbstractPaymentMethod.php +++ b/PaymentMethods/HeidelpayAbstractPaymentMethod.php @@ -469,9 +469,7 @@ public function refund(\Magento\Payment\Model\InfoInterface $payment, $amount) */ public function getHeidelpayUrl($quote) { - $this->performAuthentication(); - - $this->setAsync(); + $this->setupInitialRequest(); $user = $this->getUser($quote); $this->_heidelpayPaymentMethod->getRequest()->customerAddress( diff --git a/PaymentMethods/HeidelpayIDealPaymentMethod.php b/PaymentMethods/HeidelpayIDealPaymentMethod.php index 0aca305512a..1ac63533dce 100644 --- a/PaymentMethods/HeidelpayIDealPaymentMethod.php +++ b/PaymentMethods/HeidelpayIDealPaymentMethod.php @@ -109,6 +109,10 @@ public function prepareAdditionalFormData(Response $response) $bankList[] = $bank; } + if (empty($bankList)) { + $this->_logger->warning('heidelpay - iDeal config: brand list is empty'); + } + return $bankList; } diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv index 66b4c4ded66..069e8eb9125 100755 --- a/i18n/de_DE.csv +++ b/i18n/de_DE.csv @@ -48,6 +48,7 @@ "IBAN", "IBAN" "BIC","BIC" "Bank Account Holder", "Kontoinhaber" +"Bank", "Bank" "Account Holder","Kontoinhaber" "Salutation", "Anrede" "Mr.", "Herr"