Skip to content

Commit 7fdc9b1

Browse files
committed
Merge branch 'master' of [email protected]:/DoliCloud/dolimods
2 parents 3bafdc0 + b0d6305 commit 7fdc9b1

File tree

3 files changed

+68
-9
lines changed

3 files changed

+68
-9
lines changed

.github/workflows/codeql.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575

7676
# Initializes the CodeQL tools for scanning.
7777
- name: Initialize CodeQL
78-
uses: github/codeql-action/init@v3
78+
uses: github/codeql-action/init@v4
7979
with:
8080
languages: ${{ matrix.language }}
8181
build-mode: ${{ matrix.build-mode }}
@@ -106,6 +106,6 @@ jobs:
106106
exit 1
107107
108108
- name: Perform CodeQL Analysis
109-
uses: github/codeql-action/analyze@v3
109+
uses: github/codeql-action/analyze@v4
110110
with:
111111
category: "/language:${{matrix.language}}"

htdocs/payplugdolicloud/class/actions_payplugdolicloud.class.php

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -604,29 +604,82 @@ public function isPaymentOK($parameters, &$object, &$action, $hookmanager)
604604
{
605605
global $langs;
606606

607-
$error = 0; // Error counter
608-
$ispaymentok = false;
607+
require_once DOL_DOCUMENT_ROOT."/core/lib/geturl.lib.php";
608+
include_once DOL_DOCUMENT_ROOT.'/core/lib/security.lib.php';
609+
dol_include_once('payplugdolicloud/lib/payplugdolicloud.lib.php');
610+
$langs->load("payplugdolicloud@payplugdolicloud");
609611

612+
$error = 0;
610613
if (in_array($parameters['paymentmethod'], array('payplug'))){
611614
$code = GETPOST("code");
612615

613616
if ($code == "refused") {
614-
$ispaymentok = false;
615617
$error++;
618+
$this->errors[] = $langs->trans("ErrorPaymentRefused");
616619
} else {
617-
// TODO Do a check with payplug api call
620+
// Ensure the amount matches the requested value
621+
// Compare session amount from doPayment with PayPlug API response
622+
$paymentId = isset($_SESSION["PAYPLUG_DOLICLOUD_PAYMENT_ID"]) ? $_SESSION["PAYPLUG_DOLICLOUD_PAYMENT_ID"] : '';
623+
$amounttotest = isset($_SESSION["FinalPaymentAmt"]) ? $_SESSION["FinalPaymentAmt"] : 0;
624+
$currencyCodeTypetotest = isset($_SESSION["currencyCodeType"]) ? $_SESSION["currencyCodeType"] : '';
625+
626+
if (empty($paymentId) || empty($amounttotest) || empty($currencyCodeTypetotest)) {
627+
$error++;
628+
$this->errors[] = $langs->trans("ErrorSessionNotFound");
629+
}
630+
631+
if (!$error) {
632+
$payplugrurlapi = "api.payplug.com";
633+
if (getDolGlobalInt("PAYPLUG_DOLICLOUD_LIVE")) {
634+
$secretapikey = getDolGlobalString("PAYPLUG_DOLICLOUD_PROD_SECRET_API_KEY");
635+
} else {
636+
$secretapikey = getDolGlobalString("PAYPLUG_DOLICLOUD_TEST_SECRET_API_KEY");
637+
}
638+
639+
// Verify if payment is done
640+
$headers = array();
641+
$headers[] = "accept: application/json";
642+
$headers[] = "Authorization: Bearer ".$secretapikey;
643+
$headers[] = "Content-Type: application/json";
644+
$urlforcheckout = "https://".urlencode($payplugrurlapi)."/v1/payments/".$paymentId;
645+
$ret1 = getURLContent($urlforcheckout, 'GET', '', 1, $headers);
646+
if (empty($ret1) || !is_array($ret1) || empty($ret1['content'])) {
647+
$error++;
648+
$this->errors[] = $langs->trans("ErrorConnectionToPayplugFailed");
649+
$json1 = null;
650+
} else {
651+
$json1 = json_decode($ret1['content']);
652+
}
618653

619654

655+
if ($ret1["http_code"] == 200 && empty($json1->failure) && !$error) {
656+
if (empty($json1->id) || $json1->id != $_SESSION["PAYPLUG_DOLICLOUD_PAYMENT_ID"]) {
657+
$error++;
658+
$this->errors[] = $langs->trans("ErrorPaymentNotFound");
659+
}
660+
$amountfrompayplug = !empty($json1->amount) ? $json1->amount / 100 : 0; // Payplug amount is in cents
661+
$currencyfrompayplug = !empty($json1->currency) ? $json1->currency : '';
620662

621-
$ispaymentok = true;
663+
if ($amounttotest != $amountfrompayplug) {
664+
$error++;
665+
$this->errors[] = $langs->trans("ErrorValueFinalPaymentDiffers");
666+
}
667+
if ($currencyCodeTypetotest != $currencyfrompayplug) {
668+
$error++;
669+
$this->errors[] = $langs->trans("ErrorValueFinalPaymentDiffersCurrency");
670+
}
671+
} else {
672+
$error++;
673+
$this->errors[] = $langs->trans("ErrorPaymentNotFound");
674+
}
675+
}
622676
}
623677
}
624678

625679
if (!$error) {
626-
$this->results["ispaymentok"] = $ispaymentok;
680+
$this->results["ispaymentok"] = true;
627681
return 1;
628682
} else {
629-
$this->errors[] = $langs->trans("PaymentRefused");
630683
return -1;
631684
}
632685
}

htdocs/payplugdolicloud/langs/en_US/payplugdolicloud.lang

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ PayplugDoPayment = Pay with Payplug
4444
ErrorBadValueAmount=Please change your basket amount. It must be free or greater than €0.50 to authorize your payment
4545
ErrorValueFinalPaymentDiffers= Value of FinalPayment (%s) differs from value expected for membership (%s).
4646
ErrorBadClientIdOrSecret=Bad client ID or secret
47+
ErrorPaymentRefused=Payment was refused. Please try again later.
48+
ErrorSessionNotFound=Payment session not found or expired. Please restart the payment process.
49+
ErrorConnectionToPayplugFailed=Unable to connect to PayPlug.
50+
ErrorPaymentNotFound=Payment not found.
51+
ErrorValueFinalPaymentDiffers=The final payment amount differs from the expected value.
52+
ErrorValueFinalPaymentDiffersCurrency=The payment currency differs from the expected one.
4753

4854
#
4955
# Sample widget

0 commit comments

Comments
 (0)