Introduction to server-side SDKs
Learn how to install and use Stripe's server-side SDKs.
Stripe’s server-side SDKs reduce the amount of work required to use Stripe’s REST APIs. Stripe-maintained SDKs are available for Ruby, PHP, Java, Python, Node, .NET and Go. Community libraries are also available for other server languages.
Installation and setup ![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
Select your language in the language selector below, then follow the instructions to install the SDK.
After completing the installation, you need to initialize Stripe:
Send API requests ![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
There are six main ways to manipulate objects with the Stripe API: create, update, delete, retrieve, list, and search. Here are some examples of this with the Customer object:
API requests can contain different types of parameters. For example, here’s how to create a customer with a name
(a string), address
(an object), and preferred_
(a list):
When updating an object, you can clear some of its properties. For dynamically typed languages, send an empty string. For strongly typed languages, use specific constants. For example, here’s how to clear the name
(a string) and metadata
(a hash of key-value pairs) of a customer:
This example clears all metadata, but you can also clear individual keys. Learn more about managing metadata in our metadata guide.
Access the API response ![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
Every time you make an API request, Stripe sends you back a response.
If you create, retrieve, or update an object, you get back the object itself:
{ "id": "pi_001", "object": "payment_intent", "amount": 1099, "currency": "usd", /* ... */ }
Use a variable to access the properties of that object:
When listing or searching for objects, you get back a List object containing a data
array with the objects requested:
{ "object": "list", "data": [ { "id": "pi_003", "object": "payment_intent", "amount": 4200, "currency": "usd", /* ... */ }, { "id": "pi_002", "object": "payment_intent", "amount": 2100, "currency": "usd", "payment_method_types": [ "link" ], /* ... */ } ], "has_more": true, "url": "/v1/payment_intents" }
Use a loop on the data
array to access the properties of each object:
You could also use auto-pagination to iterate over all the results.
Expanding responses ![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
Some properties are expandable or includable, meaning you can return them by using the expand
parameter. For example:
- Retrieve a PaymentIntent and expand its associated PaymentMethod.
- Retrieve a Checkout Session and include the
line_
property.items
Learn more about expanding responses.
Retrieve the request ID ![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
Each API request has a unique request ID (req_
) associated with it. This is useful to inspect the request in the Dashboard to see the parameters Stripe received, or to share it with Stripe support when facing an issue.
You can find the IDs in your Dashboard logs, or directly with code like this:
Set additional request options ![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
When sending an API requests, you can set additional request options to:
エラー処理![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
Each server SDK interprets error responses from the Stripe API as exception types, so you don’t need to parse the response status yourself. Use error handling conventions appropriate for each language to handle those errors.
Learn more about error handling.
Private preview features ![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
Stripe regularly launches private preview features which introduce new properties or parameters that are not immediately public. Dynamically-typed SDKs (PHP, Node, Ruby, Python) automatically support these. For strongly-typed SDKs (Java, .NET, Go), use the code below, unless they’re supported in a beta release.
Send undocumented parameters:
Access undocumented fields:
Source code![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
The source code for each of our server SDKs is available on GitHub:
言語 | Repository |
---|---|
Ruby | stripe-ruby |
PHP | stripe-php |
Java | stripe-Java |
Node | stripe-node |
Python | stripe-python |
.NET | stripe-dotnet |
Go | stripe-go |
Client & service patterns![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
For some SDKs, we’ve introduced a client/service pattern that changes the way you perform operations. This new service-based pattern allows for easier mocking without static methods and enables multiple client instances to operate simultaneously with distinct configuration.
If you’re comparing code targeting older versions of these libraries with resource-based patterns, the calls might look different.
SDK | Client/Services release | Transition guide |
---|---|---|
stripe-php | 7.33.0 | GitHub Wiki |
stripe-python | 8.0.0 | GitHub Wiki |
ベータバージョン![](https://b.stripecdn.com/docs-statics-srv/assets/fcc3a1c24df6fcffface6110ca4963de.svg)
We offer beta SDKs that are identifiable by the beta
or b
filename suffix, such as 5.
or 5.
. They give you access to products and features in development, and allow you to share feedback with us before their general availability.
Access the beta SDK releases through the readme.
file of the respective GitHub repository.