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.
Issue fork commerce_stripe-3500834
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
tomtech commentedComment #5
tomtech commentedAPI version has been reworked. There is now a getter (
getApiVersion()) for it, that is used for both the SDK and the js initialization.api_versionhas been added to the configuration schema, and can be set.NOTE: While the api_version is now part of the config schema and can be set, it has NOT been added to the gateway UX at this time. Changing API version is an advanced change. Providing an invalid API version will cause exceptions. Even when a valid API version is provided, payloads returned may be different which may cause unexpected behavior, or exceptions. (This MR addresses one such case.)