diff --git a/CHANGELOG.md b/CHANGELOG.md index 53e8cf2..3c72169 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +2.0.7, 2023-04-26: +- Bug fix: Update order balance in case of online refund. +- Improve module documentation management field. + 2.0.6, 2023-01-04: - Consider IPN on operations from merchant Back Office. - Update list of supported payment means. diff --git a/commerce_payzen/commerce_payzen.info.yml b/commerce_payzen/commerce_payzen.info.yml index e25b784..c36eefd 100644 --- a/commerce_payzen/commerce_payzen.info.yml +++ b/commerce_payzen/commerce_payzen.info.yml @@ -6,7 +6,7 @@ dependencies: - commerce_payment # information about project -version: "8.x-9.x-2.0.6" +version: "8.x-9.x-2.0.7" core: "8.x" core_version_requirement: ^8 || ^9 project: "commerce_payzen" diff --git a/commerce_payzen/src/Includes/Form/Api.php b/commerce_payzen/src/Includes/Form/Api.php index 8328630..803d3b8 100644 --- a/commerce_payzen/src/Includes/Form/Api.php +++ b/commerce_payzen/src/Includes/Form/Api.php @@ -257,7 +257,8 @@ public static function getSuccessStatuses() 'AUTHORISED', 'AUTHORISED_TO_VALIDATE', // TODO is this a pending status? 'CAPTURED', - 'ACCEPTED' + 'ACCEPTED', + 'PARTIALLY_AUTHORISED' ); } @@ -274,7 +275,8 @@ public static function getPendingStatuses() 'WAITING_AUTHORISATION_TO_VALIDATE', 'UNDER_VERIFICATION', 'PRE_AUTHORISED', - 'WAITING_FOR_PAYMENT' + 'WAITING_FOR_PAYMENT', + 'PENDING' ); } @@ -409,4 +411,18 @@ public static function getOverseasCountries() 'TF', 'WF', 'YT' ); } + + /** + * Returns an array of the online documentation URI of the payment module. + * + * @return array[string][string] + */ + public static function getOnlineDocUri() + { + return array( + 'fr' => 'https://payzen.io/fr-FR/plugins/', + 'en' => 'https://payzen.io/en-EN/plugins/', + 'es' => 'https://payzen.io/es-ES/plugins/' + ); + } } diff --git a/commerce_payzen/src/Plugin/Commerce/PaymentGateway/Payzen.php b/commerce_payzen/src/Plugin/Commerce/PaymentGateway/Payzen.php index f35827c..43d8b1b 100644 --- a/commerce_payzen/src/Plugin/Commerce/PaymentGateway/Payzen.php +++ b/commerce_payzen/src/Plugin/Commerce/PaymentGateway/Payzen.php @@ -134,37 +134,27 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta ]; // Get documentation links. - $filenames = glob(drupal_get_path('module', 'commerce_payzen') . '/installation_doc/' . Tools::DOC_PATTERN); - $doc_langs = array( 'fr' => 'Français', 'en' => 'English', - 'es' => 'Español' - // complete when more languages are managed. + 'es' => 'Español', + 'pt' => 'Português' + // Complete when more languages are managed. ); - $doc_files = array(); - foreach ($filenames as $filename) { - $base_filename = basename($filename, '.pdf'); - $lang = substr($base_filename, -2); // Extract language code. + $docs = '' . $this->t('Click to view the module configuration documentation: '); - $doc_files[$base_filename . '.pdf'] = $doc_langs[$lang]; + foreach (PayzenApi::getOnlineDocUri() as $lang => $docUri) { + $docs .= '' . $doc_langs[$lang] . ''; } - if (! empty($doc_files)) { - $doc = '' . $this->t('Click to view the module configuration documentation :'); - foreach ($doc_files as $file => $lang) { - $doc .= '' . $lang . ''; - } - - $doc .= ''; + $docs .= ''; - $form['module_info']['doc_links'] = [ - '#type' => 'item', - '#title' => '', - '#markup' => $doc - ]; - } + $form['module_info']['doc_links'] = [ + '#type' => 'item', + '#title' => '', + '#markup' => $docs + ]; // Payment gateway access. $form['gateway_access'] = [ @@ -664,6 +654,9 @@ public function onNotify(Request $request) $order->getState()->applyTransitionById('cancel'); $order->save(); } + } else { + $payment_order_updater = \Drupal::service('commerce_payment.order_updater'); + $payment_order_updater->updateOrder($order, true); } die($response->getOutputForPlatform('payment_ok_already_done')); @@ -717,42 +710,44 @@ private function savePayment($order, $response) $payment->setRemoteId($trans_uuid); $payment->setRemoteState($response->getTransStatus()); + $timestamp = \Drupal::time()->getRequestTime(); if ($response->get('operation_type') == 'CREDIT') { $payment->setAmount(new Price('0', $currency->getAlpha3())); // It's a refund, not an actual payment. $payment->setRefundedAmount($amount); $state = 'refunded'; + $payment->setCompletedTime($timestamp); } elseif ($response->isAcceptedPayment() && $payment->getAmount() && $amount->lessThan($payment->getAmount())) { // Case of modification of a non-captured payment. $refunded_amount = $payment->getAmount()->subtract($amount); $payment->setRefundedAmount($refunded_amount); $state = 'partially_refunded'; } else { - $payment->setAmount($amount); - - switch ($response->getTransStatus()) { - case 'AUTHORISED' : - case 'ACCEPTED' : - case 'CAPTURED' : - $state = 'completed'; - break; - - case 'AUTHORISED_TO_VALIDATE' : - case 'WAITING_AUTHORISATION_TO_VALIDATE' : - case 'WAITING_AUTHORISATION' : - case 'UNDER_VERIFICATION' : - case 'INITIAL' : - case 'WAITING_FOR_PAYMENT' : - $state = 'pending'; - break; - - default: - $state = 'voided'; - break; - } + $payment->setAmount($amount); + + switch ($response->getTransStatus()) { + case 'AUTHORISED' : + case 'ACCEPTED' : + case 'CAPTURED' : + $state = 'completed'; + break; + + case 'AUTHORISED_TO_VALIDATE' : + case 'WAITING_AUTHORISATION_TO_VALIDATE' : + case 'WAITING_AUTHORISATION' : + case 'UNDER_VERIFICATION' : + case 'INITIAL' : + case 'WAITING_FOR_PAYMENT' : + $state = 'pending'; + break; + + default: + $state = 'voided'; + break; + } } - $payment->setAuthorizedTime(\Drupal::time()->getRequestTime()); + $payment->setAuthorizedTime($timestamp); $payment->setState($state); $payment->save(); diff --git a/commerce_payzen/src/Tools.php b/commerce_payzen/src/Tools.php index 63a3623..65903d8 100644 --- a/commerce_payzen/src/Tools.php +++ b/commerce_payzen/src/Tools.php @@ -24,8 +24,8 @@ class Tools const GATEWAY_CODE = 'PayZen'; const GATEWAY_VERSION = 'V2'; const CMS_IDENTIFIER = 'Drupal_Commerce_2.x'; - const PLUGIN_VERSION = '2.0.6'; - const DOC_PATTERN = '${doc.pattern}'; + const PLUGIN_VERSION = '2.0.7'; + const DOC_PATTERN = '###DOC_PATTERN###'; public static $pluginFeatures = array( 'qualif' => false, diff --git a/commerce_payzen/translations/payzen.de.po b/commerce_payzen/translations/payzen.de.po index fb8d384..8fb9eed 100644 --- a/commerce_payzen/translations/payzen.de.po +++ b/commerce_payzen/translations/payzen.de.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: PayZen for Drupal Commerce (8.x-" -"2.0.6)\n" +"2.0.7)\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2020-12-02 14:59+0100\n" "PO-Revision-Date: 2021-01-31 15:19+0100\n" @@ -96,8 +96,8 @@ msgid "Gateway version" msgstr "Kompatibel mit Zahlungsschnittstelle" #: src/Plugin/Commerce/PaymentGateway/Payzen.php:148 -msgid "Click to view the module configuration documentation :" -msgstr "Klicken Sie, um die Modul-Konfigurationsdokumentation zu finden:" +msgid "Click to view the module configuration documentation: " +msgstr "Klicken Sie, um die Modul-Konfigurationsdokumentation zu finden: " #: src/Plugin/Commerce/PaymentGateway/Payzen.php:166 msgid "PAYMENT GATEWAY ACCESS" diff --git a/commerce_payzen/translations/payzen.es.po b/commerce_payzen/translations/payzen.es.po index a3b5acd..12bd7a4 100644 --- a/commerce_payzen/translations/payzen.es.po +++ b/commerce_payzen/translations/payzen.es.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: PayZen for Drupal Commerce (8.x-" -"2.0.6)\n" +"2.0.7)\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2020-12-02 15:02+0100\n" "PO-Revision-Date: 2021-01-31 15:17+0100\n" @@ -95,8 +95,8 @@ msgid "Gateway version" msgstr "Versión del portal" #: src/Plugin/Commerce/PaymentGateway/Payzen.php:148 -msgid "Click to view the module configuration documentation :" -msgstr "Haga clic para ver la documentación de la configuración del módulo:" +msgid "Click to view the module configuration documentation: " +msgstr "Haga clic para ver la documentación de la configuración del módulo: " #: src/Plugin/Commerce/PaymentGateway/Payzen.php:166 msgid "PAYMENT GATEWAY ACCESS" diff --git a/commerce_payzen/translations/payzen.fr.po b/commerce_payzen/translations/payzen.fr.po index cb12dc3..3967d38 100644 --- a/commerce_payzen/translations/payzen.fr.po +++ b/commerce_payzen/translations/payzen.fr.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: PayZen for Drupal Commerce (8.x-" -"2.0.6)\n" +"2.0.7)\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2020-12-02 15:05+0100\n" "PO-Revision-Date: 2021-01-31 15:16+0100\n" @@ -96,8 +96,8 @@ msgid "Gateway version" msgstr "Version de la plateforme" #: src/Plugin/Commerce/PaymentGateway/Payzen.php:148 -msgid "Click to view the module configuration documentation :" -msgstr "Cliquer pour accéder à la documentation de configuration du module :" +msgid "Click to view the module configuration documentation: " +msgstr "Cliquer pour accéder à la documentation de configuration du module: " #: src/Plugin/Commerce/PaymentGateway/Payzen.php:166 msgid "PAYMENT GATEWAY ACCESS"