From d41ce132f37fec85dabba0925b91df2c19b23d47 Mon Sep 17 00:00:00 2001 From: ldestailleur Date: Sun, 24 Aug 2025 19:50:38 +0200 Subject: [PATCH] Save more information into exp_payment_id for Stripe payments. --- htdocs/public/payment/paymentok.php | 111 ++++++++++++++++++-- htdocs/public/stripe/ipn.php | 16 ++- htdocs/stripe/class/stripe.class.php | 149 ++++++++++++++++----------- 3 files changed, 203 insertions(+), 73 deletions(-) diff --git a/htdocs/public/payment/paymentok.php b/htdocs/public/payment/paymentok.php index effe71ebc97..c687ca4dc70 100644 --- a/htdocs/public/payment/paymentok.php +++ b/htdocs/public/payment/paymentok.php @@ -1049,8 +1049,23 @@ if ($ispaymentok) { $paiement->paiementid = $paymentTypeId; $paiement->num_payment = ''; $paiement->note_public = 'Online payment '.dol_print_date($now, 'standard').' from '.$ipaddress; - $paiement->ext_payment_id = $TRANSACTIONID; // TODO LDR May be we should store py_... instead of pi_... but we started with pi_... so we continue. - //$paiement->ext_payment_id = $TRANSACTIONID.':'.$customer->id.'@'.$stripearrayofkeysbyenv[$servicestatus]['publishable_key']; // TODO LDR It would be better if we could store this. Do we have customer->id and publishable_key ? + + // Get $customerid and $pkey + $customerid = ''; + if ($paymentIntent instanceof \Stripe\PaymentIntent) { + $customerid = $paymentIntent->customer; + } + $pkey = ''; + if (isset($stripearrayofkeysbyenv[$servicestatus]['publishable_key'])) { + $pkey = $stripearrayofkeysbyenv[$servicestatus]['publishable_key']; + } + + // May be we should store py_... instead of pi_... but we started with pi_... so we continue. + if ($customerid && $pkey) { + $paiement->ext_payment_id = $TRANSACTIONID.':'.$customerid.'@'.$pkey; + } else { + $paiement->ext_payment_id = $TRANSACTIONID; + } $paiement->ext_payment_site = $service; if (!$error) { @@ -1194,7 +1209,23 @@ if ($ispaymentok) { $paiement->paiementid = $paymentTypeId; $paiement->num_payment = ''; $paiement->note_public = 'Online payment ' . dol_print_date($now, 'standard') . ' from ' . $ipaddress; - $paiement->ext_payment_id = $TRANSACTIONID; // 'pi_...' for Stripe, ... TODO Use 'pi_...:cus_...@pk_...' + + // Get $customerid and $pkey + $customerid = ''; + if ($paymentIntent instanceof \Stripe\PaymentIntent) { + $customerid = $paymentIntent->customer; + } + $pkey = ''; + if (isset($stripearrayofkeysbyenv[$servicestatus]['publishable_key'])) { + $pkey = $stripearrayofkeysbyenv[$servicestatus]['publishable_key']; + } + + // May be we should store py_... instead of pi_... but we started with pi_... so we continue. + if ($customerid && $pkey) { + $paiement->ext_payment_id = $TRANSACTIONID.':'.$customerid.'@'.$pkey; + } else { + $paiement->ext_payment_id = $TRANSACTIONID; + } $paiement->ext_payment_site = $service; // 'StripeLive' or 'Stripe', or ... if (!$error) { @@ -1328,7 +1359,23 @@ if ($ispaymentok) { $paiement->paymenttype = $paymentTypeId; $paiement->num_payment = ''; $paiement->note_public = 'Online payment '.dol_print_date($now, 'standard').' from '.$ipaddress; - $paiement->ext_payment_id = $TRANSACTIONID; // 'pi_...' for Stripe, ... TODO Use 'pi_...:cus_...@pk_...' + + // Get $customerid and $pkey + $customerid = ''; + if ($paymentIntent instanceof \Stripe\PaymentIntent) { + $customerid = $paymentIntent->customer; + } + $pkey = ''; + if (isset($stripearrayofkeysbyenv[$servicestatus]['publishable_key'])) { + $pkey = $stripearrayofkeysbyenv[$servicestatus]['publishable_key']; + } + + // May be we should store py_... instead of pi_... but we started with pi_... so we continue. + if ($customerid && $pkey) { + $paiement->ext_payment_id = $TRANSACTIONID.':'.$customerid.'@'.$pkey; + } else { + $paiement->ext_payment_id = $TRANSACTIONID; + } $paiement->ext_payment_site = $service; // 'StripeLive' or 'Stripe', or ... if (!$error) { @@ -1463,7 +1510,23 @@ if ($ispaymentok) { $paiement->paiementid = $paymentTypeId; $paiement->num_payment = ''; $paiement->note_public = 'Online payment '.dol_print_date($now, 'standard').' from '.$ipaddress.' for event registration'; - $paiement->ext_payment_id = $TRANSACTIONID; // 'pi_...' for Stripe, ... TODO Use 'pi_...:cus_...@pk_...' + + // Get $customerid and $pkey + $customerid = ''; + if ($paymentIntent instanceof \Stripe\PaymentIntent) { + $customerid = $paymentIntent->customer; + } + $pkey = ''; + if (isset($stripearrayofkeysbyenv[$servicestatus]['publishable_key'])) { + $pkey = $stripearrayofkeysbyenv[$servicestatus]['publishable_key']; + } + + // May be we should store py_... instead of pi_... but we started with pi_... so we continue. + if ($customerid && $pkey) { + $paiement->ext_payment_id = $TRANSACTIONID.':'.$customerid.'@'.$pkey; + } else { + $paiement->ext_payment_id = $TRANSACTIONID; + } $paiement->ext_payment_site = $service; // 'StripeLive' or 'Stripe', or ... if (!$error) { @@ -1696,8 +1759,24 @@ if ($ispaymentok) { $paiement->paiementid = $paymentTypeId; $paiement->num_payment = ''; $paiement->note_public = 'Online payment '.dol_print_date($now, 'standard').' from '.$ipaddress; - $paiement->ext_payment_id = $TRANSACTIONID; - $paiement->ext_payment_site = $service; + + // Get $customerid and $pkey + $customerid = ''; + if ($paymentIntent instanceof \Stripe\PaymentIntent) { + $customerid = $paymentIntent->customer; + } + $pkey = ''; + if (isset($stripearrayofkeysbyenv[$servicestatus]['publishable_key'])) { + $pkey = $stripearrayofkeysbyenv[$servicestatus]['publishable_key']; + } + + // May be we should store py_... instead of pi_... but we started with pi_... so we continue. + if ($customerid && $pkey) { + $paiement->ext_payment_id = $TRANSACTIONID.':'.$customerid.'@'.$pkey; + } else { + $paiement->ext_payment_id = $TRANSACTIONID; + } + $paiement->ext_payment_site = $service; // 'StripeLive' or 'Stripe', or ... if (!$error) { $paiement_id = $paiement->create($user, 1); // This include closing invoices and regenerating documents @@ -1912,7 +1991,23 @@ if ($ispaymentok) { $paiement->paiementid = $paymentTypeId; $paiement->num_payment = ''; $paiement->note_public = 'Online payment ' . dol_print_date($now, 'standard') . ' from ' . $ipaddress; - $paiement->ext_payment_id = $TRANSACTIONID; // pi_... for Stripe, ... + + // Get $customerid and $pkey + $customerid = ''; + if ($paymentIntent instanceof \Stripe\PaymentIntent) { + $customerid = $paymentIntent->customer; + } + $pkey = ''; + if (isset($stripearrayofkeysbyenv[$servicestatus]['publishable_key'])) { + $pkey = $stripearrayofkeysbyenv[$servicestatus]['publishable_key']; + } + + // May be we should store py_... instead of pi_... but we started with pi_... so we continue. + if ($customerid && $pkey) { + $paiement->ext_payment_id = $TRANSACTIONID.':'.$customerid.'@'.$pkey; + } else { + $paiement->ext_payment_id = $TRANSACTIONID; + } $paiement->ext_payment_site = $service; // 'StripeLive' or 'Stripe', or ... if (!$error) { diff --git a/htdocs/public/stripe/ipn.php b/htdocs/public/stripe/ipn.php index d37e4c85c9e..6aae57116b6 100644 --- a/htdocs/public/stripe/ipn.php +++ b/htdocs/public/stripe/ipn.php @@ -505,12 +505,13 @@ if ($event->type == 'payout.created' && getDolGlobalString('STRIPE_AUTO_RECORD_P $paiement->num_payment = ''; $paiement->note_public = ''; $paiement->note_private = 'Stripe Sepa payment received by IPN service listening webhooks - ' . dol_print_date($now, 'standard') . ' (TZ server) using servicestatus=' . $servicestatus . ($ipaddress ? ' from ip ' . $ipaddress : '') . ' - Transaction ID = ' . $TRANSACTIONID; + $paiement->ext_payment_id = $TRANSACTIONID.':'.$customer_id.'@'.$stripearrayofkeysbyenv[$servicestatus]['publishable_key']; // May be we should store py_... instead of pi_... but we started with pi_... so we continue. $paiement->ext_payment_site = $service; $ispaymentdone = 0; $sql = "SELECT p.rowid FROM ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " WHERE p.ext_payment_id = '".$db->escape($paiement->ext_payment_id)."'"; + $sql .= " WHERE (p.ext_payment_id = '".$db->escape($paiement->ext_payment_id)."' OR p.ext_payment_id = '".$db->escape($TRANSACTIONID)."')"; $sql .= " AND p.ext_payment_site = '".$db->escape($paiement->ext_payment_site)."'"; $result = $db->query($sql); if ($result) { @@ -548,7 +549,7 @@ if ($event->type == 'payout.created' && getDolGlobalString('STRIPE_AUTO_RECORD_P // Search again the payment to see if it is already linked to a bank payment record (We should always find the payment that was created before). $ispaymentdone = 0; $sql = "SELECT p.rowid, p.fk_bank FROM ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " WHERE p.ext_payment_id = '".$db->escape($paiement->ext_payment_id)."'"; + $sql .= " WHERE (p.ext_payment_id = '".$db->escape($paiement->ext_payment_id)."' OR p.ext_payment_id = '".$db->escape($TRANSACTIONID)."')"; $sql .= " AND p.ext_payment_site = '".$db->escape($paiement->ext_payment_site)."'"; $sql .= " AND p.fk_bank <> 0"; $result = $db->query($sql); @@ -595,7 +596,7 @@ if ($event->type == 'payout.created' && getDolGlobalString('STRIPE_AUTO_RECORD_P $sql .= " ON pb.rowid = dp.fk_prelevement_bons"; $sql .= " WHERE dp.fk_facture = ".((int) $invoice_id); $sql .= " AND dp.sourcetype = 'facture'"; - $sql .= " AND dp.ext_payment_id = '".$db->escape($TRANSACTIONID)."'"; + $sql .= " AND (dp.ext_payment_id = '".$db->escape($paiement->ext_payment_id)."' OR dp.ext_payment_id = '".$db->escape($TRANSACTIONID)."')"; $sql .= " AND dp.traite = 1"; $sql .= " AND statut = ".((int) $bon::STATUS_TRANSFERED); // To be sure that it's not already credited $result = $db->query($sql); @@ -887,6 +888,12 @@ if ($event->type == 'payout.created' && getDolGlobalString('STRIPE_AUTO_RECORD_P $amountdispute = $stripe->convertAmount($amountdisputestripe, $currencyCodeType, 1); // In real currency format $statusdispute = $object->status; + $pkey = ''; + if (isset($stripearrayofkeysbyenv[$servicestatus]['publishable_key'])) { + $pkey = $stripearrayofkeysbyenv[$servicestatus]['publishable_key']; + } + $LONGTRANSACTIONID = $TRANSACTIONID.':'.$customer_id.'@'.$pkey; + // Get the amount of fees for the dispute $balance_transactions_array = $object->balance_transactions; $feesstripe = 0; @@ -910,7 +917,8 @@ if ($event->type == 'payout.created' && getDolGlobalString('STRIPE_AUTO_RECORD_P $sql = "SELECT pi.rowid, pi.fk_facture, pi.fk_prelevement_bons, pi.amount, pi.type, pi.traite"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pi"; - $sql .= " WHERE pi.ext_payment_id = '".$db->escape($TRANSACTIONID)."'"; + //$sql .= " WHERE pi.ext_payment_id = '".$db->escape($TRANSACTIONID)."'"; + $sql .= " WHERE (pi.ext_payment_id = '".$db->escape($LONGTRANSACTIONID)."' OR pi.ext_payment_id = '".$db->escape($TRANSACTIONID)."')"; $sql .= " AND pi.ext_payment_site = '".$db->escape($service)."'"; $result = $db->query($sql); diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index 7fa2acd2fdc..42c52e2e593 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -377,7 +377,7 @@ class Stripe extends CommonObject * @param ?CommonObject $object Object to pay with Stripe * @param ?string $customer Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe() * @param ?string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect - * @param int<0,1> $status Status (0=test, 1=live) + * @param int<0,1> $servicestatus Status (0=test, 1=live) * @param int<0,1> $usethirdpartyemailforreceiptemail 1=use thirdparty email for receipt * @param 'automatic'|'manual'|'terminal' $mode Automatic=automatic confirmation/payment when conditions are ok, manual=need to call confirm() on intent, terminal=manual * @param bool $confirmnow False=default, true=try to confirm immediately after create (if conditions are ok) @@ -387,7 +387,7 @@ class Stripe extends CommonObject * @param int $did ID of an existing line into llx_prelevement_demande (Dolibarr intent). If provided, no new line will be created. * @return ?\Stripe\PaymentIntent Stripe PaymentIntent or null if not found and failed to create */ - public function getPaymentIntent($amount, $currency_code, $tag, $description = '', $object = null, $customer = null, $key = null, $status = 0, $usethirdpartyemailforreceiptemail = 0, $mode = 'automatic', $confirmnow = false, $payment_method = null, $off_session = 0, $noidempotency_key = 1, $did = 0) + public function getPaymentIntent($amount, $currency_code, $tag, $description = '', $object = null, $customer = null, $key = null, $servicestatus = 0, $usethirdpartyemailforreceiptemail = 0, $mode = 'automatic', $confirmnow = false, $payment_method = null, $off_session = 0, $noidempotency_key = 1, $did = 0) { global $conf, $user; @@ -395,7 +395,7 @@ class Stripe extends CommonObject $error = 0; - if (empty($status)) { + if (empty($servicestatus)) { $service = 'StripeTest'; } else { $service = 'StripeLive'; @@ -423,26 +423,36 @@ class Stripe extends CommonObject // automatically return the existing payment intent if idempotency is provided when we try to create the new one. // That's why we can comment the part of code to retrieve a payment intent with object id (never mind if we cumulate payment intent with old ones that will not be used) + // Try to retrieve the last paymentintent for invoice, but if it fails, never mind. $sql = "SELECT pi.ext_payment_id, pi.entity, pi.fk_facture, pi.sourcetype, pi.ext_payment_site"; $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pi"; $sql .= " WHERE pi.fk_facture = ".((int) $object->id); $sql .= " AND pi.sourcetype = '".$this->db->escape($object->element)."'"; $sql .= " AND pi.entity IN (".getEntity('societe').")"; $sql .= " AND pi.ext_payment_site = '".$this->db->escape($service)."'"; + $sql .= " ORDER BY rowid DESC"; dol_syslog(get_class($this)."::getPaymentIntent search stripe payment intent for object id = ".$object->id, LOG_DEBUG); + $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); if ($num) { $obj = $this->db->fetch_object($resql); - $intent = $obj->ext_payment_id; - dol_syslog(get_class($this)."::getPaymentIntent found existing payment intent record"); + $ext_payment_intent = $obj->ext_payment_id; + $ext_payment_intent_array = preg_split('/[:@]/', $ext_payment_intent); + + $intent = $ext_payment_intent_array[0]; + $customerindb = (isset($ext_payment_intent_array[1]) ? $ext_payment_intent_array[1] : ''); + $pkeyindb = (isset($ext_payment_intent_array[2]) ? $ext_payment_intent_array[2] : ''); + // TODO Test that $pkeyindb and $customerindb match + + dol_syslog(get_class($this)."::getPaymentIntent found existing payment intent record with intent="+$intent); // Force to use the correct API key global $stripearrayofkeysbyenv; - \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']); + \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus]['secret_key']); try { if (empty($key)) { // If the Stripe connect account not set, we use common API usage @@ -566,7 +576,7 @@ class Stripe extends CommonObject try { // Force to use the correct API key global $stripearrayofkeysbyenv; - \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']); + \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus]['secret_key']); $arrayofoptions = array(); if (empty($noidempotency_key)) { @@ -577,70 +587,87 @@ class Stripe extends CommonObject $arrayofoptions["stripe_account"] = $key; } - dol_syslog(get_class($this)."::getPaymentIntent ".$stripearrayofkeysbyenv[$status]['publishable_key'], LOG_DEBUG); + dol_syslog(get_class($this)."::getPaymentIntent ".$stripearrayofkeysbyenv[$servicestatus]['publishable_key'], LOG_DEBUG); dol_syslog(get_class($this)."::getPaymentIntent dataforintent to create paymentintent = ".var_export($dataforintent, true)); $paymentintent = \Stripe\PaymentIntent::create($dataforintent, $arrayofoptions); - // Store the payment intent - if (is_object($object)) { - $paymentintentalreadyexists = 0; + if ($paymentintent instanceOf \Stripe\PaymentIntent) { + dol_syslog(get_class($this)."::getPaymentIntent paymentintent is a defined object"); - if ($did > 0) { - // If a payment request line provided, we do not need to recreate one, we just update it - dol_syslog(get_class($this)."::getPaymentIntent search if payment intent already in prelevement_demande", LOG_DEBUG); + // Store the payment intent + if (is_object($object)) { + $paymentintentalreadyexists = 0; - $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_demande SET"; - $sql .= " ext_payment_site = '".$this->db->escape($service)."',"; - $sql .= " ext_payment_id = '".$this->db->escape($paymentintent->id)."'"; - $sql .= " WHERE rowid = ".((int) $did); - - $resql = $this->db->query($sql); - if ($resql) { - $paymentintentalreadyexists++; - } else { - $error++; - dol_print_error($this->db); + // Get $customerid and $pkey + $customerid = $paymentintent->customer; + $pkey = ''; + if (isset($stripearrayofkeysbyenv[$servicestatus]['publishable_key'])) { + $pkey = $stripearrayofkeysbyenv[$servicestatus]['publishable_key']; } - } else { - // Check that payment intent $paymentintent->id is not already recorded. - dol_syslog(get_class($this)."::getPaymentIntent search if payment intent already in prelevement_demande", LOG_DEBUG); - $sql = "SELECT pi.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pi"; - $sql .= " WHERE pi.entity IN (".getEntity('societe').")"; - $sql .= " AND pi.ext_payment_site = '".$this->db->escape($service)."'"; - $sql .= " AND pi.ext_payment_id = '".$this->db->escape($paymentintent->id)."'"; + $LONGTRANSACTIONID = $paymentintent->id.':'.$customerid.'@'.$pkey; - $resql = $this->db->query($sql); - if ($resql) { - $num = $this->db->num_rows($resql); - if ($num) { - $obj = $this->db->fetch_object($resql); - if ($obj) { - $paymentintentalreadyexists++; - } + + if ($did > 0) { + // If a payment request line provided, we do not need to recreate one, we just update it + dol_syslog(get_class($this)."::getPaymentIntent search if payment intent already in prelevement_demande", LOG_DEBUG); + + $sql = "UPDATE ".MAIN_DB_PREFIX."prelevement_demande SET"; + $sql .= " ext_payment_site = '".$this->db->escape($service)."',"; + $sql .= " ext_payment_id = '".$this->db->escape($paymentintent->id)."'"; // TODO Save the long transaction id + $sql .= " WHERE rowid = ".((int) $did); + + $resql = $this->db->query($sql); + if ($resql) { + $paymentintentalreadyexists++; + } else { + $error++; + dol_print_error($this->db); } } else { - $error++; - dol_print_error($this->db); - } - } + // Check that payment intent $paymentintent->id is not already recorded. + dol_syslog(get_class($this)."::getPaymentIntent search if payment intent already in prelevement_demande", LOG_DEBUG); - // If not, we create it. - if (!$error && !$paymentintentalreadyexists) { - $now = dol_now(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_demande (date_demande, fk_user_demande, ext_payment_id, fk_facture, sourcetype, entity, ext_payment_site, amount)"; - $sql .= " VALUES ('".$this->db->idate($now)."', ".((int) $user->id).", '".$this->db->escape($paymentintent->id)."', ".((int) $object->id).", '".$this->db->escape($object->element)."', ".((int) $conf->entity).", '".$this->db->escape($service)."', ".((float) $amount).")"; - $resql = $this->db->query($sql); - if (!$resql) { - $error++; - $this->error = $this->db->lasterror(); - dol_syslog(get_class($this)."::PaymentIntent failed to insert paymentintent with id=".$paymentintent->id." into database.", LOG_ERR); + $sql = "SELECT pi.rowid"; + $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_demande as pi"; + $sql .= " WHERE pi.entity IN (".getEntity('societe').")"; + $sql .= " AND pi.ext_payment_site = '".$this->db->escape($service)."'"; + $sql .= " AND (pi.ext_payment_id = '".$this->db->escape($paymentintent->id)."' OR pi.ext_payment_id = '".$this->db->escape($LONGTRANSACTIONID)."')"; + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + if ($num) { + $obj = $this->db->fetch_object($resql); + if ($obj) { + $paymentintentalreadyexists++; + } + } + } else { + $error++; + dol_print_error($this->db); + } } + + // If not, we create it. + if (!$error && !$paymentintentalreadyexists) { + $now = dol_now(); + $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_demande (date_demande, fk_user_demande, ext_payment_id, fk_facture, sourcetype, entity, ext_payment_site, amount)"; + // TODO Save the long transaction id in ext_payment_id + $sql .= " VALUES ('".$this->db->idate($now)."', ".((int) $user->id).", '".$this->db->escape($paymentintent->id)."', ".((int) $object->id).", '".$this->db->escape($object->element)."', ".((int) $conf->entity).", '".$this->db->escape($service)."', ".((float) $amount).")"; + $resql = $this->db->query($sql); + if (!$resql) { + $error++; + $this->error = $this->db->lasterror(); + dol_syslog(get_class($this)."::PaymentIntent failed to insert paymentintent with id=".$paymentintent->id." into database.", LOG_ERR); + } + } + } else { + $_SESSION["stripe_payment_intent"] = $paymentintent; } } else { - $_SESSION["stripe_payment_intent"] = $paymentintent; + dol_syslog(get_class($this)."::getPaymentIntent create paymentintent did not returned a Stripe\PaymentIntent object", LOG_ERR); } } catch (Stripe\Exception\CardException $e) { $error++; @@ -683,12 +710,12 @@ class Stripe extends CommonObject * @param Societe $object Object of company to link the Stripe payment mode with * @param string $customer Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe() * @param string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect - * @param int<0,1> $status Status (0=test, 1=live) + * @param int<0,1> $servicestatus Service status (0=test, 1=live) * @param int<0,1> $usethirdpartyemailforreceiptemail 1=use thirdparty email for receipt * @param bool $confirmnow false=default, true=try to confirm immediately after create (if conditions are ok) * @return \Stripe\SetupIntent|null Stripe SetupIntent or null if not found and failed to create */ - public function getSetupIntent($description, $object, $customer, $key, $status, $usethirdpartyemailforreceiptemail = 0, $confirmnow = false) + public function getSetupIntent($description, $object, $customer, $key, $servicestatus, $usethirdpartyemailforreceiptemail = 0, $confirmnow = false) { global $conf; @@ -698,7 +725,7 @@ class Stripe extends CommonObject $error = 0; - if (empty($status)) { + if (empty($servicestatus)) { $service = 'StripeTest'; } else { $service = 'StripeLive'; @@ -767,9 +794,9 @@ class Stripe extends CommonObject try { // Force to use the correct API key global $stripearrayofkeysbyenv; - \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$status]['secret_key']); + \Stripe\Stripe::setApiKey($stripearrayofkeysbyenv[$servicestatus]['secret_key']); - dol_syslog(get_class($this)."::getSetupIntent ".$stripearrayofkeysbyenv[$status]['publishable_key'], LOG_DEBUG); + dol_syslog(get_class($this)."::getSetupIntent ".$stripearrayofkeysbyenv[$servicestatus]['publishable_key'], LOG_DEBUG); dol_syslog(get_class($this)."::getSetupIntent dataforintent to create setupintent = ".var_export($dataforintent, true)); // Note: If all data for payment intent are same than a previous one, even if we use 'create', Stripe will return ID of the old existing payment intent.