SDKs overview

Stripe offers a suite of official SDKs designed to facilitate integration with its payment processing platform. These libraries abstract away the complexities of direct HTTP requests, handling tasks such as request signing, error handling, and data serialization. The primary goal of Stripe's SDKs is to provide a consistent and idiomatic interface for interacting with the Stripe API across various programming languages. This approach allows developers to focus on application logic rather than low-level API communication details.

The SDKs are maintained by Stripe and are kept up-to-date with the latest API versions and features. They typically include methods for creating and managing customers, charges, subscriptions, invoices, and other core Stripe resources. Beyond simplifying API calls, some SDKs also provide client-side components for securely collecting sensitive payment information, such as card numbers, directly from users without it touching the developer's servers, adhering to PCI DSS compliance standards.

While the official SDKs cover the most common use cases, the Stripe ecosystem also benefits from community-contributed libraries. These community projects often extend functionality, provide integrations with specific frameworks, or offer alternative language support for niche requirements. Developers should evaluate both official and community options based on their project's specific needs, maintenance considerations, and security requirements.

Official SDKs by language

Stripe provides official SDKs for a range of popular programming languages, ensuring broad compatibility for developers. These SDKs are actively maintained and supported by Stripe, offering reliability and up-to-date functionality. Each SDK is designed to be idiomatic to its respective language, providing a natural development experience.

Language Package/Module Name Maturity Documentation Link
JavaScript (Node.js & Browser) stripe-node, @stripe/stripe-js Stable Stripe Node.js SDK documentation
Python stripe Stable Stripe Python SDK documentation
Ruby stripe Stable Stripe Ruby SDK documentation
PHP stripe/stripe-php Stable Stripe PHP SDK documentation
Go github.com/stripe/stripe-go Stable Stripe Go SDK documentation
Java com.stripe:stripe-java Stable Stripe Java SDK documentation
C# (.NET) Stripe.net Stable Stripe .NET SDK documentation

Installation

Installing Stripe's official SDKs typically involves using the standard package manager for each respective programming language. Below are common installation commands for the officially supported SDKs:

JavaScript (Node.js and Browser)

For Node.js environments:

npm install stripe
# or
yarn add stripe

For client-side browser usage, Stripe provides @stripe/stripe-js, which is typically loaded via a script tag or npm. This library helps with securely collecting payment details on the frontend. More details are available in the Stripe.js documentation.

Python

pip install --upgrade stripe

Ruby

Add to your Gemfile:

gem 'stripe'

Then run:

bundle install

PHP

Using Composer:

composer require stripe/stripe-php

Go

go get github.com/stripe/stripe-go/v72

Note: The version number (e.g., v72) should match the latest major version of the Go SDK. Refer to the official Go SDK documentation for the most current version.

Java

For Maven:

<dependency>
  <groupId>com.stripe</groupId>
  <artifactId>stripe-java</artifactId>
  <version>24.2.0</version> <!-- Replace with the latest version -->
</dependency>

For Gradle:

implementation 'com.stripe:stripe-java:24.2.0' // Replace with the latest version

Check the Java SDK documentation for the latest version number.

C# (.NET)

Using NuGet:

Install-Package Stripe.net

Or via .NET CLI:

dotnet add package Stripe.net

Quickstart example

This example demonstrates how to create a charge using the Node.js SDK. It assumes you have your Stripe secret key configured as an environment variable (STRIPE_SECRET_KEY) and have already installed the stripe package.

const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);

async function createCharge() {
  try {
    const charge = await stripe.charges.create({
      amount: 2000, // Amount in cents (e.g., $20.00)
      currency: 'usd',
      source: 'tok_visa', // Replace with a real token from Stripe.js or test token
      description: 'Example charge for a product',
    });
    console.log('Charge successful:', charge);
  } catch (error) {
    console.error('Error creating charge:', error.message);
  }
}

createCharge();

This example uses a test token (tok_visa) which is suitable for development and testing. In a production environment, you would obtain a payment token from your frontend using Stripe.js after a user enters their payment details. For a complete guide on integrating Stripe payments, refer to the Stripe Payments quickstart guide.

Community libraries

Beyond the official offerings, the Stripe developer community has contributed various libraries and integrations that extend functionality or provide support for additional languages and frameworks. These community-driven projects can offer specialized tools, such as wrappers for specific web frameworks, analytics integrations, or alternative client implementations.

Examples of areas where community libraries often emerge include:

  • Framework-specific integrations: Libraries that simplify integrating Stripe with popular web frameworks like Django, Ruby on Rails, Laravel, or various JavaScript frameworks. These might provide pre-built components or abstract common patterns.
  • GraphQL support: While Stripe's official API is RESTful, community libraries might offer GraphQL layers or clients to interact with Stripe resources using a GraphQL query language, as detailed by the GraphQL specification.
  • Additional language support: For languages not officially supported by Stripe, such as Rust, Elixir, or Dart, community members often develop and maintain their own SDKs. Developers should verify the maintenance status and security practices of such libraries before use.
  • Payment UI components: Beyond Stripe.js, some community projects offer more opinionated or framework-specific UI components to streamline the payment form creation process.

When considering a community library, it is advisable to:

  • Check the project's activity and last update date on platforms like GitHub.
  • Review the documentation and examples.
  • Examine the issue tracker for unresolved bugs or security concerns.
  • Assess the community support available for the library.
  • Ensure compatibility with the desired Stripe API version.

The Stripe documentation on libraries often lists popular community options or provides guidance on how to find them. Developers can also explore public repositories on GitHub by searching for "Stripe" along with their preferred language or framework.