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 <eldy@destailleur.fr>
This commit is contained in:
Erwan-Wiwit 2026-02-17 20:21:35 +01:00 committed by GitHub
parent 26aefd139e
commit 0f397ece1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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));