Skip to content

Commit

Permalink
[Feat] Refactor config form
Browse files Browse the repository at this point in the history
* Unify config var
* Separate form validation
* Add class to create the webhooks
* Remove unnecessary validations
* Remove duplicate code
  • Loading branch information
ElvisHeredia committed Apr 26, 2023
1 parent 078e1f8 commit 62b4d3b
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 294 deletions.
3 changes: 2 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@
'single_line' => true,
'space_before_parenthesis' => true,
'inline_constructor_arguments' => true
]
],
'ordered_imports' => ['sort_algorithm' => 'alpha']

//'not_operator_with_successor_space' => false,
//'no_superfluous_elseif' => true,
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
[Full Changelog](https://github.com/conekta/conekta_prestashop/compare/2.3.5...2.3.6)
- Add MSI feature by @ElvisHeredia [#115](https://github.com/conekta/conekta_prestashop/pull/115)
- Fix Coding standards to get approval from Prestashop Validator by @ElvisHeredia [#116](https://github.com/conekta/conekta_prestashop/pull/116)

- Unify config var by @ElvisHeredia [#117](https://github.com/conekta/conekta_prestashop/pull/117)
- Separate form validation by @ElvisHeredia [#117](https://github.com/conekta/conekta_prestashop/pull/117)
- Add class to create the webhooks by @ElvisHeredia [#117](https://github.com/conekta/conekta_prestashop/pull/117)
- Remove unnecessary validations by @ElvisHeredia [#117](https://github.com/conekta/conekta_prestashop/pull/117)
- Remove duplicate code by @ElvisHeredia [#117](https://github.com/conekta/conekta_prestashop/pull/117)

## [v2.3.5] - 2022-11-04
[Full Changelog](https://github.com/conekta/conekta_prestashop/compare/2.3.4...2.3.5)
Expand Down
164 changes: 52 additions & 112 deletions conekta.php

Large diffs are not rendered by default.

28 changes: 25 additions & 3 deletions controllers/front/notifications.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
<?php

/**
* NOTICE OF LICENSE
* Title : Conekta Card Payment Gateway for Prestashop
* Author : Conekta.io
* URL : https://www.conekta.io/es/docs/plugins/prestashop.
* PHP Version 7.0.0
* Conekta File Doc Comment
*
* @author Conekta <[email protected]>
* @copyright 2012-2023 Conekta
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
* @category Conekta
*
* @version GIT: @2.3.6@
*
* @see https://conekta.com/
*/
require_once dirname(__FILE__) . '/../../model/Database.php';
class ConektaNotificationsModuleFrontController extends ModuleFrontController
{
public const ORDER_CANCELED = 6;

public const ORDER_REFUNDED = 7;

public $auth = false;

public $ajax;
Expand Down Expand Up @@ -99,7 +121,7 @@ private function orderCanceled($orderID)
{
Db::getInstance()->Execute(
'UPDATE ' . _DB_PREFIX_
. 'orders SET current_state = ' . ORDER_CANCELED . ' WHERE id_order = '
. 'orders SET current_state = ' . self::ORDER_CANCELED . ' WHERE id_order = '
. pSQL($orderID)
);
}
Expand All @@ -113,7 +135,7 @@ private function orderRefunded($orderID)
{
Db::getInstance()->Execute(
'UPDATE ' . _DB_PREFIX_
. 'orders SET current_state = ' . ORDER_REFUNDED . ' WHERE id_order = '
. 'orders SET current_state = ' . self::ORDER_REFUNDED . ' WHERE id_order = '
. pSQL($orderID)
);
}
Expand Down
172 changes: 0 additions & 172 deletions notification.php

This file was deleted.

30 changes: 26 additions & 4 deletions src/UseCases/CreateWebhook.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?php
/**
* NOTICE OF LICENSE
* Title : Conekta Card Payment Gateway for Prestashop
* Author : Conekta.io
* URL : https://www.conekta.io/es/docs/plugins/prestashop.
* PHP Version 7.0.0
* Conekta File Doc Comment
*
* @author Conekta <[email protected]>
* @copyright 2012-2023 Conekta
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
* @category Conekta
*
* @version GIT: @2.3.6@
*
* @see https://conekta.com/
*/

namespace Conekta\Payments\UseCases;

Expand All @@ -21,8 +39,13 @@ class CreateWebhook

public const MaxFailedAttempts = 5;

public function __invoke(string $privateKey, string $isoCode, string $pluginVersion, $conektaMode): bool
{
public function __invoke(
bool $conektaMode,
string $privateKey,
string $isoCode,
string $pluginVersion,
string $oldWebhook
): bool {
Conekta::setApiKey($privateKey);
Conekta::setPlugin('Prestashop');
Conekta::setApiVersion('2.0.0');
Expand All @@ -32,10 +55,9 @@ public function __invoke(string $privateKey, string $isoCode, string $pluginVers
$events = ['events' => ['order.paid', 'order.expired']];

$newWebhook = Tools::safeOutput(Tools::getValue(self::webhookSetting));
$oldWebhook = Tools::safeOutput(Configuration::get(self::webhookSetting));
Configuration::deleteByName(self::webhookErrorSetting);

if ($newWebhook === $oldWebhook) {
if ($oldWebhook === $newWebhook) {
return true;
}

Expand Down
18 changes: 18 additions & 0 deletions src/UseCases/ValidateAdminForm.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
<?php
/**
* NOTICE OF LICENSE
* Title : Conekta Card Payment Gateway for Prestashop
* Author : Conekta.io
* URL : https://www.conekta.io/es/docs/plugins/prestashop.
* PHP Version 7.0.0
* Conekta File Doc Comment
*
* @author Conekta <[email protected]>
* @copyright 2012-2023 Conekta
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
* @category Conekta
*
* @version GIT: @2.3.6@
*
* @see https://conekta.com/
*/

namespace Conekta\Payments\UseCases;

Expand Down
2 changes: 1 addition & 1 deletion views/js/tokenize.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ $(document).ready (function($) {
$form.append($('<input type="hidden" name="chargeId" id="chargeId" />').val((event.subscription) ? null : event.charge.id));
$form.append($('<input type="hidden" name="charge_currency" id="charge_currency" />').val((event.subscription) ? null : event.charge.currency));
$form.append($('<input type="hidden" name="charge_status" id="charge_status" />').val((event.subscription) ? event.subscription.status : event.charge.status));
$form.append($('<input type="hidden" name="payment_type" id="payment_type" />').val(event.charge.payment_method.type));
$form.append($('<input type="hidden" name="payment_type" id="payment_type" />').val(event.charge.paymentMethod.type));
$form.append($('<input type="hidden" name="createAt" id="createAt" />').val((event.subscription) ? event.subscription.created_at : null));
$form.append($('<input type="hidden" name="reference" id="reference" />').val((event.reference)? event.reference : null));
$form.append($('<input type="hidden" name="plan_id" id="plan_id" />').val((event.subscription)? event.subscription.plan_id : null));
Expand Down

0 comments on commit 62b4d3b

Please sign in to comment.