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.

Command icon 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

nicolas bouteille created an issue. See original summary.

tomtech’s picture

Title: Init Stripe.js with same API version than StripePaymentElement::init() to ensure consistency » Stripe API Version should be consistent and configurable
Version: 8.x-1.2 » 2.x-dev
Assigned: Unassigned » tomtech

  • bfa168e1 committed on 2.x
    Issue #3500834 by nicolas bouteille, tomtech: Stripe API Version should...
tomtech’s picture

Status: Active » Fixed

API version has been reworked. There is now a getter (getApiVersion()) for it, that is used for both the SDK and the js initialization.

api_version has 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.)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.