Skip to content

Commit

Permalink
Merge branch 'hotfix/2.0.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alima Grine committed Apr 26, 2023
2 parents 1592ca5 + eeaaaac commit 93b6e94
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 59 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion commerce_payzen/commerce_payzen.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 18 additions & 2 deletions commerce_payzen/src/Includes/Form/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ public static function getSuccessStatuses()
'AUTHORISED',
'AUTHORISED_TO_VALIDATE', // TODO is this a pending status?
'CAPTURED',
'ACCEPTED'
'ACCEPTED',
'PARTIALLY_AUTHORISED'
);
}

Expand All @@ -274,7 +275,8 @@ public static function getPendingStatuses()
'WAITING_AUTHORISATION_TO_VALIDATE',
'UNDER_VERIFICATION',
'PRE_AUTHORISED',
'WAITING_FOR_PAYMENT'
'WAITING_FOR_PAYMENT',
'PENDING'
);
}

Expand Down Expand Up @@ -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/'
);
}
}
85 changes: 40 additions & 45 deletions commerce_payzen/src/Plugin/Commerce/PaymentGateway/Payzen.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<span class="payzen-doc-links">' . $this->t('Click to view the module configuration documentation: ');

$doc_files[$base_filename . '.pdf'] = $doc_langs[$lang];
foreach (PayzenApi::getOnlineDocUri() as $lang => $docUri) {
$docs .= '<a href="' . $docUri . 'drupal-commerce2/sitemap.html" target="_blank">' . $doc_langs[$lang] . '</a>';
}

if (! empty($doc_files)) {
$doc = '<span class="payzen-doc-links">' . $this->t('Click to view the module configuration documentation :');
foreach ($doc_files as $file => $lang) {
$doc .= '<a href="' . base_path() . drupal_get_path('module', 'commerce_payzen') . '/installation_doc/' . $file . '" target="_blank">' . $lang . '</a>';
}

$doc .= '</span>';
$docs .= '</span>';

$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'] = [
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions commerce_payzen/src/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions commerce_payzen/translations/payzen.de.po
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions commerce_payzen/translations/payzen.es.po
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions commerce_payzen/translations/payzen.fr.po
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 93b6e94

Please sign in to comment.