diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index e6008e01a92..c7621ab75c4 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1490,6 +1490,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; diff --git a/htdocs/public/payment/newpayment.php b/htdocs/public/payment/newpayment.php index 306e7b5bf72..a0d2fe0b05e 100644 --- a/htdocs/public/payment/newpayment.php +++ b/htdocs/public/payment/newpayment.php @@ -1010,6 +1010,7 @@ if (isModEnabled('paybox')) { } if (isModEnabled('stripe')) { print ''."\n"; + print ''."\n"; } print ''."\n"; print ''."\n"; @@ -2368,7 +2369,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 ''; @@ -2376,7 +2377,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'; @@ -2449,7 +2471,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; diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index 9564ced0a2b..85d0e69b705 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -1072,9 +1072,19 @@ if ($ispaymentok) { $invoice = new Facture($db); $result = $invoice->createFromOrder($object, $user); if ($result > 0) { - $object->classifyBilled($user); - $invoice->validate($user); - // Creation of payment line + 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); + // 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). + + $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 (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;