Development quickstart
Integrating Stripe into your app can begin as soon as you create a Stripe account, and takes about five minutes to set up your development environment:
- Send and receive test data as you build
- Install a Stripe library to call Stripe APIs
- Add your API secret key to your server-side code
- Get a test credit card to use in your API request
- Send an API request with the test card to confirm everything works
Use your secret key to call Stripe APIs
All accounts have a total of four keys: a publishable and secret key pair for test mode and live mode. Stripe APIs use your secret key to authenticate requests on your server. By default, your account’s secret keys can be used to perform any API request without restriction. You can find your keys on the API Keys page in the Developers Dashboard.
Stripe automatically populates code examples in our documentation with your test API keys while you’re logged in—only you can see these values. For your convenience, your test API keys for your account are:
Type | Value | When to use |
---|---|---|
Publishable | pk_test_TYooMQauvdEDq54NiTphI7jx | On the client-side. Can be publicly-accessible in your web or mobile app’s client-side code (such as checkout.js) to tokenize payment information such as with Stripe Elements. By default, Stripe Checkout tokenizes payment information. |
Secret | sk_test_4eC39HqLyjWDarjtT1zdp7dc | On the server-side. Must be secret and stored securely in your web or mobile app’s server-side code (such as in an environment variable or credential management system) to call Stripe APIs. |
Use only your test API keys for testing and development. This ensures that you don’t accidentally modify your live customers or charges.
If you can’t see your secret API keys in the Dashboard, this means you don’t have access to them. Contact your Stripe account’s owner and ask to be added to their team as a developer.
Install a Stripe library
The server-side Stripe client libraries allow you to interact with Stripe APIs from your code. The libraries provide helpful methods for interacting with Stripe resources, such as your Stripe customers, products, and payments. For example, to use the “create” operation for the PaymentIntent API in Python, you’d use stripe.PaymentIntent.create()
with your request parameters, and receive a PaymentIntent response object for your API version.
Libraries
iOS SDK
The iOS SDK is open source, fully documented, and compatible with apps supporting iOS 11 or above.
For details on the latest SDK release and past versions, see the Releases page on GitHub. To receive notifications when a new release is published, watch releases for the repository.
When your app starts, configure the SDK with your Stripe publishable key so that it can make requests to the Stripe API.
Android SDK
The Android SDK is open source and fully documented.
To install the SDK, add stripe-android
to the dependencies
block of your app/build.gradle
file:
apply plugin: 'com.android.application' android { ... } dependencies { // ... // Stripe Android SDK implementation 'com.stripe:stripe-android:20.1.0' }
For details on the latest SDK release and past versions, see the Releases page on GitHub. To receive notifications when a new release is published, watch releases for the repository.
Configure the SDK with your Stripe publishable key so that it can make requests to the Stripe API, such as in your Application
subclass:
There are also many third-party libraries created by the Stripe community so you can use a language we don’t officially support.
Start the payment flow
Let’s say a new customer purchases a product in your app. As soon as you know the payment amount, create the customer, and optionally save the customer payment details in Stripe. This allows a customer to use a saved payment method in your app. The following example shows how to Create a customer, then pass the customer identifier and save the payment method by passing setup_future_usage
to Create a PaymentIntent. If your app doesn’t charge customers right away, see The SetupIntents API. We’ve pre-filled these code examples with your test secret API key—only you can see this value.
- Create a customer and save the customer identifier from the response in
id
(for example,cus_Kc9ph4bLXyngqA
).
- Create a PaymentIntent with the customer identifier, and pass
on_session
tosetup_future_usage
. Anon_session
value indicates the customer is in the checkout flow of your app. Anoff_session
value indicates the customer has exited out of your app.
To learn more about this payment flow, see The PaymentIntents API.
Collect payment information
You need to create a checkout page to collect customer payment information. You can use a prebuilt Stripe-hosted solution, or build a custom payment flow on the server-side using embeddable Stripe UI components. For a list of all payment integrations, such as creating a subscription, see the Payments guide.
Don’t code? Use Stripe’s no-code options to collect payment.
Integration | Branding | Payments | Description |
---|---|---|---|
Prebuilt checkout page with client-side and server-side code. Can use it for web apps. | Supports basic customization to match your brand. | Built-in support for one-time, subscription, and future payments for the payment methods you support. | Uses Stripe Checkout. A Stripe-hosted payment form to collect customer payment details and confirm payment, that redirects to your success page after payment. Conversion optimized, localized in supported languages, built-in Tax support, coupons, adjustable quantities, billing and shipping address collection. |
Custom payment flow with client-side code (only). Can use it for web and mobile apps. | Supports fully-customized branding. | Built-in support for one-time, subscription, and future payments for the payment methods you support. | Uses Stripe Elements. A customizable client-side payment form you can use with your server-side code to collect customer payment details. You need to build the server-side code to create a PaymentIntent, collect payment details, confirm payment, and redirect to your success page after payment. |
Alternatively, you can use the Stripe CLI to call Stripe APIs in test mode directly from your terminal.
Test your payment integration
Stripe returns HTTP response codes to indicate the success or failure of your API requests. If you have any immediate errors (for example, a declined card), show the error message to your customer so they can try again. Use Stripe’s test credit card numbers to test the response handling of your payment integration. Start with a successful payment to make sure everything works. The payment status
in these examples is returned in the Create a PaymentIntent response payload.
We’ve provided some of the more common test card scenarios for your convenience. Use them with any CVC, postal code, and future expiration date:
Number | HTTP code | Payment status | Description | Next steps |
---|---|---|---|---|
4242424242424242 | 200 - OK | succeeded | The card payment succeeds and doesn’t require authentication. | Redirect the customer to your success page. |
4000002760003184 | 200 - OK | requires_action | The card payment requires Strong Customer Authentication (SCA) for the initial payment and subsequent payments. | Display the 3DS authentication modal so the customer can authenticate and authorize their payment. To learn more, see How intents work. |
4000000000009995 | 402 - Request Failed | incorrect_number | The card payment fails due to an incorrect credit card number. | Ask the customer to enter their card again, or try a new credit card number. |
Handle order fulfillment
When you call Stripe APIs, Stripe logs the API call and events that represent this activity. You can view logs and event activity in the Developers Dashboard, or stream logs and events using the Stripe CLI or the Stripe for Visual Studio Code extension. Use incoming webhooks to receive these real-time events in your app. This allows your app to programmatically handle the order fulfillment flow, and any errors that can occur.
Stripe triggers a set of events in response to the Create a session API call for the Prebuilt Checkout page. Here are the typical one-time payment (not recurring) events that the checkout flow triggers.
When events occur | Events |
---|---|
When your customer clicks the Checkout button in your app. | Triggers the payment_intent.created event. |
When your customer clicks the Pay button in the Stripe Checkout URL. | Triggers the payment_intent.succeeded , charge.succeeded , customer.created events. Note: the charge.succeeded event is triggered when a charge transaction is successfully recorded, not when the customer payment succeeded. |
When your customer’s payment is successful and they’re redirected to your Success page. | Triggers the checkout.session.completed event with a payment_status of paid in the event object payload. |
To test a webhooks integration with the CLI, see Test a webhooks integration with the Stripe CLI.
Sign up for updates
After you send your first API request, Stripe assigns the latest API version to your account. This means all subsequent calls to Stripe APIs and your webhook event object payloads are shaped by this version, unless you specify a different version. You can find your default API version on the Developers Dashboard.
Stripe periodically releases new versions. Sign up for the Developer Digest to receive emails on the latest updates.