From 3bd7b75ad008f7851fff68ecd156ef1abd2bd685 Mon Sep 17 00:00:00 2001 From: Jehyson Bustamante Date: Thu, 4 Apr 2024 11:59:25 -0500 Subject: [PATCH] =?UTF-8?q?Revisi=C3=B3n:=206=20-=20payment=20method=20mbw?= =?UTF-8?q?ay=20added?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - improve css with module: onepagecheckoutps --- monei.php | 53 ++++++++++++++++++++++++- src/Monei/Model/MoneiPaymentMethod.php | 13 +++++- src/Monei/Model/MoneiPaymentMethods.php | 2 + translations/ag.php | 2 + translations/es.php | 2 + translations/mx.php | 2 + upgrade/upgrade-1.1.5.php | 11 +++++ views/css/checkout_page.css | 4 ++ 8 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 upgrade/upgrade-1.1.5.php diff --git a/monei.php b/monei.php index 4016d7b..db4fda5 100644 --- a/monei.php +++ b/monei.php @@ -72,6 +72,7 @@ public function install() Configuration::updateValue('MONEI_ALLOW_COFIDIS', false); Configuration::updateValue('MONEI_ALLOW_KLARNA', false); Configuration::updateValue('MONEI_ALLOW_MULTIBANCO', false); + Configuration::updateValue('MONEI_ALLOW_MBWAY', false); // Status Configuration::updateValue('MONEI_STATUS_SUCCEEDED', Configuration::get('PS_OS_PAYMENT')); Configuration::updateValue('MONEI_STATUS_FAILED', Configuration::get('PS_OS_ERROR')); @@ -207,6 +208,7 @@ public function uninstall() Configuration::deleteByName('MONEI_ALLOW_COFIDIS'); Configuration::deleteByName('MONEI_ALLOW_KLARNA'); Configuration::deleteByName('MONEI_ALLOW_MULTIBANCO'); + Configuration::deleteByName('MONEI_ALLOW_MBWAY'); // Status Configuration::deleteByName('MONEI_STATUS_SUCCEEDED'); Configuration::deleteByName('MONEI_STATUS_FAILED'); @@ -322,6 +324,7 @@ protected function getConfigFormGatewaysValues() 'MONEI_ALLOW_COFIDIS' => Configuration::get('MONEI_ALLOW_COFIDIS', false), 'MONEI_ALLOW_KLARNA' => Configuration::get('MONEI_ALLOW_KLARNA', false), 'MONEI_ALLOW_MULTIBANCO' => Configuration::get('MONEI_ALLOW_MULTIBANCO', false), + 'MONEI_ALLOW_MBWAY' => Configuration::get('MONEI_ALLOW_MBWAY', false), ); } @@ -724,6 +727,26 @@ protected function getConfigFormGateways() ) ), ), + array( + 'type' => 'switch', + 'label' => $this->l('Allow MBWay'), + 'name' => 'MONEI_ALLOW_MBWAY', + 'is_bool' => true, + 'desc' => $this->l('Allow payments with MBWay.'), + 'hint' => $this->l('The payment must be active and configured on your MONEI Dashboard.'), + 'values' => array( + array( + 'id' => 'active_on', + 'value' => true, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'active_off', + 'value' => false, + 'label' => $this->l('Disabled') + ) + ), + ), ), 'submit' => array( 'title' => $this->l('Save'), @@ -970,9 +993,12 @@ public function checkCurrency($cart) */ private function getPaymentMethods($id_cart, $id_customer) { + $countryIsoCode = $this->context->country->iso_code; $addressInvoice = new Address($this->context->cart->id_address_invoice); - $countryInvoice = new Country($addressInvoice->id_country); - $countryIsoCode = $countryInvoice->iso_code; + if (Validate::isLoadedObject($addressInvoice)) { + $countryInvoice = new Country($addressInvoice->id_country); + $countryIsoCode = $countryInvoice->iso_code; + } $crypto = ServiceLocator::get('\\PrestaShop\\PrestaShop\\Core\\Crypto\\Hashing'); $transaction_id = $crypto->hash($id_cart . $id_customer, _COOKIE_KEY_); @@ -1235,6 +1261,29 @@ private function getPaymentMethods($id_cart, $id_customer) $payment_methods[] = $option; } + // MBWay + if (Configuration::get('MONEI_ALLOW_MBWAY') && $moneiPaymentMethod->isMBWayAvailable($countryIsoCode)) { + $link_create_payment = $this->context->link->getModuleLink($this->name, 'redirect', [ + 'method' => 'mbway', + 'transaction_id' => $transaction_id + ]); + + $paymentName = 'MB Way'; + if (!$moneiAccount->getAccountInformation()->isLiveMode()) { + $paymentName .= ' (' . $this->l('Test Mode') . ')'; + } + + $option = new \PrestaShop\PrestaShop\Core\Payment\PaymentOption(); + $option + ->setCallToActionText($paymentName) + ->setAdditionalInformation($template) + ->setLogo( + Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/views/img/payments/mbway.svg') + ) + ->setAction($link_create_payment); + $payment_methods[] = $option; + } + return $payment_methods; } diff --git a/src/Monei/Model/MoneiPaymentMethod.php b/src/Monei/Model/MoneiPaymentMethod.php index 3543a08..3df3a12 100644 --- a/src/Monei/Model/MoneiPaymentMethod.php +++ b/src/Monei/Model/MoneiPaymentMethod.php @@ -23,7 +23,8 @@ class MoneiPaymentMethod implements ModelInterface 'paypal' => 'paypal', 'cofidis' => 'cofidis', 'klarna' => 'klarna', - 'multibanco' => 'multibanco' + 'multibanco' => 'multibanco', + 'mbway' => 'mbway', ]; private $attribute_type = [ @@ -57,6 +58,7 @@ private function isPaymentMethodAllowedByIsoCode(string $paymentMethod, string $ case MoneiPaymentMethods::COFIDIS: return $isoCode === 'ES'; case MoneiPaymentMethods::MULTIBANCO: + case MoneiPaymentMethods::MBWAY: return $isoCode === 'PT'; case MoneiPaymentMethods::KLARNA: return in_array($isoCode, ['AT', 'BE', 'CH', 'DE', 'DK', 'ES', 'FI', 'FR', 'GB', 'IT', 'NL', 'NO', 'SE']); @@ -74,6 +76,15 @@ public function isMultibancoAvailable(string $isoCode): bool return false; } + public function isMBWayAvailable(string $isoCode): bool + { + if (in_array(MoneiPaymentMethods::MBWAY, $this->container)) { + return $this->isPaymentMethodAllowedByIsoCode(MoneiPaymentMethods::MBWAY, $isoCode); + } + + return false; + } + public function isBizumAvailable(string $isoCode): bool { if (in_array(MoneiPaymentMethods::BIZUM, $this->container)) { diff --git a/src/Monei/Model/MoneiPaymentMethods.php b/src/Monei/Model/MoneiPaymentMethods.php index 678eced..68c7b55 100644 --- a/src/Monei/Model/MoneiPaymentMethods.php +++ b/src/Monei/Model/MoneiPaymentMethods.php @@ -15,6 +15,7 @@ class MoneiPaymentMethods public const COFIDIS = 'cofidis'; public const KLARNA = 'klarna'; public const MULTIBANCO = 'multibanco'; + public const MBWAY = 'mbway'; /** * Gets allowable values of the enum @@ -32,6 +33,7 @@ public static function getAllowableEnumValues() self::COFIDIS, self::KLARNA, self::MULTIBANCO, + self::MBWAY, ]; } } diff --git a/translations/ag.php b/translations/ag.php index 76de32e..1848c9a 100644 --- a/translations/ag.php +++ b/translations/ag.php @@ -47,6 +47,8 @@ $_MODULE['<{monei}prestashop>monei_4fd7a878cd96e48fe4905e5bf1ab6bdc'] = 'Permite los pagos mediante Klarna'; $_MODULE['<{monei}prestashop>monei_ae7d4ec3f5431e177f9a23377026f8fb'] = 'Permite Multibanco'; $_MODULE['<{monei}prestashop>monei_bd1d60241f1f1f311d3a32269a7377e3'] = 'Permite los pagos mediante Multibanco'; +$_MODULE['<{monei}prestashop>monei_3183c05e14d3dffde5bf3b49c4c506c8'] = 'Permite MB Way'; +$_MODULE['<{monei}prestashop>monei_afb1c70183b543427739f73e196a8f44'] = 'Permite los pagos mediante MB Way'; $_MODULE['<{monei}prestashop>monei_5dc837808ce6d5f248b62ae205489a4a'] = 'Estado de Pedido'; $_MODULE['<{monei}prestashop>monei_ca626a4aa5d64c74c6a67fd048786057'] = 'Estado para pago pendiente'; $_MODULE['<{monei}prestashop>monei_07bb619bce377cb5d79252a8b8ddb023'] = 'Debes seleccionar aquí el estado para los pagos pendientes.'; diff --git a/translations/es.php b/translations/es.php index 76de32e..1848c9a 100644 --- a/translations/es.php +++ b/translations/es.php @@ -47,6 +47,8 @@ $_MODULE['<{monei}prestashop>monei_4fd7a878cd96e48fe4905e5bf1ab6bdc'] = 'Permite los pagos mediante Klarna'; $_MODULE['<{monei}prestashop>monei_ae7d4ec3f5431e177f9a23377026f8fb'] = 'Permite Multibanco'; $_MODULE['<{monei}prestashop>monei_bd1d60241f1f1f311d3a32269a7377e3'] = 'Permite los pagos mediante Multibanco'; +$_MODULE['<{monei}prestashop>monei_3183c05e14d3dffde5bf3b49c4c506c8'] = 'Permite MB Way'; +$_MODULE['<{monei}prestashop>monei_afb1c70183b543427739f73e196a8f44'] = 'Permite los pagos mediante MB Way'; $_MODULE['<{monei}prestashop>monei_5dc837808ce6d5f248b62ae205489a4a'] = 'Estado de Pedido'; $_MODULE['<{monei}prestashop>monei_ca626a4aa5d64c74c6a67fd048786057'] = 'Estado para pago pendiente'; $_MODULE['<{monei}prestashop>monei_07bb619bce377cb5d79252a8b8ddb023'] = 'Debes seleccionar aquí el estado para los pagos pendientes.'; diff --git a/translations/mx.php b/translations/mx.php index 76de32e..1848c9a 100644 --- a/translations/mx.php +++ b/translations/mx.php @@ -47,6 +47,8 @@ $_MODULE['<{monei}prestashop>monei_4fd7a878cd96e48fe4905e5bf1ab6bdc'] = 'Permite los pagos mediante Klarna'; $_MODULE['<{monei}prestashop>monei_ae7d4ec3f5431e177f9a23377026f8fb'] = 'Permite Multibanco'; $_MODULE['<{monei}prestashop>monei_bd1d60241f1f1f311d3a32269a7377e3'] = 'Permite los pagos mediante Multibanco'; +$_MODULE['<{monei}prestashop>monei_3183c05e14d3dffde5bf3b49c4c506c8'] = 'Permite MB Way'; +$_MODULE['<{monei}prestashop>monei_afb1c70183b543427739f73e196a8f44'] = 'Permite los pagos mediante MB Way'; $_MODULE['<{monei}prestashop>monei_5dc837808ce6d5f248b62ae205489a4a'] = 'Estado de Pedido'; $_MODULE['<{monei}prestashop>monei_ca626a4aa5d64c74c6a67fd048786057'] = 'Estado para pago pendiente'; $_MODULE['<{monei}prestashop>monei_07bb619bce377cb5d79252a8b8ddb023'] = 'Debes seleccionar aquí el estado para los pagos pendientes.'; diff --git a/upgrade/upgrade-1.1.5.php b/upgrade/upgrade-1.1.5.php new file mode 100644 index 0000000..d6286d4 --- /dev/null +++ b/upgrade/upgrade-1.1.5.php @@ -0,0 +1,11 @@ +