How to change the Stripe API version for testing, etc.

We are running an old Rails application that uses Stripe, but our version of Stripe is 26 months behind the current API. We strive to move to the current Stripe API, but since many changes will affect our system, we would really like to check these changes before we change the Live API that our site uses.

I have two questions:

1) When working with the API, we rely heavily on the difference between the Live and Test modes. Is there a way to update only the testing mode API (without updating the Live) so that we can identify and fix any breakdowns without disturbing the user?

2) Is it possible to update the API one version at a time, and not in different ways, to make the transition more convenient for us?

+5
source share
2 answers

This is extremely poorly documented, but it turns out that you can change the Stripe API version to whatever version you want for each request by setting it Stripe.api_version = 'YYYY-MM-DD'before using the Ruby bindings before sending the request ( https://stripe.com/docs/api/ruby# versioning ) or by sending an HTTP header Stripe-Version.

So, we plan to configure our specifications to use the latest version of the API for all requests and test it this way.

+12
source

Below is a one-way way to override the Stripe version at a detailed level in your code.

Stripe.api_version Stripe.api_version , , . Stripe.api_version HTTP- Stripe-Version lib/stripe.rb.

, Stripe Gem 1.58.0 :

config/initializers/stripe_api_version_overrider.rb :

module StripeAPIVersionOverrider
  def api_version
    Thread.current[:__stripe_api_version_override] || super
  end

  def with_api_version(version, &block)
    original_version = api_version
    Thread.current[:__stripe_api_version_override] = version
    block.call
  ensure
    Thread.current[:__stripe_api_version_override] = original_version
  end
end

Stripe.singleton_class.prepend(StripeAPIVersionOverrider)

, , Stripe API, , Stripe.with_api_version:

Stripe.with_api_version "2016-07-06" do
  # API versions prior to 2016-07-06 did not support
  # retrieving canceled subscriptions.
  Stripe::Subscription.retrieve(subscription_id)
end

bin/spring stop .

0

All Articles