API Libraries

    Stripe has official libraries for different programming languages and mobile platforms. There are also many more third-party libraries and plugins created by the Stripe community.

    Server-side libraries

    # Available as a gem sudo gem install stripe
    # If you use bundler, you can add this line to your Gemfile gem 'stripe'
    # Install through pip pip install --upgrade stripe
    # Or find the Stripe package on http://pypi.python.org/pypi/stripe/
    # Install the PHP library via Composer composer require stripe/stripe-php
    # Or download the source directly: https://github.com/stripe/stripe-php/releases
    /* For Gradle, add the following dependency to your build.gradle and replace {VERSION} with the version number you want to use from - https://mvnrepository.com/artifact/com.stripe/stripe-java or - https://github.com/stripe/stripe-java/releases/latest */ implementation "com.stripe:stripe-java:{VERSION}"
    <!-- For Maven, add the following dependency to your POM and replace {VERSION} with the version number you want to use from - https://mvnrepository.com/artifact/com.stripe/stripe-java or - https://github.com/stripe/stripe-java/releases/latest --> <dependency> <groupId>com.stripe</groupId> <artifactId>stripe-java</artifactId> <version>{VERSION}</version> </dependency>
    # For other environments, manually install the following JARs: # - The Stripe JAR from https://github.com/stripe/stripe-java/releases/latest # - Google Gson from https://github.com/google/gson
    # Install via npm npm install --save stripe
    # Install via go go get github.com/stripe/stripe-go
    // Then import the package import ( "github.com/stripe/stripe-go" )
    # Install via dotnet dotnet add package Stripe.net dotnet restore
    # Or install via NuGet PM> Install-Package Stripe.net

    For more details, check out the API reference or see the source on GitHub.

    Client-side libraries

    Use Stripe on the web with Elements, a set of prebuilt UI components for collecting and validating card details. Elements uses Stripe.js, our foundational JavaScript library for building payment flows.

    Include the Stripe.js script on your checkout page by adding it to the head of your HTML file:

    <head> <title>Checkout</title> <script src="https://js.stripe.com/v3/"></script> </head>

    Create an instance of Elements with the following JavaScript on your checkout page:

    // Set your publishable key: remember to change this to your live publishable key in production // See your keys here: https://dashboard.stripe.com/account/apikeys var stripe = Stripe('pk_test_TYooMQauvdEDq54NiTphI7jx'); var elements = stripe.elements();

    Now you can use Elements to create payment forms with prebuilt input fields to collect payment method details. See accept a payment for detailed instructions.

    Install @stripe/react-stripe-js and @stripe/stripe-js:

    npm install --save @stripe/react-stripe-js @stripe/stripe-js

    Add Stripe.js and Elements to your page

    To use Element components, wrap the root of your React app in an Elements provider. Call loadStripe with your publishable key and pass the returned Promise to the Elements provider.

    import React from 'react'; import ReactDOM from 'react-dom'; import {Elements} from '@stripe/react-stripe-js'; import {loadStripe} from '@stripe/stripe-js'; import CheckoutForm from './CheckoutForm'; // Make sure to call `loadStripe` outside of a component’s render to avoid // recreating the `Stripe` object on every render. const stripePromise = loadStripe("pk_test_TYooMQauvdEDq54NiTphI7jx"); function App() { return ( <Elements stripe={stripePromise}> <CheckoutForm /> </Elements> ); }; ReactDOM.render(<App />, document.getElementById('root'));

    Now you can use Elements to create payment forms with prebuilt input fields to collect payment method details.

    The iOS SDK is open source, fully documented, and compatible with apps supporting iOS 10 or above.

    1. If you haven't already, install the latest version of CocoaPods.
    2. If you don't have an existing Podfile, run the following command to create one:
      pod init
    3. Add this line to your Podfile:
      pod 'Stripe'
    4. Run the following command:
      pod install
    5. Don't forget to use the .xcworkspace file to open your project in Xcode, instead of the .xcodeproj file, from here on out.
    6. In the future, to update to the latest version of the SDK, just run:
      pod update Stripe
    1. If you haven't already, install the latest version of Carthage.
    2. Add this line to your Cartfile:
      github "stripe/stripe-ios"
    3. Follow the Carthage installation instructions.
    4. In the future, to update to the latest version of the SDK, run the following command:
      carthage update stripe-ios --platform ios
    1. Head to our GitHub releases page and download and unzip Stripe.framework.zip.
    2. Drag Stripe.framework to the "Embedded Binaries" section of your Xcode project's "General" settings. Make sure to select "Copy items if needed".
    3. Head to the "Build Phases" section of your Xcode project settings, and create a new "Run Script Build Phase". Paste the following snippet into the text field:
      bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/Stripe.framework/integrate-dynamic-framework.sh"
    4. In the future, to update to the latest version of our SDK, just repeat steps 1 and 2.

    When your app starts, configure the SDK with your Stripe publishable key so that it can make requests to the Stripe API.

    import UIKit import Stripe @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { Stripe.setDefaultPublishableKey("pk_test_TYooMQauvdEDq54NiTphI7jx") // do any other necessary launch configuration return true } }
    #import "AppDelegate.h" #import <Stripe/Stripe.h> @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [Stripe setDefaultPublishableKey:@"pk_test_TYooMQauvdEDq54NiTphI7jx"]; // do any other necessary launch configuration return YES; } @end

    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:14.0.0' }

    Configure the SDK with your Stripe publishable key so that it can make requests to the Stripe API, such as in your Application subclass:

    import com.stripe.android.PaymentConfiguration class MyApp: Application() { override fun onCreate() { super.onCreate() PaymentConfiguration.init( applicationContext, "pk_test_TYooMQauvdEDq54NiTphI7jx" ) } }
    import com.stripe.android.PaymentConfiguration; public class MyApp extends Application { @Override public void onCreate() { super.onCreate(); PaymentConfiguration.init( getApplicationContext(), "pk_test_TYooMQauvdEDq54NiTphI7jx" ); } }

    Upgrading your client library

    Minor updates to our libraries are backwards compatible and are generally safe to upgrade. Major updates often include breaking changes, which may require changes to your code to upgrade. A new major version is sometimes required if you plan to use a new feature not present in the version of the library you’re currently using.

    For client libraries in dynamic languages (Ruby, Python, PHP, and Node.js), any client library version can be used with any API version.

    Client libraries in static languages (Java, Go, and .NET) are pinned to a specific API version. If you use webhooks you’ll need to create webhook endpoints with API versions that match the pinned API version in the library.

    Upgrading client libraries for Java, Go, or .NET

    During the upgrade process, you should create and maintain two webhook endpoints with two different API versions: one for your existing API version, and one for the API version that you want to upgrade to. This allows you to test your new code while maintaining the ability to safely roll back to your existing version if needed.

    curl https://api.stripe.com/v1/webhook_endpoints \ -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \ -d url="https://example.com/my/webhook/endpoint" \ -d "enabled_events[]"="payment_intent.succeeded" \ -d "enabled_events[]"="payment_intent.payment_failed" \ -d api_version=2019-03-14
    # Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' Stripe::WebhookEndpoint.create({ url: 'https://example.com/my/webhook/endpoint', enabled_events: ['payment_intent.succeeded', 'payment_intent.payment_failed'], api_version: '2019-03-14', })
    # Set your secret key. Remember to switch to your live secret key in production! # See your keys here: https://dashboard.stripe.com/account/apikeys stripe.api_key = 'sk_test_4eC39HqLyjWDarjtT1zdp7dc' stripe.WebhookEndpoint.create( url='https://example.com/my/webhook/endpoint', enabled_events=['payment_intent.succeeded', 'payment_intent.payment_failed'], api_version='2019-03-14', )
    // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys \Stripe\Stripe::setApiKey('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); StripeWebhookEndpoint::create([ 'url' => 'https://example.com/my/webhook/endpoint', 'enabled_events' => ['payment_intent.succeeded', 'payment_intent.payment_failed'], 'api_version' => '2019-03-14' ]);
    // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys Stripe.apiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; Map<String, Object> webhookendpointParams = new HashMap<String, Object>(); webhookendpointParams.put("url", "https://example.com/my/webhook/endpoint"); webhookendpointParams.put("enabled_events", Arrays.asList("payment_intent.succeeded", "payment_intent.payment_failed")); webhookendpointParams.put("api_version", "2019-03-14"); WebhookEndpoint.create(webhookendpointParams);
    // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys const stripe = require('stripe')('sk_test_4eC39HqLyjWDarjtT1zdp7dc'); const webhookEndpoint = await stripe.webhookEndpoints.create({ url: 'https://example.com/my/webhook/endpoint', enabled_events: ['payment_intent.succeeded', 'payment_intent.payment_failed'], api_version: '2019-03-14', });
    // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc" params := &stripe.WebhookEndpointParams{ URL: stripe.String("https://example.com/my/webhook/endpoint"), EnabledEvents: stripe.StringSlice([]string{ "payment_intent.succeeded", "payment_intent.payment_failed", }), APIVersion: stripe.String("2019-03-14"), } we, err := webhookendpoint.New(params)
    // Set your secret key. Remember to switch to your live secret key in production! // See your keys here: https://dashboard.stripe.com/account/apikeys StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"; var options = new WebhookEndpointCreateOptions { Url = "https://example.com/my/webhook/endpoint", EnabledEvents = new List<String> { "payment_intent.succeeded", "payment_intent.payment_failed", }, ApiVersion = "2019-03-14", }; var service = new WebhookEndpointService(); var webhookEndpoint = service.Create(options);
    1. Write your new event handling code using the version of the library you want to upgrade to. When handling incoming events, store the raw body of the request from Stripe in a queue that is processed sequentially
    2. Create a new webhook endpoint with the API version you’re upgrading to and point it at your new code.
    3. Test your new event handling code.
    4. When you’re confident your new code works as intended, you can start processing events with your new code and disable or delete your old webhook endpoint.

    If you’re not using an event queue, you can modify your old code to stop processing events and respond with a 400 HTTP status code. Then, if the new code isn’t working as expected and you need to revert to the old code, you can turn the event processing logic back on and have it respond normally again. As long as you do so within the three day window, you’ll get all the events retried, and not miss any.

    Community Libraries

    Find some of the many community-supported libraries available for Stripe listed below.

    Plugins for third-party services

    Want to make an existing tool better with Stripe? Here are some plugins to help you get started without any programming needed.

    Developed by Stripe

    Developed by the community

    Implemented your own library or an example you'd like to share? Send a link to your code and we'll be happy to add it to the list!

    Was this page helpful?

    Feedback about this page?

    Thank you for helping improve Stripe's documentation. If you need help or have any questions, please consider contacting support.

    On this page