From 0f397ece1c4cdbef364d1bd2cc86fe59694da1a7 Mon Sep 17 00:00:00 2001 From: Erwan-Wiwit Date: Tue, 17 Feb 2026 20:21:35 +0100 Subject: [PATCH] Add hook beforeCreateStripePaymentIntent in getPaymentIntent() (#37261) Add a hook point in Stripe::getPaymentIntent() to allow external modules to modify the $dataforintent array before the Stripe PaymentIntent::create() API call. This enables modules to customize: - statement_descriptor (e.g. structured communication for SEPA DD) - metadata - description - payment_method_types - and other PaymentIntent parameters The $arrayofoptions (containing stripe_account and idempotency_key) is intentionally NOT exposed for security reasons. Co-authored-by: Laurent Destailleur --- htdocs/stripe/class/stripe.class.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index d33047b9baf..9bc95cc10cf 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -389,7 +389,7 @@ class Stripe extends CommonObject */ 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; + global $conf, $user, $hookmanager; dol_syslog(get_class($this)."::getPaymentIntent description=".$description, LOG_INFO, 1); @@ -585,6 +585,24 @@ class Stripe extends CommonObject $arrayofoptions["stripe_account"] = $key; } + // Hook to allow external modules to modify Stripe PaymentIntent data before API call. + // Can be used to customize statement_descriptor (e.g. structured communication for SEPA), + // add metadata, modify description, etc. + // Note: $arrayofoptions is not passed for security reasons (contains stripe_account and idempotency_key). + $parameters = array( + 'dataforintent' => $dataforintent, + 'object' => $object, + 'tag' => $tag, + 'amount' => $amount, + 'currency_code' => $currency_code, + 'customer' => $customer, + 'servicestatus' => $servicestatus, + ); + $reshook = $hookmanager->executeHooks('beforeCreateStripePaymentIntent', $parameters, $this); + if (!empty($hookmanager->resArray['dataforintent'])) { + $dataforintent = $hookmanager->resArray['dataforintent']; + } + dol_syslog(get_class($this)."::getPaymentIntent ".$stripearrayofkeysbyenv[$servicestatus]['publishable_key'], LOG_DEBUG); dol_syslog(get_class($this)."::getPaymentIntent dataforintent to create paymentintent = ".formatLogObject($dataforintent));