From 48a033e012fe60889e4f009b364ee0b9e5197651 Mon Sep 17 00:00:00 2001 From: Nabil Berhouche Date: Tue, 6 Feb 2024 11:24:21 +0100 Subject: [PATCH] [BOT] Migrate hotfix 1.16.5 to GitHub. --- CHANGELOG.md | 3 ++ payzen/classes/PayzenTools.php | 2 +- payzen/payzen.php | 50 ++++++++++++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05d8adb..6560bf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/payzen/classes/PayzenTools.php b/payzen/classes/PayzenTools.php index b00b02d..6d0f1da 100644 --- a/payzen/classes/PayzenTools.php +++ b/payzen/classes/PayzenTools.php @@ -33,7 +33,7 @@ class PayzenTools private static $CMS_IDENTIFIER = 'PrestaShop_1.5-8.x'; private static $SUPPORT_EMAIL = 'support@payzen.eu'; - 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}$#'; diff --git a/payzen/payzen.php b/payzen/payzen.php index e8182c5..dfef28b 100644 --- a/payzen/payzen.php +++ b/payzen/payzen.php @@ -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'; @@ -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')) { @@ -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/'; @@ -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. *