SDKs overview
Stripe Billing provides a suite of official software development kits (SDKs) designed to facilitate interaction with its API for managing subscriptions, invoices, and recurring payments. These SDKs abstract the underlying HTTP requests and responses, allowing developers to focus on application logic rather than low-level API communication. The official SDKs are available for a range of popular programming languages, ensuring broad compatibility for development teams. In addition to official support, a developer community contributes third-party libraries and tools that can extend or complement Stripe's offerings.
Integrating Stripe Billing functions, such as creating subscriptions, managing customer payment methods, or processing one-off invoices, typically involves using a secret API key for authenticated server-side requests and a publishable API key for client-side operations, such as tokenizing payment information. The SDKs handle the secure transmission of these keys and the construction of API requests according to the Stripe API specification.
Official SDKs by language
Stripe maintains official SDKs for several programming languages, which are consistently updated to support new API features and ensure compatibility. These SDKs are the recommended method for integrating Stripe Billing functionality due to their comprehensive coverage of the API, active maintenance, and direct support from Stripe.
| Language | Package/Module | Installation Command | Maturity |
|---|---|---|---|
| Python | stripe |
pip install stripe |
Stable, Actively Maintained |
| Ruby | stripe |
gem install stripe |
Stable, Actively Maintained |
| Java | stripe-java |
Maven: <dependency><groupId>com.stripe</groupId><artifactId>stripe-java</artifactId><version>24.x.x</version></dependency>Gradle: implementation 'com.stripe:stripe-java:24.x.x' |
Stable, Actively Maintained |
| Node.js | stripe |
npm install stripe or yarn add stripe |
Stable, Actively Maintained |
| Go | stripe-go |
go get github.com/stripe/stripe-go/v72 |
Stable, Actively Maintained |
| PHP | stripe/stripe-php |
composer require stripe/stripe-php |
Stable, Actively Maintained |
| C# (.NET) | Stripe.net |
Install-Package Stripe.net (NuGet) |
Stable, Actively Maintained |
| CLI | stripe-cli |
brew install stripe/stripe-cli/stripe (macOS) or refer to Stripe CLI installation instructions |
Stable, Actively Maintained |
For the most current version numbers and detailed installation instructions, developers should always refer to the official Stripe documentation for SDKs.
Installation
Installation procedures for Stripe Billing SDKs follow standard practices for each respective programming language ecosystem. Below are general guidelines for common languages:
- Python: Use
pip, the Python package installer. Ensure you have a recent version of Python and pip installed. The commandpip install stripefetches the latest official Stripe Python library. - Ruby: Use RubyGems. The command
gem install stripeinstalls the Stripe Ruby gem. RubyGems is Ruby's standard package manager. - Java: For Java projects, manage dependencies using Maven or Gradle. The Stripe Java library is available on Maven Central. Developers add the appropriate dependency entry in their
pom.xmlorbuild.gradlefile. - Node.js: Utilize npm (Node Package Manager) or Yarn. The command
npm install stripeoryarn add stripeadds the Stripe Node.js library to your project. - Go: Go modules handle dependency management. The command
go get github.com/stripe/stripe-go/v72(version may vary) retrieves the Go SDK. - PHP: Composer is the dependency manager for PHP. Run
composer require stripe/stripe-phpto include the Stripe PHP library in your project. - C# (.NET): NuGet is the package manager for .NET. Use the Package Manager Console command
Install-Package Stripe.netor search for "Stripe.net" in the NuGet Package Manager UI. - CLI: The Stripe CLI offers direct command-line access to Stripe APIs. Installation varies by operating system; for macOS, Homebrew is commonly used (
brew install stripe/stripe-cli/stripe). Other platforms have specific instructions detailed in the Stripe CLI documentation.
After installation, the SDKs typically require configuration with your Stripe API keys. It is best practice to load secret API keys from environment variables rather than hardcoding them into your application, enhancing security. For example, in Node.js, you might set const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);.
Quickstart example
The following example demonstrates how to create a new customer and then subscribe them to a product with a recurring price using the Stripe Billing Node.js SDK. This snippet assumes you have installed the SDK and set your STRIPE_SECRET_KEY environment variable.
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
async function createSubscription() {
try {
// 1. Create a Customer
const customer = await stripe.customers.create({
email: '[email protected]',
description: 'New customer for monthly plan',
});
console.log('Customer created:', customer.id);
// 2. Create a Product (if not already existing)
// In a real application, you'd likely retrieve an existing product ID
const product = await stripe.products.create({
name: 'Basic Plan',
description: 'Monthly subscription for basic features',
type: 'service',
});
console.log('Product created:', product.id);
// 3. Create a Price for the Product (if not already existing)
// In a real application, you'd likely retrieve an existing price ID
const price = await stripe.prices.create({
unit_amount: 1000, // $10.00
currency: 'usd',
recurring: { interval: 'month' },
product: product.id,
});
console.log('Price created:', price.id);
// 4. Create a Subscription for the Customer to the Price
const subscription = await stripe.subscriptions.create({
customer: customer.id,
items: [{
price: price.id,
}],
payment_behavior: 'default_incomplete',
expand: ['latest_invoice.payment_intent'],
});
console.log('Subscription created:', subscription.id);
// Handle subscription status, e.g., prompt for payment if incomplete
if (subscription.latest_invoice.payment_intent.status === 'requires_action') {
console.log('Requires action, redirect customer to complete payment.');
} else if (subscription.status === 'active') {
console.log('Subscription is active.');
}
return subscription;
} catch (error) {
console.error('Error creating subscription:', error.message);
// For specific error handling, refer to Stripe's error codes
// in the official documentation.
throw error;
}
}
createSubscription();
This quickstart illustrates the fundamental steps: creating a customer, defining a product and its price, and then linking them into a subscription. More complex scenarios involving usage-based billing, trials, or promotions are also supported by the Stripe Subscriptions API and its SDKs.
Community libraries
While Stripe provides and maintains a comprehensive set of official SDKs, the developer community also contributes various libraries and tools that can enhance or specialize Stripe Billing integrations. These community-driven projects can offer:
- Framework-specific integrations: Libraries tailored for specific web frameworks (e.g., Django, Ruby on Rails, Laravel), simplifying integration into existing application architectures.
- Client-side components: UI libraries or components for popular frontend frameworks (React, Vue, Angular) that interact with Stripe.js to handle payment element rendering and tokenization securely. Stripe's own Stripe.js library is the primary tool for client-side interactions, but community efforts may build on top of it.
- Utility functions: Helpers for common tasks not directly covered by the official SDKs, such as webhook verification middleware or advanced reporting tools.
- Language-specific extensions: For languages where official support might be less mature, or for niche use cases, community libraries can fill gaps.
When considering community libraries, it is important to evaluate their maintenance status, documentation, and security implications, as they are not officially supported by Stripe. Resources like GitHub, package repositories (e.g., npm, PyPI, RubyGems), and technical forums are good places to discover such libraries. Always verify the authenticity and security practices of any third-party code before integrating it into a production environment. The Mozilla Developer Network's web security guide offers general best practices for securing web applications against common vulnerabilities.