Init Stripe.js with same API version than StripePaymentElement::init() to ensure consistency

Created on 20 January 2025, 3 months ago

Hi, I just discovered that we did not specify an API Version when using Stripe.js library.
So we use API 2019-12-03 to create the PaymentIntent but when calling confirmPayment() in JS, no API version is specified and the account / dashboard default API version is used!
To make sure the same API Version and is used throughout the process and especially for both PaymentIntent creation and confirmation, we must specify the API Version when initializing Stripe JS.

I see that some work has already been made in that intention by Tom Ashe (tomtech) in commit c41d17427327c78301f1cf6ba4c78350c169f1cd in version 1.2 in commerce_stripe.payment_element.js:

if (settings.apiVersion) {
  stripeOptions.apiVersion = settings.apiVersion;
}
// Create a Stripe client.
const stripe = Stripe(settings.publishableKey, stripeOptions);

However, if I am not mistaken, there is no apiVersion so far in drupalSettings.commerceStripePaymentElement so this code is currently ignored

Since the API Version is hard coded to 2019-12-03 in StripePaymentElement::init(), I suggest we do the same here for consistency.

In the future, if the API Version can be specified in the module settings, the same version should be used for server and client requests.

πŸ“Œ Task
Status

Active

Version

1.2

Component

Payment Element

Created by

πŸ‡«πŸ‡·France nicolas bouteille

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024