Skip to content

Commit

Permalink
Merge branch 'hotfix/1.16.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
nberhouche committed Feb 6, 2024
2 parents 3318baf + 48a033e commit 97ab11a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.16.5, 2024-02-06:
- Bug fix: Fix payment in installments invoice for PrestaShop 1.7.x and higher.

1.16.4, 2024-01-25:
- Bug fix: ignore abandoned payments in IPN calls for already saved orders.
- Improve IPN errors management.
Expand Down
2 changes: 1 addition & 1 deletion payzen/classes/PayzenTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PayzenTools

private static $CMS_IDENTIFIER = 'PrestaShop_1.5-8.x';
private static $SUPPORT_EMAIL = '[email protected]';
private static $PLUGIN_VERSION = '1.16.4';
private static $PLUGIN_VERSION = '1.16.5';
private static $GATEWAY_VERSION = 'V2';

const ORDER_ID_REGEX = '#^[a-zA-Z0-9]{1,9}$#';
Expand Down
50 changes: 48 additions & 2 deletions payzen/payzen.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct()
{
$this->name = 'payzen';
$this->tab = 'payments_gateways';
$this->version = '1.16.4';
$this->version = '1.16.5';
$this->author = 'Lyra Network';
$this->controllers = array('redirect', 'submit', 'rest', 'iframe');
$this->module_key = 'f3e5d07f72a9d27a5a09196d54b9648e';
Expand Down Expand Up @@ -152,6 +152,15 @@ public function install()
$installError = true;
}

if (version_compare(_PS_VERSION_, '1.7', '>')) {
if (! $this->registerHook('actionEmailSendBefore')) {
$this->logger->logWarning('Hook « actionEmailSendBefore » could not be saved.');
$this->_errors[] = $this->l('One or more hooks necessary for the module could not be saved.');

$installError = true;
}
}

$admin_config_params = PayzenTools::getAdminParameters();

if (defined('PAYZEN_MODULE_UPGRADE')) {
Expand Down Expand Up @@ -1732,6 +1741,25 @@ public function hookDisplayAdminOrder($params)
return $this->displayRefundOnlineCheckbox(true) . $this->displaySupportContactFromOrderDetails($order);
}

public function hookActionEmailSendBefore(array $params)
{
$order = new Order((int) $params['templateVars']['{id_order}']);
if (! $this->active || ($order->module != $this->name)) {
return;
}

if (! isset($this->context->cookie->payzenActionEmailSend)) {
$this->logger->logInfo("Stop Order #{$order->id} payment email from being sent.");
$this->context->cookie->payzenActionEmailSend = true;
return false;
}

if ($params['template'] === 'payment') {
unset($this->context->cookie->payzenActionEmailSend);
return true;
}
}

private function displayRefundOnlineCheckbox($isBackwardCompatibility = false)
{
$template = _PS_MODULE_DIR_ . 'payzen/views/templates/admin/';
Expand Down Expand Up @@ -2150,10 +2178,28 @@ public function saveOrder($cart, $state, $response)
$this->savePayment($order, $response);
$this->saveIdentifier($customer, $response);

if (version_compare(_PS_VERSION_, '1.7', '>')) {
// Send email upon the update of the payment.
$order_history = new OrderHistory();
$order_history->id_order = (int) $order->id;
$order_history->id_order_state = $order->getCurrentState();
if (! $order_history->addWithemail(true)) {
$this->logger->logInfo("Failed to send email when updating payments for cart #{$cart->id}.");
}

// Delete double entry from history.
$result = Db::getInstance()->execute(
'DELETE FROM `' . _DB_PREFIX_ . 'order_history` WHERE `id_order` = ' . (int) $order->id . ' AND `id_order_state` = '
. (int) $order->getCurrentState() . ' ORDER BY `date_add` DESC LIMIT 1');

if (! $result) {
$this->logger->logWarning("An error occurred when deleting history for order #{$order->id}.");
}
}

return $order;
}


/**
* Update current order state.
*
Expand Down

0 comments on commit 97ab11a

Please sign in to comment.