From c09f7a235c6c955f48882947725d92ff7f0ad487 Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Wed, 9 Apr 2025 11:56:21 +0200 Subject: [PATCH 1/7] Fix type --- htdocs/compta/facture/class/facture.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index ec1603d3baf..0027af94cbe 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1491,6 +1491,7 @@ class Facture extends CommonInvoice $this->pos_source = $object->pos_source; $this->origin = $object->element; + $this->origin_type = $object->element; $this->origin_id = $object->id; $this->fk_user_author = $user->id; From 9ab63b3491a450a585f684ae695f5ce5f78b8481 Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Wed, 9 Apr 2025 12:32:53 +0200 Subject: [PATCH 2/7] Doc --- htdocs/public/payment/paymentok.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index fcb4486f99b..44adc70ff78 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -1068,8 +1068,10 @@ if ($ispaymentok) { $invoice = new Facture($db); $result = $invoice->createFromOrder($object, $user); if ($result > 0) { - $object->classifyBilled($user); - $invoice->validate($user); + $object->classifyBilled($user); // The invoice has been create from the order so total is the same, so we can classify order to billed (even if payment may be partial). + + $invoice->validate($user); // This may re-classify all linked orders to billed (done previously) if amount of invoice is ok by triggers, depending on the workflow module setup. + // Creation of payment line include_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; $paiement = new Paiement($db); From f2cef3a8d13de2bd93e75f635550324975a76a6e Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Wed, 9 Apr 2025 12:35:35 +0200 Subject: [PATCH 3/7] Doc --- htdocs/public/payment/paymentok.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 44adc70ff78..0aee2a9b482 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -1072,7 +1072,7 @@ if ($ispaymentok) { $invoice->validate($user); // This may re-classify all linked orders to billed (done previously) if amount of invoice is ok by triggers, depending on the workflow module setup. - // Creation of payment line + // Creation of payment line (warning: if amount has been modified on page, the payment may be partial) include_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; $paiement = new Paiement($db); $paiement->datepaye = $now; From 8ef33a848d1b5ce50d31fab93a65c240be58b76f Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Wed, 9 Apr 2025 13:28:33 +0200 Subject: [PATCH 4/7] Doc --- htdocs/public/payment/paymentok.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 0aee2a9b482..a329fa92d99 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -1068,6 +1068,13 @@ if ($ispaymentok) { $invoice = new Facture($db); $result = $invoice->createFromOrder($object, $user); if ($result > 0) { + if ($FinalPaymentAmt != $object->total_ttc) { + // The amount paid can be lower than the order only if the user tried to modified the amount from the payment page. A payment has been received but it is a hack attempt + // We can add a line to reduce the amount of the invoice but with which vat ? + // TODO Test if vat on line is the same everywhere, if yes we can add + // $invoice->addline('Fix amount of invoice', $FinalPaymentAmt - $object->total_ttc, 1, $txtva); + } + $object->classifyBilled($user); // The invoice has been create from the order so total is the same, so we can classify order to billed (even if payment may be partial). $invoice->validate($user); // This may re-classify all linked orders to billed (done previously) if amount of invoice is ok by triggers, depending on the workflow module setup. From 0757f6048f2b0bf53d9be8ad601fdea4d926048e Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Wed, 9 Apr 2025 13:39:28 +0200 Subject: [PATCH 5/7] Doc --- htdocs/public/payment/paymentok.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index a329fa92d99..90284ff7d8b 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -1073,6 +1073,7 @@ if ($ispaymentok) { // We can add a line to reduce the amount of the invoice but with which vat ? // TODO Test if vat on line is the same everywhere, if yes we can add // $invoice->addline('Fix amount of invoice', $FinalPaymentAmt - $object->total_ttc, 1, $txtva); + // TODO Send a warning email. } $object->classifyBilled($user); // The invoice has been create from the order so total is the same, so we can classify order to billed (even if payment may be partial). From d826358d588431c8246bcfb7860b75318eee06fb Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Wed, 9 Apr 2025 13:56:05 +0200 Subject: [PATCH 6/7] Log --- htdocs/public/payment/newpayment.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 78f321ba802..abbe1b8acf0 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -1001,6 +1001,7 @@ if (isModEnabled('paybox')) { } if (isModEnabled('stripe')) { print ''."\n"; + print ''."\n"; } print ''."\n"; print ''."\n"; From 964ee3e2b8763fae096b759909becba13fbbea9a Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Wed, 9 Apr 2025 14:47:37 +0200 Subject: [PATCH 7/7] FIX Do not allow to force amount for online payment of order --- htdocs/public/payment/newpayment.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index abbe1b8acf0..ceb5d6cb984 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -2359,7 +2359,7 @@ if (preg_match('/^dopayment/', $action)) { // If we chose/clicked on the payme print ''."\n"; print ''."\n"; print ''."\n"; - print ''; + print ''."\n"; print ''."\n"; print ''."\n"; print ''; @@ -2367,7 +2367,28 @@ if (preg_match('/^dopayment/', $action)) { // If we chose/clicked on the payme print ''; print ''; - if (getDolGlobalString('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') || getDolGlobalString('STRIPE_USE_NEW_CHECKOUT')) { // Use a SCA ready method + // Make some check on amount: We accept an amount that is different to allow to pay an existing invoice partially or + // to allow to pay a membership with open amount, but for a payment of an order, we have no reason to accept partial payment. + $checkamount = 1; + $tmptag = dolExplodeIntoArray($fulltag, '.', '='); + if (array_key_exists('ORD', $tmptag) && (int) $tmptag['ORD'] > 0) { + include_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; + $object = new Commande($db); + $result = $object->fetch((int) $tmptag['ORD']); + if ($result > 0) { + if ($object->total_ttc != $amount) { + $checkamount = 0; + } + } else { + $checkamount = 0; + } + } + if (!$checkamount) { + dol_syslog("Hack attempt detected", LOG_WARNING); + setEventMessages('Bad value for amount. Reported as a hack attempt.', null, 'errors'); + } + + if ($checkamount && (getDolGlobalString('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION') || getDolGlobalString('STRIPE_USE_NEW_CHECKOUT'))) { // Use a SCA ready method require_once DOL_DOCUMENT_ROOT.'/stripe/class/stripe.class.php'; $service = 'StripeLive'; @@ -2440,7 +2461,7 @@ if (preg_match('/^dopayment/', $action)) { // If we chose/clicked on the payme if (getDolGlobalString('STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION')) { if (empty($paymentintent)) { - print '
'.$langs->trans("Error").'
'; + print '
'.$langs->trans("Error").' - Failed to get PaymentIntent
'; } else { print ''; //$_SESSION["paymentintent_id"] = $paymentintent->id;