Skip to content

Commit

Permalink
Merge pull request #19 from payrexx/bugfix/PP-10834
Browse files Browse the repository at this point in the history
bugfix/PP-10834: Testing Our Actual Plugin Version With Our Prestashop Plugin
  • Loading branch information
michaelraess authored Jan 8, 2024
2 parents 3c486de + 5cb016f commit 76d3ab1
Show file tree
Hide file tree
Showing 14 changed files with 232 additions and 36 deletions.
13 changes: 13 additions & 0 deletions payrexx/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>payrexx</name>
<displayName><![CDATA[Payrexx]]></displayName>
<version><![CDATA[1.4.8]]></version>
<description><![CDATA[Accept payments using Payrexx Payment gateway]]></description>
<author><![CDATA[Payrexx]]></author>
<tab><![CDATA[payments_gateways]]></tab>
<confirmUninstall><![CDATA[Are you sure you want to uninstall?]]></confirmUninstall>
<is_configurable>1</is_configurable>
<need_instance>1</need_instance>
<limited_countries></limited_countries>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Payrexx Payment Gateway.
*
* @author Payrexx <[email protected]>
* @copyright 2023 Payrexx
* @copyright 2024 Payrexx
* @license MIT License
*/
include_once _PS_MODULE_DIR_ . 'payrexx/src/Models/PayrexxPaymentMethod.php';
Expand Down Expand Up @@ -40,7 +40,7 @@ public function __construct()

$paymentMethod = $this->loadObject(true);
foreach (['country', 'currency', 'customer_group'] as $fieldName) {
$this->fields_value[$fieldName . '[]'] = unserialize($paymentMethod->$fieldName);
$this->fields_value[$fieldName . '[]'] = json_decode($paymentMethod->$fieldName, true);
}
$configPaymentMethods = PayrexxConfig::getPaymentMethods();
$pageTitle = $this->l($configPaymentMethods[$paymentMethod->pm]);
Expand Down Expand Up @@ -89,7 +89,7 @@ public function __construct()
'desc' => 'Leave empty accepts payment for all currency',
'options' => [
'query' => Currency::getCurrencies(false, false),
'id' => 'id',
'id' => 'id_currency',
'name' => 'name',
],
],
Expand Down Expand Up @@ -126,8 +126,8 @@ public function __construct()
public function display()
{
// show saved messages
if ($this->context->cookie->__isset('redirect_errors') &&
$this->context->cookie->__get('redirect_errors') != '') {
if ($this->context->cookie->__isset('redirect_errors')
&& $this->context->cookie->__get('redirect_errors') != '') {
$this->errors = array_merge(
[
$this->context->cookie->__get('redirect_errors'),
Expand All @@ -152,14 +152,14 @@ public function postProcess()

// Country
$postCountry = !Tools::getIsset('country') ? [] : Tools::getValue('country');
$_POST['country'] = serialize($postCountry);
$_POST['country'] = json_encode($postCountry);

// currency
$postCurrency = !Tools::getIsset('currency') ? [] : Tools::getValue('currency');
$_POST['currency'] = serialize($postCurrency);
$_POST['currency'] = json_encode($postCurrency);

$postCustomerGroup = !Tools::getIsset('customer_group') ? [] : Tools::getValue('customer_group');
$_POST['customer_group'] = serialize($postCustomerGroup);
$_POST['customer_group'] = json_encode($postCustomerGroup);

parent::postProcess();
}
Expand Down
21 changes: 18 additions & 3 deletions payrexx/controllers/front/gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,26 @@
* @copyright 2023 Payrexx
* @license MIT License
*/
if (!defined('_PS_VERSION_')) {
exit;
}
use Payrexx\Models\Response\Transaction;
use Payrexx\PayrexxPaymentGateway\Config\PayrexxConfig;
use Payrexx\PayrexxPaymentGateway\Service\PayrexxApiService;
use Payrexx\PayrexxPaymentGateway\Service\PayrexxDbService;
use Payrexx\PayrexxPaymentGateway\Service\PayrexxOrderService;

class PayrexxGatewayModuleFrontController extends ModuleFrontController
{
public function initContent()
{
$payrexxOrderService = $this->get('payrexx.payrexxpaymentgateway.payrexxorderservice');
$payrexxDbService = $this->get('payrexx.payrexxpaymentgateway.payrexxdbservice');
if (version_compare(_PS_VERSION_, '1.7.6', '<')) {
$payrexxOrderService = new PayrexxOrderService();
$payrexxDbService = new PayrexxDbService();
} else {
$payrexxOrderService = $this->get('payrexx.payrexxpaymentgateway.payrexxorderservice');
$payrexxDbService = $this->get('payrexx.payrexxpaymentgateway.payrexxdbservice');
}

$transaction = Tools::getValue('transaction');
$cartId = $transaction['invoice']['referenceId'];
Expand Down Expand Up @@ -66,7 +77,11 @@ private function validRequest($transaction, $cartId, $requestStatus): bool
return false;
}

$payrexxApiService = $this->get('payrexx.payrexxpaymentgateway.payrexxapiservice');
if (version_compare(_PS_VERSION_, '1.7.6', '<')) {
$payrexxApiService = new PayrexxApiService();
} else {
$payrexxApiService = $this->get('payrexx.payrexxpaymentgateway.payrexxapiservice');
}
$gateway = $payrexxApiService->getPayrexxGateway((int) $transaction['invoice']['paymentRequestId']);

// Validate request by gateway ID
Expand Down
21 changes: 17 additions & 4 deletions payrexx/controllers/front/payrexx.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
* @copyright 2023 Payrexx
* @license MIT License
*/
if (!defined('_PS_VERSION_')) {
exit;
}

use Payrexx\PayrexxException;
use Payrexx\PayrexxPaymentGateway\Service\PayrexxApiService;
use Payrexx\PayrexxPaymentGateway\Service\PayrexxDbService;

class PayrexxPayrexxModuleFrontController extends ModuleFrontController
{
private $supportedLang = ['nl', 'fr', 'de', 'it', 'nl', 'pt', 'tr', 'pl', 'es', 'dk'];
Expand All @@ -15,8 +23,13 @@ public function postProcess()
{
try {
// Collect Gateway data
$payrexxDbService = $this->get('payrexx.payrexxpaymentgateway.payrexxdbservice');
$payrexxApiService = $this->get('payrexx.payrexxpaymentgateway.payrexxapiservice');
if (version_compare(_PS_VERSION_, '1.7.6', '<')) {
$payrexxDbService = new PayrexxDbService();
$payrexxApiService = new PayrexxApiService();
} else {
$payrexxDbService = $this->get('payrexx.payrexxpaymentgateway.payrexxdbservice');
$payrexxApiService = $this->get('payrexx.payrexxpaymentgateway.payrexxapiservice');
}
$context = Context::getContext();

$cart = $context->cart;
Expand Down Expand Up @@ -61,7 +74,7 @@ public function postProcess()
);

if (!$gateway) {
throw new \Payrexx\PayrexxException();
throw new PayrexxException();
}
$context->cookie->paymentId = $gateway->getId();
$payrexxDbService->insertGatewayInfo(
Expand All @@ -79,7 +92,7 @@ public function postProcess()
$gatewayUrl = str_replace('?', $lang . '/?', $link);

Tools::redirect($gatewayUrl);
} catch (\Payrexx\PayrexxException $e) {
} catch (PayrexxException $e) {
Tools::redirect(
Context::getContext()->link->getModuleLink(
$this->module->name,
Expand Down
12 changes: 10 additions & 2 deletions payrexx/controllers/front/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
* @copyright 2023 Payrexx
* @license MIT License
*/
if (!defined('_PS_VERSION_')) {
exit;
}
use Payrexx\PayrexxPaymentGateway\Service\PayrexxDbService;

class PayrexxValidationModuleFrontController extends ModuleFrontController
{
const ERROR_CONFIG = 'config';
Expand All @@ -24,8 +29,11 @@ public function initContent()
exit;
}

$payrexxDbService = $this->get('payrexx.payrexxpaymentgateway.payrexxdbservice');

if (version_compare(_PS_VERSION_, '1.7.6', '<')) {
$payrexxDbService = new PayrexxDbService();
} else {
$payrexxDbService = $this->get('payrexx.payrexxpaymentgateway.payrexxdbservice');
}
$gatewayId = $this->context->cookie->paymentId;
$cartId = $payrexxDbService->getGatewayCartId($gatewayId);

Expand Down
30 changes: 19 additions & 11 deletions payrexx/payrexx.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Payrexx Payment Gateway.
*
* @author Payrexx <[email protected]>
* @copyright 2023 Payrexx
* @copyright 2024 Payrexx
* @license MIT License
*/
if (!defined('_PS_VERSION_')) {
Expand All @@ -14,6 +14,13 @@
use Payrexx\PayrexxPaymentGateway\Service\PayrexxApiService;
use PrestaShop\PrestaShop\Core\Payment\PaymentOption;

if (!class_exists(PayrexxConfig::class)) {
$autoloadLocation = __DIR__ . '/vendor/autoload.php';
if (file_exists($autoloadLocation)) {
require_once $autoloadLocation;
}
}

class Payrexx extends PaymentModule
{
/**
Expand All @@ -24,7 +31,7 @@ public function __construct()
$this->name = 'payrexx';
$this->tab = 'payments_gateways';
$this->module_key = '0c4dbfccbd85dd948fd9a13d5a4add90';
$this->version = '1.4.7';
$this->version = '1.4.8';
$this->author = 'Payrexx';
$this->is_eu_compatible = 1;
$this->ps_versions_compliancy = ['min' => '1.7'];
Expand All @@ -44,10 +51,10 @@ public function __construct()
public function install()
{
// Install default
if (!parent::install() ||
!$this->installDb() ||
!$this->registerHook('paymentOptions') ||
!$this->registerHook('actionFrontControllerSetMedia')
if (!parent::install()
|| !$this->installDb()
|| !$this->registerHook('paymentOptions')
|| !$this->registerHook('actionFrontControllerSetMedia')
) {
return false;
}
Expand Down Expand Up @@ -329,6 +336,7 @@ public function hookPaymentOptions($params)
// Additional payment methods
$this->loadTranslationsInUi();
$action = $this->context->link->getModuleLink($this->name, 'payrexx');
$paymentMethods = [];
foreach ($this->getPaymentMethodsList(true) as $paymentMethod) {
if (!$this->allowedPaymentMethodToPay($paymentMethod)) {
continue;
Expand Down Expand Up @@ -373,17 +381,17 @@ public function hookPaymentOptions($params)
*/
public function allowedPaymentMethodToPay(array $paymentMethod): bool
{
$allowedCountries = unserialize($paymentMethod['country']);
$allowedCurrencies = unserialize($paymentMethod['currency']);
$allowedCustomerGroups = unserialize($paymentMethod['customer_group']);
$allowedCountries = json_decode($paymentMethod['country'], true);
$allowedCurrencies = json_decode($paymentMethod['currency'], true);
$allowedCustomerGroups = json_decode($paymentMethod['customer_group'], true);
if (!empty($allowedCountries) && !in_array($this->context->country->id, $allowedCountries)) {
return false;
}
if (!empty($allowedCurrencies) && !in_array($this->context->currency->id, $allowedCurrencies)) {
return false;
}
if (!empty($allowedCustomerGroups) &&
empty(array_intersect(
if (!empty($allowedCustomerGroups)
&& empty(array_intersect(
$this->context->customer->getGroups(),
$allowedCustomerGroups
))
Expand Down
9 changes: 6 additions & 3 deletions payrexx/sql/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* @copyright 2023 Payrexx
* @license MIT License
*/
if (!defined('_PS_VERSION_')) {
exit;
}
require_once _PS_MODULE_DIR_ . 'payrexx/src/Config/PayrexxConfig.php';

use Payrexx\PayrexxPaymentGateway\Config\PayrexxConfig;
Expand Down Expand Up @@ -61,9 +64,9 @@
$insertData = [
'active' => $paymentMethod == 'payrexx' ? 1 : 0,
'pm' => $paymentMethod,
'country' => serialize([]),
'currency' => serialize([]),
'customer_group' => serialize([]),
'country' => json_encode([]),
'currency' => json_encode([]),
'customer_group' => json_encode([]),
'position' => 0,
];
if (Db::getInstance()->insert('payrexx_payment_methods', $insertData) == false) {
Expand Down
3 changes: 3 additions & 0 deletions payrexx/sql/uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* @copyright 2023 Payrexx
* @license MIT License
*/
if (!defined('_PS_VERSION_')) {
exit;
}
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'payrexx_gateway`;';
$sql[] = 'DROP TABLE IF EXISTS `' . _DB_PREFIX_ . 'payrexx_payment_methods`;';

Expand Down
4 changes: 4 additions & 0 deletions payrexx/src/Config/PayrexxConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
*/
namespace Payrexx\PayrexxPaymentGateway\Config;

if (!defined('_PS_VERSION_')) {
exit;
}

class PayrexxConfig
{
/**
Expand Down
4 changes: 4 additions & 0 deletions payrexx/src/Models/PayrexxPaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* @copyright 2023 Payrexx
* @license MIT License
*/
if (!defined('_PS_VERSION_')) {
exit;
}

class PayrexxPaymentMethod extends ObjectModel
{
public $id;
Expand Down
16 changes: 11 additions & 5 deletions payrexx/src/Service/PayrexxApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@
* @copyright 2023 Payrexx
* @license MIT License
*/

namespace Payrexx\PayrexxPaymentGateway\Service;

if (!defined('_PS_VERSION_')) {
exit;
}

use Configuration;
use Payrexx\Models\Request\SignatureCheck;
use Payrexx\Models\Response\Gateway;
use Payrexx\Models\Response\Transaction;
use Payrexx\PayrexxException;

class PayrexxApiService
{
Expand Down Expand Up @@ -45,7 +51,7 @@ public function getPayrexxGateway($gatewayId): ?Gateway

try {
return $payrexx->getOne($gateway);
} catch (\Payrexx\PayrexxException $e) {
} catch (PayrexxException $e) {
}
return null;
}
Expand Down Expand Up @@ -84,7 +90,7 @@ public function getPayrexxTransaction($transactionId): ?Transaction

try {
return $payrexx->getOne($transaction);
} catch (\Payrexx\PayrexxException $e) {
} catch (PayrexxException $e) {
return null;
}
}
Expand Down Expand Up @@ -172,7 +178,7 @@ public function createPayrexxGateway(

try {
return $payrexx->create($gateway);
} catch (\Payrexx\PayrexxException $e) {
} catch (PayrexxException $e) {
}
return null;
}
Expand All @@ -186,7 +192,7 @@ public function deletePayrexxGateway($gatewayId)

try {
$payrexx->delete($gateway);
} catch (\Payrexx\PayrexxException $e) {
} catch (PayrexxException $e) {
}
}

Expand Down Expand Up @@ -217,7 +223,7 @@ public function validateSignature(string $instance, string $apiKey, string $plat
try {
$payrexx->getOne(new SignatureCheck());
return true;
} catch (\Payrexx\PayrexxException $e) {
} catch (PayrexxException $e) {
return false;
}
}
Expand Down
5 changes: 5 additions & 0 deletions payrexx/src/Service/PayrexxDbService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
* @copyright 2023 Payrexx
* @license MIT License
*/

namespace Payrexx\PayrexxPaymentGateway\Service;

use Db;

if (!defined('_PS_VERSION_')) {
exit;
}

class PayrexxDbService
{
/**
Expand Down
Loading

0 comments on commit 76d3ab1

Please sign in to comment.