SDKs overview
Stripe Radar provides a suite of Software Development Kits (SDKs) designed to facilitate the integration of its fraud detection and prevention capabilities into various application environments. These SDKs abstract the complexities of direct API interactions, offering language-specific methods for tasks such as creating and managing Radar rules, evaluating risk scores for transactions, and responding to fraud alerts. The primary goal of these SDKs is to enable developers to embed Stripe Radar's machine learning-driven fraud analysis directly into their backend systems or client-side applications with minimal overhead.
The official SDKs are developed and maintained by Stripe, ensuring they are kept up-to-date with the latest API versions and features of the Stripe Radar documentation. This maintenance includes security updates, performance improvements, and alignment with new functionalities introduced on the Stripe platform. For developers working with existing Stripe integrations, the Radar SDKs offer a consistent and familiar programming paradigm.
Beyond the official offerings, the open-source nature of many programming ecosystems has led to the development of community-contributed libraries. While these community projects can offer alternative approaches or specialized functionalities, developers should assess their maintenance status, security practices, and compatibility with the Stripe API reference before integrating them into production environments.
Official SDKs by language
Stripe offers official SDKs across several popular programming languages, providing idiomatic access to the Stripe API, which includes endpoints relevant to Stripe Radar. These SDKs are the recommended method for interfacing with Stripe's services due to their active maintenance and direct support from Stripe.
| Language | Package/Library Name | Maturity |
|---|---|---|
| Python | stripe-python |
Stable, Actively Maintained |
| Ruby | stripe-ruby |
Stable, Actively Maintained |
| Java | stripe-java |
Stable, Actively Maintained |
| Node.js | stripe-node |
Stable, Actively Maintained |
| PHP | stripe-php |
Stable, Actively Maintained |
| .NET | Stripe.net |
Stable, Actively Maintained |
| Go | stripe-go |
Stable, Actively Maintained |
Installation
Installing Stripe's official SDKs typically involves using the package manager specific to your programming language's ecosystem. The process is designed to be straightforward, allowing developers to quickly add Stripe's capabilities to their projects. Below are common installation commands for the primary supported languages. Developers should refer to the Stripe API client libraries page for the most current and detailed instructions for each language.
Python
Install via pip:
pip install --upgrade stripe
Ruby
Add to your Gemfile and run bundle install:
gem 'stripe'
bundle install
Java
For Maven projects, add the dependency to your pom.xml:
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>{latest.version}</version>
</dependency>
For Gradle projects, add to your build.gradle:
implementation 'com.stripe:stripe-java:{latest.version}'
Node.js
Install via npm:
npm install stripe
Or via yarn:
yarn add stripe
PHP
Install via Composer:
composer require stripe/stripe-php
.NET
Install via NuGet Package Manager Console:
Install-Package Stripe.net
Or via .NET CLI:
dotnet add package Stripe.net
Go
Install via go get:
go get github.com/stripe/stripe-go/v72
Quickstart example
While Stripe Radar primarily operates automatically in the background for transactions processed via Stripe Payments, its SDKs are used to interact with Radar's rule management and evaluation features. The following Node.js example demonstrates how to create a Radar rule using the official Stripe Node.js SDK. This example assumes you have an API key configured.
This code snippet creates a new Radar rule that blocks payments if the card's country does not match the customer's IP country, with a specified description and action.
const stripe = require('stripe')('YOUR_SECRET_KEY');
async function createRadarRule() {
try {
const rule = await stripe.radar.rules.create({
action: 'block',
predicate: 'card_country != ip_country',
description: 'Block if card country does not match IP country'
});
console.log('Radar Rule created:', rule);
} catch (error) {
console.error('Error creating Radar Rule:', error);
}
}
createRadarRule();
Replace 'YOUR_SECRET_KEY' with your actual Stripe secret key. This example illustrates a basic interaction. More complex scenarios might involve listing existing rules, updating rules, or evaluating specific risk scores. Developers interested in further examples and detailed API functionality should consult the Stripe Radar rules reference and the broader Stripe API documentation.
Community libraries
Beyond Stripe's officially supported SDKs, the developer community has created various libraries and tools that extend or complement Stripe Radar's capabilities. These community-driven projects can offer specialized functionalities, integrations with lesser-supported languages or frameworks, or alternative approaches to interacting with the Stripe API. For example, some developers might create wrappers for specific frontend frameworks or build tools for managing Radar rules through configuration files rather than direct API calls.
When considering community libraries, it is important to evaluate several factors:
- Maintenance Status: Check the project's activity on platforms like GitHub to ensure it is actively maintained and compatible with recent Stripe API versions. Unmaintained libraries may become incompatible or pose security risks.
- Security Practices: Review the library's code and its approach to handling sensitive data, especially API keys and payment information. Official SDKs adhere to stringent security standards, while community libraries may vary.
- Documentation and Support: Assess the quality of the documentation and the availability of community support channels. Robust documentation and an active community can be crucial for troubleshooting and implementation.
- Licensing: Understand the licensing terms of the library, as this can affect its use in commercial projects.
While Stripe does not officially endorse or provide support for community-built libraries, they can sometimes offer innovative solutions or bridge gaps for niche use cases. Developers can often find these resources by searching relevant package managers (e.g., npm, PyPI, RubyGems) or by exploring forums and community groups dedicated to API development and integration.