A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/stripe/stripe-ruby/wiki/Migration-guide-for-v13 below:

Migration guide for v13 · stripe/stripe-ruby Wiki · GitHub

StripeClient and service-based call pattern

In stripe-ruby v13, we have renamed the StripeClient requestor interface to APIRequestor and repurposed the StripeClient name for a new class as an entry-point to the service-based call pattern. This new interface allows you to easily call Stripe APIs and has several benefits over the existing resource-based pattern:

  1. No global config: you can simultaneously use multiple clients with different configuration options (such as API keys)
  2. No extra API calls. All API endpoints can be accessed with a single method call. You don't have to call retrieve before doing an update.
  3. No static methods results in easier mocking

While there are no plans yet to completely remove the previous resource-based call pattern, it will be deprecated soon and new API endpoints will be supported only in the new pattern. We strongly recommend migrating to the new service-based pattern as you begin to use new APIs. This will help you avoid mixing the two patterns in your integration, which can lead to confusion as you maintain your code.

To migrate from a resource-based to service-based pattern:

  1. Initialize a StripeClient instance. It is required to pass an api key as the first positional argument of StripeClient.

    Before

    Stripe.api_key = "sk_test_123"

    After

    client = Stripe::StripeClient.new("sk_test_123")

    You can also pass in previously configurable global options as keyword arguments into the StripeClient constructor. As of v13.3.1, for configurable options that are not specified or not currently available on StripeClient, we fall back to the global StripeConfiguration.

    Before

    Stripe.api_key = "sk_test_123"
    Stripe.api_version = "2022-11-15"

    After

    client = Stripe::StripeClient.new(
      "sk_test_123",
      stripe_version: "2022-11-15",
    )
  2. Convert class resource method calls to StripeClient calls. Parameters and options are still passed in the same way as in the resource-based pattern. Services are available under either the v1 or v2 accessors.

    Before

    customer = Stripe::Customer.create({email: "jenny.rosen@example.com"}, {stripe_account: "acct_123"})

    After

    customer = client.v1.customers.create({email: "jenny.rosen@example.com"}, {stripe_account: "acct_123"})
  3. Convert instance resource method calls to StripeClient calls.

    Before

    customer = Stripe::Customer.retrieve("cus_123");
    customer.delete();

    After

    client.v1.customers.delete("cus_123");
  4. Convert nested resource operations to StripeClient calls.

    Before

    Stripe::Customer.list_balance_transactions(
      "cus_123",
      {limit: 3},
      {stripe_version: "2022-11-15"}
    )

    After

    customer = client.v1.customers.balance_transactions.list(
      "cus_123",
      {"limit": 3},
      {"stripe_version": "2022-11-15"},
    );

request is still available for StripeClient, though it is deprecated and will be removed in a future version. It is backed by APIRequestor.request, which has the same behavior as in previous versions. We suggest migrating to StripeClient.raw_request and StripeClient.deserialize if you need to make custom requests:

Before

client = StripeClient.new
charge, resp = client.request { Charge.create }

After

client = StripeClient.new("sk_test_123")
resp = client.raw_request(:post, "/v1/charges")
charge = client.deserialize(resp.data)

If you need to pass params and to raw_request, pass them in as keyword arguments:

resp = client.raw_request(
  :post,
  "/v1/charges",
  params: {
    amount: 4242,
    currency: "usd",
    source: tok_visa",
  }, opts: {
    stripe_account: "acct_123"
  })

If you need the raw StripeResponse instead, you can access it via the last_response property on deserialized objects:

charge = client.v1.charges.create(...)
charge.last_response

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4