Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

payment method mbway added #24

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions monei.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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),
);
}

Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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_);
Expand Down Expand Up @@ -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;
}

Expand Down
13 changes: 12 additions & 1 deletion src/Monei/Model/MoneiPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class MoneiPaymentMethod implements ModelInterface
'paypal' => 'paypal',
'cofidis' => 'cofidis',
'klarna' => 'klarna',
'multibanco' => 'multibanco'
'multibanco' => 'multibanco',
'mbway' => 'mbway',
];

private $attribute_type = [
Expand Down Expand Up @@ -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']);
Expand All @@ -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)) {
Expand Down
2 changes: 2 additions & 0 deletions src/Monei/Model/MoneiPaymentMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,6 +33,7 @@ public static function getAllowableEnumValues()
self::COFIDIS,
self::KLARNA,
self::MULTIBANCO,
self::MBWAY,
];
}
}
2 changes: 2 additions & 0 deletions translations/ag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down
2 changes: 2 additions & 0 deletions translations/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down
2 changes: 2 additions & 0 deletions translations/mx.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.';
Expand Down
11 changes: 11 additions & 0 deletions upgrade/upgrade-1.1.5.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
if (!defined('_PS_VERSION_')) {
exit;
}

function upgrade_module_1_1_5($module)
{
Configuration::updateValue('MONEI_ALLOW_MBWAY', false);

return true;
}
4 changes: 4 additions & 0 deletions views/css/checkout_page.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ section.checkout-step .payment-option img {
margin-left: 0.5rem;
}

#opc_step_payment .payment-option img {
width: 89px;
}

.monei-powered-by {
margin-bottom: 1rem;
}
Loading