-
Notifications
You must be signed in to change notification settings - Fork 391
Migration guide for v23
pakrym-stripe edited this page Aug 16, 2023
·
11 revisions
StripeClient and the new service-based pattern is introduced. StripeClient has multiple benefits over existing resource-based patterns:
- Allows to have multiple clients with different connection options (different API keys).
- All operations can be performed in a single HTTP call.
// Before: creating funding instructions takes two HTTP calls Customer customer = Customer.retrieve("cus_123"); // HTTP call 1 customer.createFundingInstructions(..); // HTTP call 2 // After: creating funding instructions is a single HTTP call StripeClient client = new StripeClient(); client.customers().createFundingInstructions("cus_123", ...); // HTTP call 1
-
StripeClientis easier to mock for testing as all methods are instance methods.
To migrate from resource-based to service-based pattern:
- Initialize a
StripeClientinstance.// Before Stripe.apiKey = "sk_test_123" // After StripeClient client = new StripeClient("sk_test_123");
- Convert static resource method calls to
StripeClientcalls:// Before Customer customer = Customer.retrieve("cus_123"); // After client.customers().retrieve("cus_123");
- Convert instance resource method calls to
StripeClientcalls. Params classes will, in most cases, stay the same as you used for resource-based calls.// Before Customer customer = Customer.retrive("cus_123"); customer.delete(); // After client.customers().delete("cus_123"); // After client.customers().delete(customer.id); PaymentMethod pm = client.customers().retrievePaymentMethod(customer.id, "pm_123");
-
RequestOptions.getReadTimeout(),getConnectTimeout(),getMaxNetworkRetries()now returnIntegerinstead ofint. -
RequestOptions.getDefault()does not apply global configuration options fromStripeclass, all fields are initialized tonull. -
RequestOptionsBuilderdoes not apply global configuration options fromStripeclass, all fields are initialized tonull. -
StripeResponseGetter.oauthRequest(...)was removed. OAuth requests are now performed viaStripeResponseGetter.requestwithApiMode.OAuth. -
StripeResponseGetter.request(...),streamRequest(...)signatures changed.-
BaseAddressparameter added. -
urlrenamed topathand is a relative to the base address -
apiModeparameter added to control how request is sent and response is handled,V1andOAuthare supported values.
-
- Deprecated
ApiResource.className()singleClassUrl(),classUrl(),instanceUrl(),subresourceUrl()methods removed. -
ApiResource.request(),requestStream(),requestCollection(),requestSearchResult()methods removed.