Skip to content

Commit

Permalink
Merge branch 'hotfix/1.14.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nabil Berhouche committed Apr 1, 2021
2 parents 61d11a5 + 99e8211 commit 2cb3fe7
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 119 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.14.1, 2021-04-01:
- Bug fix: Do not refund payments when vouchers are genereated in PrestShop 1.6.x.
- Bug fix: Do not save payments with negative amount in PrestaShop 1.7.7.x.
- Update 3DS management option description.
- Improve REST API keys configuration display.
- Possibility to disable web services for order operations in PrestaShop Back Office.

1.14.0, 2021-03-03:
- Bug fix: Update order status after multiple payment tries or on cancellation from gateway Back Office.
- [franfinance] Added new FranFinance submodule.
Expand Down
3 changes: 2 additions & 1 deletion payzen/classes/PayzenTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class PayzenTools

private static $CMS_IDENTIFIER = 'PrestaShop_1.5-1.7';
private static $SUPPORT_EMAIL = '[email protected]';
private static $PLUGIN_VERSION = '1.14.0';
private static $PLUGIN_VERSION = '1.14.1';
private static $GATEWAY_VERSION = 'V2';

const ORDER_ID_REGEX = '#^[a-zA-Z0-9]{1,9}$#';
Expand Down Expand Up @@ -242,6 +242,7 @@ public static function getAdminParameters()

array('key' => 'PAYZEN_PRIVKEY_TEST', 'default' => '', 'label' => 'Test password'),
array('key' => 'PAYZEN_PRIVKEY_PROD', 'default' => '', 'label' => 'Production password'),
array('key' => 'PAYZEN_ENABLE_WS', 'default' => 'disabled', 'label' => 'Enable web services'),
array('key' => 'PAYZEN_PUBKEY_TEST', 'default' => '', 'label' => 'Public test key'),
array('key' => 'PAYZEN_PUBKEY_PROD', 'default' => '', 'label' => 'Public production key'),
array('key' => 'PAYZEN_RETKEY_TEST', 'default' => '', 'label' => 'SHA256 test key'),
Expand Down
1 change: 1 addition & 0 deletions payzen/classes/admin/PayzenHelperForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ public static function getAdminFormContext()

'PAYZEN_PUBKEY_TEST' => Configuration::get('PAYZEN_PUBKEY_TEST'),
'PAYZEN_PRIVKEY_TEST' => Configuration::get('PAYZEN_PRIVKEY_TEST'),
'PAYZEN_ENABLE_WS' => Configuration::get('PAYZEN_ENABLE_WS'),
'PAYZEN_PUBKEY_PROD' => Configuration::get('PAYZEN_PUBKEY_PROD'),
'PAYZEN_PRIVKEY_PROD' => Configuration::get('PAYZEN_PRIVKEY_PROD'),
'PAYZEN_RETKEY_TEST' => Configuration::get('PAYZEN_RETKEY_TEST'),
Expand Down
141 changes: 113 additions & 28 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.14.0';
$this->version = '1.14.1';
$this->author = 'Lyra Network';
$this->controllers = array('redirect', 'submit', 'rest', 'iframe');
$this->module_key = 'f3e5d07f72a9d27a5a09196d54b9648e';
Expand Down Expand Up @@ -136,18 +136,23 @@ public function install()

// Set default values.
foreach ($admin_config_params as $param) {
if (! defined('PAYZEN_MODULE_UPGRADE') || ! in_array($param['key'], $already_installed_params)) {
if (in_array($param['key'], PayzenTools::$multi_lang_fields)) {
$key = $param['key'];

if (! defined('PAYZEN_MODULE_UPGRADE') || ! in_array($key, $already_installed_params)) {
if (in_array($key, PayzenTools::$multi_lang_fields)) {
$default = PayzenTools::convertIsoArrayToIdArray($param['default']);
} elseif (is_array($param['default'])) {
$default = serialize($param['default']);
} elseif (defined('PAYZEN_TRANSIENT_DEFAULT')) {
$defaults = unserialize(PAYZEN_TRANSIENT_DEFAULT);
$default = isset($defaults[$key]) ? $defaults[$key] : $param['default'];
} else {
$default = $param['default'];
}

if (! Configuration::updateValue($param['key'], $default, false, false, false)) {
$this->logger->logWarning("Error while saving default value for field {$param['key']}.");
$this->_errors[] = sprintf($this->l('Error while saving default value for field « %s ».'), $param['key']);
if (! Configuration::updateValue($key, $default, false, false, false)) {
$this->logger->logWarning("Error while saving default value for field {$key}.");
$this->_errors[] = sprintf($this->l('Error while saving default value for field « %s ».'), $key);

$installError = true;
}
Expand Down Expand Up @@ -469,7 +474,7 @@ private function postProcess()
foreach (PayzenTools::getAdminParameters() as $param) {
$key = $param['key']; // PrestaShop parameter key.

if (! Tools::getIsset($key)) {
if (! Tools::getIsset($key) && $key !== 'PAYZEN_ENABLE_WS') {
// If field is disabled, don't save it.
continue;
}
Expand All @@ -478,7 +483,10 @@ private function postProcess()
$name = isset($param['name']) ? $param['name'] : null; // Gateway API parameter name.

$value = Tools::getValue($key, null);
if ($value === '') { // Consider empty strings as null.

if ($key === 'PAYZEN_ENABLE_WS') {
$value = $value ? $value : 'disabled';
} elseif ($value === '') { // Consider empty strings as null.
$value = null;
}

Expand Down Expand Up @@ -1623,13 +1631,18 @@ public function hookAdminOrder($params)
*/
public function hookActionOrderStatusUpdate($params)
{
// It is an IPN, no online refund.
if (PayzenTools::checkFormIpnValidity() || PayzenTools::checkRestIpnValidity()) {
$order = new Order((int) $params['id_order']);
if (! $this->active || ($order->module != $this->name)) {
return;
}

$order = new Order((int) $params['id_order']);
if (! $this->active || ($order->module != $this->name)) {
// WS disabled in plugin configuration, no online refund.
if (Configuration::get('PAYZEN_ENABLE_WS') === 'disabled') {
return;
}

// It is an IPN, no online refund.
if (PayzenTools::checkFormIpnValidity() || PayzenTools::checkRestIpnValidity()) {
return;
}

Expand All @@ -1649,7 +1662,26 @@ public function hookActionOrderStatusUpdate($params)

// If any error during WS refund/cancel redirect to order details to avoid display success message.
if (! $this->refund($order, $order->total_paid_real)) {
Tools::redirectAdmin(AdminController::$currentIndex . '&id_order=' . $order->id . '&vieworder&token=' . Tools::getValue('token'));
if (Tools::isSubmit('token')) {
// PrestaShop versions < 1.7.7.0.
Tools::redirectAdmin(AdminController::$currentIndex . '&id_order=' . $order->id . '&vieworder&token=' . Tools::getValue('token'));
} else {
// Display warning to customer if any for PrestaShop versions >= 1.7.7.0.
if (isset($this->context->cookie->payzenRefundWarn)) {
$this->get('session')->getFlashBag()->set('warning', $this->context->cookie->payzenRefundWarn);
unset($this->context->cookie->payzenRefundWarn);
}

// PrestaShop versions >= 1.7.7.0.
$url_admin_orders = $this->context->link->getAdminLink('AdminOrders');
$url_admin_order = str_replace('/?_token=', '/' . $order->id . '/view?_token=', $url_admin_orders);

Tools::redirectAdmin($url_admin_order);
}
} elseif (! Tools::isSubmit('token') && isset($this->context->cookie->payzenRefundWarn)) {
// Display warning to customer if any for Prestashop versions >= 1.7.7.0.
$this->get('session')->getFlashBag()->set('warning', $this->context->cookie->payzenRefundWarn);
unset($this->context->cookie->payzenRefundWarn);
}

return true;
Expand All @@ -1667,6 +1699,11 @@ public function hookActionOrderStatusPostUpdate($params)
return;
}

// WS disabled in plugin configuration, no online refund.
if (Configuration::get('PAYZEN_ENABLE_WS') === 'disabled') {
return;
}

// If it is manual update of order state to refunded, update order total paid real to 0.
if (isset($this->context->cookie->payzenManualUpdateToManagedRefundStatuses)
&& ($this->context->cookie->payzenManualUpdateToManagedRefundStatuses === 'True')) {
Expand All @@ -1693,33 +1730,69 @@ public function hookActionObjectOrderSlipAddBefore($orderSlip)
return;
}

// WS disabled in plugin configuration, no online refund.
if (Configuration::get('PAYZEN_ENABLE_WS') === 'disabled') {
return;
}

// Stop the refund if the merchant want to generate a discount.
if (Tools::isSubmit('generateDiscount')) {
// If in POST we receive generateDiscount OR generateDiscountRefund for versions < 1.7.7.0.
// If in POST we receive cancel_product['voucher'] for versions >= 1.7.7.0.
if (Tools::isSubmit('generateDiscount') // PrestaShop >= 1.7.7.0
|| Tools::isSubmit('generateDiscountRefund') // PrestaShop < 1.7.7.0
|| (($cancel_product = Tools::getValue('cancel_product')) && isset($cancel_product['voucher']))) {
return;
}

// Get amount from OrderSlip, for now it's a workaround instead of use OrderSlip->amount for a bug in prestashop calculation.
$amount = ! Tools::getValue('TaxMethod') ? $orderSlipObject->total_products_tax_excl : $orderSlipObject->total_products_tax_incl;
// Get amount from OrderSlip.
$amount = $orderSlipObject->amount;
if (Tools::isSubmit('TaxMethod')) {
// Prestashop versions < 1.7.7.0.
// For now it's a workaround instead of use OrderSlip->amount for a bug in prestashop calculation.
$amount = ! Tools::getValue('TaxMethod') ? $orderSlipObject->total_products_tax_excl : $orderSlipObject->total_products_tax_incl;
}

// Add shipping cost amount.
$amount += $orderSlipObject->shipping_cost_amount;

// If any error during WS refund redirect to order details to avoid creation of a credit and displaying success message.
// If any error during WS refund, redirect to order details to avoid creation of a credit and displaying success message.
if (! $this->refund($order, $amount)) {
// No refund, so get back refunded products quantities, and available products stock quantities.
$id_order_details = Tools::isSubmit('generateCreditSlip') ? Tools::getValue('cancelQuantity')
: Tools::getValue('partialRefundProductQuantity');
foreach ($id_order_details as $id_order_detail => $quantity) {
// Update order detail.
$order_detail = new OrderDetail($id_order_detail);
$order_detail->product_quantity_refunded -= $quantity;
$order_detail->update();

// Update product available quantity.
StockAvailable::updateQuantity($order_detail->product_id, $order_detail->product_attribute_id, -$quantity, $order->id_shop);
if (is_array($id_order_details) && ! empty($id_order_details)) {
// Prestashop versions < 1.7.7.0.
foreach ($id_order_details as $id_order_detail => $quantity) {
// Update order detail.
$order_detail = new OrderDetail($id_order_detail);
$order_detail->product_quantity_refunded -= $quantity;
$order_detail->update();

// Update product available quantity.
StockAvailable::updateQuantity($order_detail->product_id, $order_detail->product_attribute_id, -$quantity, $order->id_shop);
}
}

Tools::redirectAdmin(AdminController::$currentIndex . '&id_order=' . $order_id . '&vieworder&token=' . Tools::getValue('token'));
if (Tools::isSubmit('token')) {
// Prestashop versions < 1.7.7.0.
Tools::redirectAdmin(AdminController::$currentIndex . '&id_order=' . $order->id . '&vieworder&token=' . Tools::getValue('token'));
} else {
// Display warning to customer if any for Prestashop versions >= 1.7.7.0.
if (isset($this->context->cookie->payzenRefundWarn)) {
$this->get('session')->getFlashBag()->set('warning', $this->context->cookie->payzenRefundWarn);
unset($this->context->cookie->payzenRefundWarn);
}

// Prestashop versions >= 1.7.7.0.
$url_admin_orders = $this->context->link->getAdminLink('AdminOrders');
$url_admin_order = str_replace('/?_token=', '/' . $order->id . '/view?_token=', $url_admin_orders);

Tools::redirectAdmin($url_admin_order);
}
} elseif (! Tools::isSubmit('token') && isset($this->context->cookie->payzenRefundWarn)) {
// Display warning to customer if any for Prestashop versions >= 1.7.7.0.
$this->get('session')->getFlashBag()->set('warning', $this->context->cookie->payzenRefundWarn);
unset($this->context->cookie->payzenRefundWarn);
}

return true;
Expand Down Expand Up @@ -2464,8 +2537,20 @@ public function savePayment($order, $response, $force_stop_payment_creation = fa
}

if ($response->get('operation_type') === 'CREDIT') {
// This is a refund, set transaction amount to negative.
$amount = $amount * -1;
if (version_compare(_PS_VERSION_, '1.7.7.0', '>=')) {
// Workarround for PrestaShop 1.7.7.x, payments with negative amounts not accepted.
$order->total_paid_real -= $amount;

if ($order->total_paid_real < 0) {
$order->total_paid_real = 0;
}

$order->update();
return;
} else {
// This is a refund, set transaction amount to negative.
$amount = $amount * -1;
}
}

$timestamp = strtotime($response->get('presentation_date').' UTC');
Expand Down
16 changes: 10 additions & 6 deletions payzen/translations/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,15 @@
$_MODULE['<{payzen}prestashop>back_office_d8353641f40a9ac55d076ea2785f2d60'] = 'Unter Multistore Modus, die URL Bestätigung ist die gleiche für alle Geschäfte.';
$_MODULE['<{payzen}prestashop>back_office_9deb4807a73db0f73c602248395ebca3'] = 'Plattform-URL';
$_MODULE['<{payzen}prestashop>back_office_81f1212295fb14103dc46d3be825b597'] = 'Link zur Bezahlungsplattform.';
$_MODULE['<{payzen}prestashop>back_office_e439dbf7038faf7b0d2ba9bd7c64c288'] = ' SCHLÛSSEL';
$_MODULE['<{payzen}prestashop>back_office_572e6a060b94065a102dfd32e0732e99'] = 'Configure this section if you are using order operations from PrestaShop backend or if you are using « Embedded payment fields » mode.';
$_MODULE['<{payzen}prestashop>back_office_4fd8968c92494e97456ff9c36c21075b'] = ' keys are available in your PayZen Back Office (menu: Settings > Shops > keys).';
$_MODULE['<{payzen}prestashop>back_office_e439dbf7038faf7b0d2ba9bd7c64c288'] = 'REST API SCHLÛSSEL';
$_MODULE['<{payzen}prestashop>back_office_e0762730de91a2e9b7f475c02e19531f'] = 'Configure this section if you are using order operations from PrestaShop Back Office or if you are using embedded payment fields or popin modes.';
$_MODULE['<{payzen}prestashop>back_office_4fd8968c92494e97456ff9c36c21075b'] = 'REST API keys are available in your PayZen Back Office (menu: Settings > Shops > keys).';
$_MODULE['<{payzen}prestashop>back_office_ffe24c9204d65518429aa701f3a6bdc5'] = 'Testpasswort';
$_MODULE['<{payzen}prestashop>back_office_3bc58e8a715eb613362ea9c0928fdaef'] = 'Passwort Produktion';
$_MODULE['<{payzen}prestashop>back_office_57d1e443b33b8a3b97a8c5b08252bd7c'] = 'Enable web services';
$_MODULE['<{payzen}prestashop>back_office_8b8d88e1d028c9cee5d472e4e413ae4f'] = 'Enable web services for order operations from PrestaShop Back Office.';
$_MODULE['<{payzen}prestashop>back_office_220e711410bd180a73217043ee0d2fbe'] = 'If you keep the box unchecked, you will have to intervene directly on PayZen Back Office to manage these operations.';
$_MODULE['<{payzen}prestashop>back_office_ab7f5b3b1e4f151e6ff0c8a26f5a425c'] = 'Configure this section only if you are using embedded payment fields or popin mode.';
$_MODULE['<{payzen}prestashop>back_office_37bbf3ceb28155bbb59f260fb3e33174'] = 'Öffentlicher Schlüssel (Test)';
$_MODULE['<{payzen}prestashop>back_office_57bf638e4efbe98ed21368e1743f1c36'] = 'Öffentlicher Produktionsschlüssel';
$_MODULE['<{payzen}prestashop>back_office_20fc8a7c61c03bf03d45b1365928060d'] = 'Schlüssel HMAC-SHA-256 für Test';
Expand All @@ -229,9 +233,9 @@
$_MODULE['<{payzen}prestashop>back_office_308f0485502f1aa7f578790e9eec965d'] = 'Shopbezeichnung zur Anzeige auf der Zahlungsseite. Feld leer lassen, um Schnittstellenkonfiguration zu verwenden.';
$_MODULE['<{payzen}prestashop>back_office_37d00f4554dc3c0baeb34a9c22d787d9'] = 'Shop-URL';
$_MODULE['<{payzen}prestashop>back_office_b1ca847217866d6307aa21c8f1c1195c'] = 'Shop-URL zur Anzeige auf der Zahlungsseite. Feld leer lassen, um Schnittstellenkonfiguration zu verwenden.';
$_MODULE['<{payzen}prestashop>back_office_bf261894e1e1e3e798d4b636696e6662'] = 'SELEKTIVES 3DS';
$_MODULE['<{payzen}prestashop>back_office_9a65ef2ca0613ac0ec960d288bb5d86a'] = '3DS nach Kundengruppe deaktivieren';
$_MODULE['<{payzen}prestashop>back_office_56a1c847e333a58a7df6bdd970f6916c'] = 'Betrag, unter dem 3DS für jede Kundengruppe deaktiviert wird. Muss für die Option Selektives 3DS freigeschaltet sein. Weitere Informationen finden Sie in der Moduldokumentation.';
$_MODULE['<{payzen}prestashop>back_office_c5e4a364a24d4f29af7654a2e982506a'] = 'CUSTOM 3DS';
$_MODULE['<{payzen}prestashop>back_office_a7439f063e2478cce5954b8f5d10d273'] = 'Manage 3DS by customer group';
$_MODULE['<{payzen}prestashop>back_office_fd3370f13644db0dcd1a1b4eb0573220'] = 'Amount by customer group below which customer could be exempt from strong authentication. Needs subscription to « Selective 3DS1 » or « Frictionless 3DS2 » options. For more information, refer to the module documentation.';
$_MODULE['<{payzen}prestashop>back_office_8e0b19a82842dddd5b4bbf435017d611'] = 'ZURÜCK ZUM SHOP';
$_MODULE['<{payzen}prestashop>back_office_aadb7680e9cf237017cd8b67f6c73260'] = 'Automatische Weiterleitung';
$_MODULE['<{payzen}prestashop>back_office_fc89f4bc15ae48552928b1a7ca71d2f7'] = 'Ist diese Einstellung aktiviert, wird der Kunde am Ende des Bezahlvorgangs automatisch auf Ihre Seite weitergeleitet.';
Expand Down
Loading

0 comments on commit 2cb3fe7

Please sign in to comment.