From 1fe589ac3e2d67effa6b8722fe47a8e17309b58b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 18 Jan 2023 14:43:09 +0100 Subject: [PATCH] Fix debug payment using SEPA Stripe --- htdocs/core/class/commoninvoice.class.php | 45 +++++++++++++++++++---- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index 7a8b5e3cbf7..93d125291ef 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -1299,18 +1299,49 @@ abstract class CommonInvoice extends CommonObject } } - $object = $invoice; + $object = $this; - $actioncode = ''; - $extraparams = ''; + // Send emails + $labeltouse = 'InvoicePaymentSuccess'; + $sendemailtocustomer = 1; + + if (empty($charge) || $charge->status == 'failed') { + $labeltouse = 'InvoicePaymentFailure'; + if ($noemailtocustomeriferror) { + $sendemailtocustomer = 0; + } // $noemailtocustomeriferror is set when error already reported on myaccount screen + } + + // Track an event + if (empty($charge) || $charge->status == 'failed') { + $actioncode = 'PAYMENT_STRIPE_KO'; + $extraparams = $stripefailurecode; + $extraparams .= (($extraparams && $stripefailuremessage) ? ' - ' : '') . $stripefailuremessage; + $extraparams .= (($extraparams && $stripefailuredeclinecode) ? ' - ' : '') . $stripefailuredeclinecode; + } else { + $actioncode = 'PAYMENT_STRIPE_OK'; + $extraparams = ''; + } } else { $error++; $errorforinvoice++; dol_syslog("No direct debit payment method found for this stripe customer " . $customer->id, LOG_WARNING); $this->errors[] = 'Failed to get direct debit payment method for stripe customer = ' . $customer->id; - $object = $invoice; - $actioncode = ''; + $labeltouse = 'InvoicePaymentFailure'; + $sendemailtocustomer = 1; + if ($noemailtocustomeriferror) { + $sendemailtocustomer = 0; + } // $noemailtocustomeriferror is set when error already reported on myaccount screen + + $description = 'Failed to find or use the payment mode - no credit card defined for the customer account'; + $stripefailurecode = 'BADPAYMENTMODE'; + $stripefailuremessage = 'Failed to find or use the payment mode - no credit card defined for the customer account'; + $postactionmessages[] = $description . ' (' . $stripearrayofkeys['publishable_key'] . ')'; + + $object = $this; + + $actioncode = 'PAYMENT_STRIPE_KO'; $extraparams = ''; } } else { @@ -1322,7 +1353,7 @@ abstract class CommonInvoice extends CommonObject $stripefailurecode = ''; $stripefailuremessage = ''; - $object = $invoice; + $object = $this; $actioncode = ''; $extraparams = ''; @@ -1349,7 +1380,7 @@ abstract class CommonInvoice extends CommonObject $stripefailuremessage = 'Failed to find or use your payment mode (no payment mode for this customer id)'; $postactionmessages = []; - $object = $invoice; + $object = $this; $actioncode = 'PAYMENT_STRIPE_KO'; $extraparams = '';