From 27e2ce480d4c3a66eb25e43b19bbe8b7fe46da87 Mon Sep 17 00:00:00 2001 From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com> Date: Mon, 1 May 2023 11:46:18 +0200 Subject: [PATCH 1/5] PLUG-1822 - Fix for graphql logos --- Model/Config.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Model/Config.php b/Model/Config.php index d1df6254..f3c1b88b 100755 --- a/Model/Config.php +++ b/Model/Config.php @@ -417,7 +417,12 @@ public function getIconUrl(string $methodCode) if (empty($brandId)) { $brandId = $this->brands[$methodCode]; } - return $this->resources->getViewFileUrl("Paynl_Payment::logos/" . $brandId . ".png"); + return $this->resources->getViewFileUrl( + "Paynl_Payment::logos/" . $brandId . ".png", + array( + 'area' => 'frontend' + ) + ); } /** @@ -426,7 +431,12 @@ public function getIconUrl(string $methodCode) */ public function getIconUrlIssuer(string $issuerId) { - return $this->resources->getViewFileUrl("Paynl_Payment::logos_issuers/qr-" . $issuerId . ".svg"); + return $this->resources->getViewFileUrl( + "Paynl_Payment::logos_issuers/qr-" . $issuerId . ".svg", + array( + 'area' => 'frontend' + ) + ); } /** From 1fc7dfc48edaa1d02f15d427fdc4f9d74a4b86ca Mon Sep 17 00:00:00 2001 From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com> Date: Wed, 3 May 2023 15:37:30 +0200 Subject: [PATCH 2/5] Fix logos not being send to graphql depending on settings --- Model/Paymentmethod/Ideal.php | 29 ++++++++++----- Model/Paymentmethod/Instore.php | 53 ++++++++++++++++++++++----- Model/Paymentmethod/PaymentMethod.php | 3 +- 3 files changed, 66 insertions(+), 19 deletions(-) diff --git a/Model/Paymentmethod/Ideal.php b/Model/Paymentmethod/Ideal.php index 87747195..4ac7eca0 100644 --- a/Model/Paymentmethod/Ideal.php +++ b/Model/Paymentmethod/Ideal.php @@ -2,20 +2,24 @@ namespace Paynl\Payment\Model\Paymentmethod; -use Paynl\Payment\Model\Config; - class Ideal extends PaymentMethod { - - const BANKSDISPLAYTYPE_DROPDOWN = 1; - const BANKSDISPLAYTYPE_LIST = 2; + public const BANKSDISPLAYTYPE_DROPDOWN = 1; + public const BANKSDISPLAYTYPE_LIST = 2; protected $_code = 'paynl_payment_ideal'; + /** + * @return integer + */ protected function getDefaultPaymentOptionId() { return 10; } + /** + * @param \Magento\Framework\DataObject $data + * @return object + */ public function assignData(\Magento\Framework\DataObject $data) { parent::assignData($data); @@ -32,15 +36,22 @@ public function assignData(\Magento\Framework\DataObject $data) return $this; } + /** + * @return integer + */ public function showPaymentOptions() { return $this->_scopeConfig->getValue('payment/' . $this->_code . '/bank_selection', 'store'); } - public function getPaymentOptions() + /** + * @param boolean $graphql + * @return array + */ + public function getPaymentOptions($graphql = false) { $show_banks = $this->_scopeConfig->getValue('payment/' . $this->_code . '/bank_selection', 'store'); - if (!$show_banks) { + if (!$show_banks && !$graphql) { return []; } @@ -59,11 +70,11 @@ public function getPaymentOptions() $banks = \Paynl\Paymentmethods::getBanks($this->getPaymentOptionId()); $cache->save(json_encode($banks), $cacheName); } - if ($this->showPaymentOptions() != self::BANKSDISPLAYTYPE_LIST) { + if ($this->showPaymentOptions() != self::BANKSDISPLAYTYPE_LIST && !$graphql) { array_unshift($banks, array( 'id' => '', 'name' => __('Choose your bank'), - 'visibleName' => __('Choose your bank') + 'visibleName' => __('Choose your bank'), )); } else { foreach ($banks as $key => $bank) { diff --git a/Model/Paymentmethod/Instore.php b/Model/Paymentmethod/Instore.php index 1504bc1e..eea057a6 100644 --- a/Model/Paymentmethod/Instore.php +++ b/Model/Paymentmethod/Instore.php @@ -3,7 +3,7 @@ namespace Paynl\Payment\Model\Paymentmethod; use Magento\Sales\Model\Order; -use \Paynl\Payment\Helper\PayHelper; +use Paynl\Payment\Helper\PayHelper; class Instore extends PaymentMethod { @@ -16,11 +16,19 @@ class Instore extends PaymentMethod */ protected $_formBlockType = \Paynl\Payment\Block\Form\Instore::class; + /** + * @return integer + */ protected function getDefaultPaymentOptionId() { return 1729; } + /** + * @param string $paymentAction + * @param string $stateObject + * @return void + */ public function initialize($paymentAction, $stateObject) { if ($paymentAction == 'order') { @@ -40,6 +48,11 @@ public function initialize($paymentAction, $stateObject) } } + /** + * @param Order $order + * @param boolean $fromAdmin + * @return string + */ public function startTransaction(Order $order, $fromAdmin = false) { $store = $order->getStore(); @@ -71,13 +84,13 @@ public function startTransaction(Order $order, $fromAdmin = false) } catch (\Exception $e) { payHelper::logCritical($e->getMessage(), [], $store); - if ($e->getCode() == 201) { + if ($e->getCode() == 201) { if ($fromAdmin) { throw new \Exception(__($e->getMessage())); } else { $this->messageManager->addNoticeMessage($e->getMessage()); } - } else { + } else { if ($fromAdmin) { throw new \Exception(__('Pin transaction could not be started')); } else { @@ -89,6 +102,10 @@ public function startTransaction(Order $order, $fromAdmin = false) return $url; } + /** + * @param \Magento\Framework\DataObject $data + * @return object + */ public function assignData(\Magento\Framework\DataObject $data) { parent::assignData($data); @@ -105,7 +122,11 @@ public function assignData(\Magento\Framework\DataObject $data) return $this; } - public function getPaymentOptions() + /** + * @param boolean $graphql + * @return array + */ + public function getPaymentOptions($graphql = false) { $cache = $this->getCache(); $store = $this->storeManager->getStore(); @@ -140,14 +161,19 @@ public function getPaymentOptions() return false; } } - array_unshift($terminalsArr, [ - 'id' => '', - 'name' => __('Choose the pin terminal'), - 'visibleName' => __('Choose the pin terminal') - ]); + if (!$graphql) { + array_unshift($terminalsArr, [ + 'id' => '', + 'name' => __('Choose the pin terminal'), + 'visibleName' => __('Choose the pin terminal'), + ]); + } return $terminalsArr; } + /** + * @return integer + */ public function hidePaymentOptions() { if (!empty($this->getDefaultPaymentOption()) && $this->getDefaultPaymentOption() != '0') { @@ -156,6 +182,9 @@ public function hidePaymentOptions() return 0; } + /** + * @return string + */ public function getDefaultPaymentOption() { return $this->_scopeConfig->getValue('payment/' . $this->_code . '/default_terminal', 'store'); @@ -173,6 +202,9 @@ private function getCache() return $cache; } + /** + * @return boolean + */ public function isCurrentIpValid() { $onlyAllowedIPs = $this->_scopeConfig->getValue('payment/' . $this->_code . '/exclusiveforipaddress', 'store'); @@ -184,6 +216,9 @@ public function isCurrentIpValid() return in_array($this->helper->getClientIp(), explode(",", $onlyAllowedIPs)); } + /** + * @return boolean + */ public function isCurrentAgentValid() { $specifiedUserAgent = $this->_scopeConfig->getValue('payment/' . $this->_code . '/exclusiveforuseragent', 'store'); diff --git a/Model/Paymentmethod/PaymentMethod.php b/Model/Paymentmethod/PaymentMethod.php index 10ca9b6a..77e25608 100644 --- a/Model/Paymentmethod/PaymentMethod.php +++ b/Model/Paymentmethod/PaymentMethod.php @@ -156,9 +156,10 @@ public function getInstructions() } /** + * @param boolean $graphql * @return array */ - public function getPaymentOptions() + public function getPaymentOptions($graphql = false) { return []; } From a155d10558ce959b6eb95063dadf2815be1fdcf7 Mon Sep 17 00:00:00 2001 From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com> Date: Fri, 12 May 2023 10:53:29 +0200 Subject: [PATCH 3/5] Make getPaymentOptions() always return payment options --- Model/Paymentmethod/Ideal.php | 21 +++-------- Model/Paymentmethod/Instore.php | 35 ++++++++----------- Model/Paymentmethod/PaymentMethod.php | 3 +- .../view/payment/method-renderer/default.js | 22 +++++++++--- 4 files changed, 37 insertions(+), 44 deletions(-) diff --git a/Model/Paymentmethod/Ideal.php b/Model/Paymentmethod/Ideal.php index 4ac7eca0..0cd98071 100644 --- a/Model/Paymentmethod/Ideal.php +++ b/Model/Paymentmethod/Ideal.php @@ -45,16 +45,10 @@ public function showPaymentOptions() } /** - * @param boolean $graphql * @return array */ - public function getPaymentOptions($graphql = false) + public function getPaymentOptions() { - $show_banks = $this->_scopeConfig->getValue('payment/' . $this->_code . '/bank_selection', 'store'); - if (!$show_banks && !$graphql) { - return []; - } - $cache = $this->getCache(); $store = $this->storeManager->getStore(); $storeId = $store->getId(); @@ -70,16 +64,9 @@ public function getPaymentOptions($graphql = false) $banks = \Paynl\Paymentmethods::getBanks($this->getPaymentOptionId()); $cache->save(json_encode($banks), $cacheName); } - if ($this->showPaymentOptions() != self::BANKSDISPLAYTYPE_LIST && !$graphql) { - array_unshift($banks, array( - 'id' => '', - 'name' => __('Choose your bank'), - 'visibleName' => __('Choose your bank'), - )); - } else { - foreach ($banks as $key => $bank) { - $banks[$key]['logo'] = $this->paynlConfig->getIconUrlIssuer($bank['id']); - } + + foreach ($banks as $key => $bank) { + $banks[$key]['logo'] = $this->paynlConfig->getIconUrlIssuer($bank['id']); } return $banks; diff --git a/Model/Paymentmethod/Instore.php b/Model/Paymentmethod/Instore.php index e25f8e40..3627d8a2 100644 --- a/Model/Paymentmethod/Instore.php +++ b/Model/Paymentmethod/Instore.php @@ -129,11 +129,23 @@ public function assignData(\Magento\Framework\DataObject $data) } /** - * @param boolean $graphql + * @return integer|mixed + */ + public function showPaymentOptions() + { + if (!empty($this->getDefaultPaymentOption()) && $this->getDefaultPaymentOption() != '0') { + if ($this->_scopeConfig->getValue('payment/' . $this->_code . '/hide_terminal_selection', 'store') == 1) { + return 0; + } + } + return 1; + } + + /** * @return array|false|mixed * @throws \Magento\Framework\Exception\NoSuchEntityException */ - public function getPaymentOptions($graphql = false) + public function getPaymentOptions() { $cache = $this->getCache(); $store = $this->storeManager->getStore(); @@ -168,27 +180,10 @@ public function getPaymentOptions($graphql = false) return false; } } - if (!$graphql) { - array_unshift($terminalsArr, [ - 'id' => '', - 'name' => __('Choose the pin terminal'), - 'visibleName' => __('Choose the pin terminal'), - ]); - } + return $terminalsArr; } - /** - * @return integer|mixed - */ - public function hidePaymentOptions() - { - if (!empty($this->getDefaultPaymentOption()) && $this->getDefaultPaymentOption() != '0') { - return $this->_scopeConfig->getValue('payment/' . $this->_code . '/hide_terminal_selection', 'store'); - } - return 0; - } - /** * @return mixed */ diff --git a/Model/Paymentmethod/PaymentMethod.php b/Model/Paymentmethod/PaymentMethod.php index fdc3be5d..6bbfc043 100644 --- a/Model/Paymentmethod/PaymentMethod.php +++ b/Model/Paymentmethod/PaymentMethod.php @@ -172,10 +172,9 @@ public function getInstructions() } /** - * @param boolean $graphql * @return array */ - public function getPaymentOptions($graphql = false) + public function getPaymentOptions() { return []; } diff --git a/view/frontend/web/js/view/payment/method-renderer/default.js b/view/frontend/web/js/view/payment/method-renderer/default.js index 53a743e1..d9a4dbf6 100755 --- a/view/frontend/web/js/view/payment/method-renderer/default.js +++ b/view/frontend/web/js/view/payment/method-renderer/default.js @@ -142,16 +142,28 @@ define( return (this.getDOB() > 0 && this.getKVK() > 0); }, showPaymentOptions: function () { - if (window.checkoutConfig.payment.hidepaymentoptions[this.item.method] == 1) { - return false; - } - return window.checkoutConfig.payment.paymentoptions[this.item.method].length > 0 && window.checkoutConfig.payment.showpaymentoptions[this.item.method] != 2; + return window.checkoutConfig.payment.paymentoptions[this.item.method].length > 0 && window.checkoutConfig.payment.showpaymentoptions[this.item.method] == 1; }, showPaymentOptionsList: function () { return window.checkoutConfig.payment.paymentoptions[this.item.method].length >= 1 && window.checkoutConfig.payment.showpaymentoptions[this.item.method] == 2; }, getPaymentOptions: function () { - return window.checkoutConfig.payment.paymentoptions[this.item.method]; + var paymentOptions = window.checkoutConfig.payment.paymentoptions[this.item.method]; + var message = null; + if (this.item.method == 'paynl_payment_ideal') { + message = $.mage.__('Choose your bank'); + } + if (this.item.method == 'paynl_payment_instore') { + message = $.mage.__('Choose the pin terminal'); + } + if(message && this.showPaymentOptions() === true){ + var firstArray = []; + firstArray['id'] = ''; + firstArray['name'] = message; + firstArray['visibleName'] = message; + paymentOptions.unshift(firstArray); + } + return paymentOptions; }, getPaymentOptionsList: function(){ if(!this.showPaymentOptionsList){ From b0cdd1554d78d1bc5d4c3853ce0aa54b3d131429 Mon Sep 17 00:00:00 2001 From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com> Date: Fri, 12 May 2023 10:56:28 +0200 Subject: [PATCH 4/5] Fix phplint --- Model/Paymentmethod/Instore.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/Paymentmethod/Instore.php b/Model/Paymentmethod/Instore.php index 3627d8a2..f21242a4 100644 --- a/Model/Paymentmethod/Instore.php +++ b/Model/Paymentmethod/Instore.php @@ -180,7 +180,7 @@ public function getPaymentOptions() return false; } } - + return $terminalsArr; } From 2b17ed79dea7380bacd7964243a34586b34f3bd8 Mon Sep 17 00:00:00 2001 From: kevinverschoor <61683999+kevinverschoor@users.noreply.github.com> Date: Fri, 12 May 2023 11:28:03 +0200 Subject: [PATCH 5/5] Autoformat & Change var name --- .../js/view/payment/method-renderer/default.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/view/frontend/web/js/view/payment/method-renderer/default.js b/view/frontend/web/js/view/payment/method-renderer/default.js index d9a4dbf6..31922392 100755 --- a/view/frontend/web/js/view/payment/method-renderer/default.js +++ b/view/frontend/web/js/view/payment/method-renderer/default.js @@ -151,17 +151,17 @@ define( var paymentOptions = window.checkoutConfig.payment.paymentoptions[this.item.method]; var message = null; if (this.item.method == 'paynl_payment_ideal') { - message = $.mage.__('Choose your bank'); - } + message = $.mage.__('Choose your bank'); + } if (this.item.method == 'paynl_payment_instore') { - message = $.mage.__('Choose the pin terminal'); + message = $.mage.__('Choose the pin terminal'); } - if(message && this.showPaymentOptions() === true){ - var firstArray = []; - firstArray['id'] = ''; - firstArray['name'] = message; - firstArray['visibleName'] = message; - paymentOptions.unshift(firstArray); + if (message && this.showPaymentOptions() === true) { + var paymentOption = []; + paymentOption['id'] = ''; + paymentOption['name'] = message; + paymentOption['visibleName'] = message; + paymentOptions.unshift(paymentOption); } return paymentOptions; },