Skip to content

Commit dd022b8

Browse files
Merge pull request #4 from agence-tbd/version_1.5.2
Version 1.5.2
2 parents ecf40d7 + e1d31c1 commit dd022b8

39 files changed

+2897
-970
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Changelog
22
-------
3+
* 1.5.2 - 2024/12/05
4+
* Add Klarna payment compatibility
5+
* Add log visibility in backoffice
6+
* Fix billingDay for NX payment
7+
8+
---
39
* 1.5.1 - 2024/10/24
410
* Refund order on cancel status
511

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ Here are the main configuration fields for the payment method:
5050

5151
![Screenshot showing payment method configuration in backoffice](doc/config.png)
5252

53-
* Base
53+
1. Base
5454
* Title
5555

5656
![Screenshot showing payment method configuration in backoffice](doc/config_base.png)
5757

58-
* Acess:
58+
2. Acess:
5959
* Merchant ID
6060
* Access key
6161
* Environment
@@ -65,7 +65,7 @@ Here are the main configuration fields for the payment method:
6565
*
6666
![Screenshot showing payment method configuration in backoffice](doc/config_access.png)
6767

68-
* Settings
68+
3. Settings
6969
* Payment action
7070
* Widget integration mode
7171
* Main contract number

assets/css/admin.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#log_container {
2+
overflow: hidden;
3+
height: 410px;
4+
padding: 5px;
5+
margin-top: 10px;
6+
}
7+
8+
#log_container.card {
9+
max-width: 100%;
10+
}
11+
12+
#log_display {
13+
width: 100%;
14+
height: 400px;
15+
overflow: auto;
16+
margin: 0;
17+
padding: 6px;
18+
background: black;
19+
color: #2EC029EC
20+
}
21+
22+
#log_display details[open] {
23+
padding: 4px;
24+
}

assets/js/admin/logs.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
jQuery(document).on('change', 'select#logs-files-list-select', function() {
2+
jQuery('#log_display').html("<p>Loading...</p>");
3+
4+
jQuery.ajax({
5+
url: logs_viewer_js_data.ajax_url,
6+
// url: window.url,
7+
type: 'GET',
8+
dataType: 'JSON',
9+
data: {
10+
action: 'load_log',
11+
data: jQuery('#logs-files-list-select').val(),
12+
},
13+
success: (result) => {
14+
jQuery('#log_display').html("");
15+
16+
result.data.forEach((logLine) => {
17+
let html = "<p>" + logLine.date + " - " + logLine.logger + " " + logLine.level + " : " + logLine.message;
18+
19+
if (logLine['context'].length !== 0) {
20+
html += "<details><summary>[ View Context ]</summary><div style='white-space: pre'>"
21+
+ JSON.stringify(logLine.context, null, 2)
22+
+ "</div></details>";
23+
}
24+
25+
html += "</p>";
26+
jQuery('#log_display').append(html);
27+
})
28+
},
29+
});
30+
});

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"require": {
3-
"monext/payline-sdk": "4.76"
3+
"monext/payline-sdk": "4.76",
4+
"ddtraceweb/monolog-parser": "^1.3"
45
}
56
}

composer.lock

Lines changed: 44 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
use Dubture\Monolog\Reader\LogReader;
4+
class PaylineLogsViewer {
5+
6+
public static function showLogs()
7+
{
8+
$template_data = array(
9+
'logsFilesArray' => self::getPaylineLogsFilesList(),
10+
);
11+
12+
// wc_get_template( 'admin/logs-viewer.php', $template_data );
13+
load_template( WP_PLUGIN_DIR.'/payline/templates/admin/logs-viewer.php', true, $template_data );
14+
}
15+
16+
protected static function getPaylineLogsFilesList()
17+
{
18+
$logsFiles = [];
19+
$directoryPath = WP_CONTENT_DIR.'/uploads/wc-logs/payline';
20+
if (is_dir($directoryPath)) {
21+
$files = scandir($directoryPath);
22+
$files = array_diff($files, array('.', '..')); // Exclure les entrées spéciales
23+
foreach ($files as $file) {
24+
$logsFiles[] = $file;
25+
}
26+
}
27+
return $logsFiles;
28+
}
29+
30+
public function doAjaxGetLogs()
31+
{
32+
$logFileContent = self::getLogsLines($_GET['data']);
33+
wp_send_json_success($logFileContent);
34+
}
35+
36+
protected function getLogsLines($logFilename)
37+
{
38+
$logFileContent = [];
39+
if ($logFilename) {
40+
$logFile = WP_CONTENT_DIR.'/uploads/wc-logs/payline/'. $logFilename;
41+
$reader = new LogReader($logFile, 0);
42+
43+
foreach ($reader as $log) {
44+
if (!empty($log) && !empty($log['date'])) {
45+
46+
$logFileContent[] = [
47+
'date' => $log['date']->format('d-m-Y'),
48+
'logger' => $log['logger'],
49+
'level' => $log['level'],
50+
'message' => $log['message'],
51+
'context' => $log['context'],
52+
];
53+
}
54+
}
55+
}
56+
return $logFileContent;
57+
}
58+
}

includes/gateway/class-wc-gateway-abstract-payline.php

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract class WC_Abstract_Payline extends WC_Payment_Gateway {
1919

2020
protected $paymentMode = '';
2121

22-
protected $extensionVersion = '1.5.1';
22+
protected $extensionVersion = '1.5.2';
2323

2424
/** @var int Payline internal API version */
2525
protected $APIVersion = 26;
@@ -675,9 +675,11 @@ function getRawRedirectUrl($order_id) {
675675
$order = wc_get_order($order_id);
676676

677677
$this->SDK = $this->getSDK();
678+
$redirectURL = $this->getCachedDWPDataForOrder($order, 'redirectURL', true);
678679

679680

680-
$redirectURL = $this->getCachedDWPDataForOrder($order, 'redirectURL', true);
681+
$errorCode = $this->SDK::ERR_CODE;
682+
$errorMsg = $this->SDK::ERR_SHORT_MESSAGE;
681683

682684
if ( !$redirectURL ) {
683685
$requestParams = $this->getWebPaymentRequest($order);
@@ -688,10 +690,13 @@ function getRawRedirectUrl($order_id) {
688690
if ( $result['result']['code'] === '00000' ) {
689691
$this->updateTokenForOrder($order, $result);
690692
return $result['redirectURL'];
693+
} else {
694+
$errorCode = $result['result']['code'];
695+
$errorMsg = $result['result']['longMessage'];
691696
}
692697
}
693698

694-
$message = sprintf( __( 'You can\'t be redirected to payment page (error code ' . $result['result']['code'] . ' : ' . $result['result']['longMessage'] . '). Please contact us.', 'payline' ), 'Payline' );
699+
$message = sprintf( __( 'You can\'t be redirected to payment page (error code %s : %s). Please contact us.', 'payline' ), $errorCode, $errorMsg);
695700
return $this->get_error_payment_url($order, $message);
696701
}
697702

@@ -820,10 +825,12 @@ protected function getWebPaymentRequest(WC_Order $order)
820825

821826
$doWebPaymentRequest['order']['ref'] = $this->cleanSubstr($order->get_id(), 0, 50);
822827
$doWebPaymentRequest['order']['country'] = $order->get_billing_country();
823-
$doWebPaymentRequest['order']['taxes'] = round($order->get_total_tax());
828+
$doWebPaymentRequest['order']['taxes'] = round(($order->get_total_tax() - $order->get_shipping_tax()) * 100);
824829
$doWebPaymentRequest['order']['amount'] = $doWebPaymentRequest['payment']['amount'];
825830
$doWebPaymentRequest['order']['date'] = date(self::PAYLINE_DATE_FORMAT);
826831
$doWebPaymentRequest['order']['currency'] = $doWebPaymentRequest['payment']['currency'];
832+
$doWebPaymentRequest['order']['deliveryCharge'] = round(($order->get_shipping_total() + $order->get_shipping_tax()) * 100);
833+
//$doWebPaymentRequest['order']['discountAmount'] = round(($order->get_discount_total() + $order->get_discount_tax()) * 100);
827834

828835
// BUYER
829836
// TODO: Default value
@@ -860,26 +867,49 @@ protected function getWebPaymentRequest(WC_Order $order)
860867
$doWebPaymentRequest['shippingAddress']['name'] .= ' (' . $order->get_shipping_company() . ')';
861868
}
862869
$doWebPaymentRequest['shippingAddress']['name'] = $this->cleanSubstr($doWebPaymentRequest['shippingAddress']['name'], 0, 100);
863-
$doWebPaymentRequest['shippingAddress']['firstName'] = $this->cleanSubstr($order->get_shipping_first_name(), 0, 100);
864-
$doWebPaymentRequest['shippingAddress']['lastName'] = $this->cleanSubstr($order->get_shipping_last_name(), 0, 100);
865-
$doWebPaymentRequest['shippingAddress']['street1'] = $this->cleanSubstr($order->get_shipping_address_1(), 0, 100);
866-
$doWebPaymentRequest['shippingAddress']['street2'] = $this->cleanSubstr($order->get_shipping_address_2(), 0, 100);
867-
$doWebPaymentRequest['shippingAddress']['cityName'] = $this->cleanSubstr($order->get_shipping_city(), 0, 40);
868-
$doWebPaymentRequest['shippingAddress']['zipCode'] = $this->cleanSubstr($order->get_shipping_postcode(), 0, 20);
869-
$doWebPaymentRequest['shippingAddress']['country'] = $order->get_shipping_country();
870+
$doWebPaymentRequest['shippingAddress']['firstName'] = $this->cleanSubstr($order->get_shipping_first_name()?: $order->get_billing_first_name(), 0, 100);
871+
$doWebPaymentRequest['shippingAddress']['lastName'] = $this->cleanSubstr($order->get_shipping_last_name()?: $order->get_billing_last_name(), 0, 100);
872+
$doWebPaymentRequest['shippingAddress']['street1'] = $this->cleanSubstr($order->get_shipping_address_1()?: $order->get_billing_address_1(), 0, 100);
873+
$doWebPaymentRequest['shippingAddress']['street2'] = $this->cleanSubstr($order->get_shipping_address_2()?: $order->get_billing_address_2(), 0, 100);
874+
$doWebPaymentRequest['shippingAddress']['cityName'] = $this->cleanSubstr($order->get_shipping_city()?: $order->get_billing_city(), 0, 40);
875+
$doWebPaymentRequest['shippingAddress']['zipCode'] = $this->cleanSubstr($order->get_shipping_postcode()?: $order->get_billing_postcode(), 0, 20);
876+
$doWebPaymentRequest['shippingAddress']['country'] = $order->get_shipping_country()?: $order->get_billing_country();
870877
$doWebPaymentRequest['shippingAddress']['phone'] = '';
871878

879+
$totalOrderLines = 0;
872880
// ORDER DETAILS
873881
$items = $order->get_items();
874-
foreach ($items as $item) {
875-
$this->SDK->addOrderDetail(array(
882+
/** @var WC_Order_Item_Product $item */
883+
foreach ($items as $item) {
884+
$orderLine = array(
876885
'ref' => $this->cleanSubstr($item['name'], 0, 50),
877-
'price' => round($item['line_total'] * 100),
878-
'quantity' => $item['qty'],
879-
'comment' => ''
880-
));
886+
'price' => round(($item->get_subtotal() + $item->get_subtotal_tax())/$item['qty'],2) * 100,
887+
'quantity' => (int)$item['qty'],
888+
'comment' => (string)$item['name'],
889+
'taxRate' => round(($item['total_tax'] / $item['total']) * 100 * 100)
890+
);
891+
$this->SDK->addOrderDetail($orderLine);
892+
893+
$totalOrderLines+=$orderLine['price'] * $orderLine['quantity'];
881894
}
882895

896+
//Allow Klarna with cart discount
897+
//$adjustment = $doWebPaymentRequest['order']['amount'] - $totalOrderLines - $doWebPaymentRequest['order']['deliveryCharge'] - $doWebPaymentRequest['order']['discountAmount'];
898+
$adjustment = $doWebPaymentRequest['order']['amount'] - $totalOrderLines - $doWebPaymentRequest['order']['deliveryCharge'];
899+
if ($adjustment) {
900+
$prixHT = ($order->get_total() - $order->get_total_tax() - $order->get_shipping_total());
901+
$taxRate = round(($order->get_cart_tax() / $prixHT) * 100 * 100);
902+
903+
$this->SDK->addOrderDetail(array(
904+
'ref' => 'CART_DISCOUNT',
905+
'price' => $adjustment,
906+
'quantity' => 1,
907+
'comment' => 'Cart amount adjustment',
908+
'category' => 'main',
909+
'taxRate' => $taxRate
910+
));
911+
}
912+
883913
// TRANSACTION OPTIONS
884914
$doWebPaymentRequest['notificationURL'] = $this->get_request_url('notification');
885915
$doWebPaymentRequest['returnURL'] = $this->get_request_url('return');
@@ -1008,7 +1038,7 @@ function generate_payline_form($order_id) {
10081038

10091039
exit;
10101040
} else {
1011-
$message = sprintf( __( 'You can\'t be redirected to payment page (error code ' . $result['result']['code'] . ' : ' . $result['result']['longMessage'] . '). Please contact us.', 'payline' ), 'Payline' );
1041+
$message = sprintf( __( 'You can\'t be redirected to payment page (error code %s : %s). Please contact us.', 'payline' ), $result['result']['code'], $result['result']['longMessage']);
10121042
wp_redirect($this->get_error_payment_url($order, $message));
10131043
die();
10141044
}

includes/gateway/class-wc-gateway-payline-nx.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,11 @@ protected function getWebPaymentRequest(WC_Order $order) {
5858
$requestParams['recurring']['amount'] = $recurringAmount;
5959
$requestParams['recurring']['billingCycle'] = $this->settings['billing_cycle'];
6060

61-
62-
$requestParams['recurring']['billingDay'] = '01'; // [01 à 30]
63-
6461
$numberDaysCycle = $this->getDaysForCycles($this->settings['billing_cycle']);
6562

6663
//$today = current_time( 'd/m/Y' );
6764
$requestParams['recurring']['startDate'] = current_datetime()->modify( '+' .$numberDaysCycle. ' day' )->format( 'd/m/Y' );; // dd/mm/yyyy
65+
$requestParams['recurring']['billingDay'] = current_datetime()->modify( '+' .$numberDaysCycle. ' day' )->format( 'd' );
6866

6967
do_action('payline_before_do_web_payment_nx', $requestParams, $this);
7068

languages/payline-fr_FR.mo

1000 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)