• Stars
    star
    1,307
  • Rank 34,479 (Top 0.8 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created over 12 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Stripe.net is a sync/async .NET 4.6.1+ client, and a portable class library for stripe.com.

Stripe.net

NuGet Build Status Coverage Status

The official Stripe .NET library, supporting .NET Standard 2.0+, .NET Core 2.0+, and .NET Framework 4.6.1+.

Installation

Using the .NET Core command-line interface (CLI) tools:

dotnet add package Stripe.net

Using the NuGet Command Line Interface (CLI):

nuget install Stripe.net

Using the Package Manager Console:

Install-Package Stripe.net

From within Visual Studio:

  1. Open the Solution Explorer.
  2. Right-click on a project within your solution.
  3. Click on Manage NuGet Packages...
  4. Click on the Browse tab and search for "Stripe.net".
  5. Click on the Stripe.net package, select the appropriate version in the right-tab and click Install.

Documentation

For a comprehensive list of examples, check out the API documentation. See video demonstrations covering how to use the library.

Usage

Authentication

Stripe authenticates API requests using your account’s secret key, which you can find in the Stripe Dashboard. By default, secret keys can be used to perform any API request without restriction.

Use StripeConfiguration.ApiKey property to set the secret key.

StripeConfiguration.ApiKey = "sk_test_...";

Creating a resource

The Create method of the service class can be used to create a new resource:

var options = new CustomerCreateOptions
{
    Email = "[email protected]"
};

var service = new CustomerService();
Customer customer = service.Create(options);

// Newly created customer is returned
Console.WriteLine(customer.Email);

Retrieve a resource

The Retrieve method of the service class can be used to retrieve a resource:

var service = new CustomerService();
Customer customer = service.Get("cus_1234");

Console.WriteLine(customer.Email);

Updating a resource

The Update method of the service class can be used to update a resource:

var options = new CustomerUpdateOptions
{
    Email = "[email protected]"
};

var service = new CustomerService();
Customer customer = service.Update("cus_123", options);

// The updated customer is returned
Console.WriteLine(customer.Email);

Deleting a resource

The Delete method of the service class can be used to delete a resource:

var service = new CustomerService();
Customer customer = service.Delete("cus_123", options);

Listing a resource

The List method on the service class can be used to list resources page-by-page.

NOTE The List method returns only a single page, you have to manually continue the iteration using the StartingAfter parameter.

var service = new CustomerService();
var customers = service.List();

string lastId = null;

// Enumerate the first page of the list
foreach (Customer customer in customers)
{
   lastId = customer.Id;
   Console.WriteLine(customer.Email);
}

customers = service.List(new CustomerListOptions()
{
    StartingAfter = lastId,
});

// Enumerate the subsequent page
foreach (Customer customer in customers)
{
   lastId = customer.Id;
   Console.WriteLine(customer.Email);
}

Listing a resource with auto-pagination

The ListAutoPaging method on the service class can be used to automatically iterate over all pages.

var service = new CustomerService();
var customers = service.ListAutoPaging();

// Enumerate all pages of the list
foreach (Customer customer in customers)
{
   Console.WriteLine(customer.Email);
}

Per-request configuration

All of the service methods accept an optional RequestOptions object. This is used if you want to set an idempotency key, if you are using Stripe Connect, or if you want to pass the secret API key on each method.

var requestOptions = new RequestOptions();
requestOptions.ApiKey = "SECRET API KEY";
requestOptions.IdempotencyKey = "SOME STRING";
requestOptions.StripeAccount = "CONNECTED ACCOUNT ID";

Using a custom HttpClient

You can configure the library with your own custom HttpClient:

StripeConfiguration.StripeClient = new StripeClient(
    apiKey,
    httpClient: new SystemNetHttpClient(httpClient));

Please refer to the Advanced client usage wiki page to see more examples of using custom clients, e.g. for using a proxy server, a custom message handler, etc.

Automatic retries

The library automatically retries requests on intermittent failures like on a connection error, timeout, or on certain API responses like a status 409 Conflict. Idempotency keys are always added to requests to make any such subsequent retries safe.

By default, it will perform up to two retries. That number can be configured with StripeConfiguration.MaxNetworkRetries:

StripeConfiguration.MaxNetworkRetries = 0; // Zero retries

How to use undocumented parameters and properties

stripe-dotnet is a typed library and it supports all public properties or parameters.

Stripe sometimes has beta features which introduce new properties or parameters that are not immediately public. The library does not support these properties or parameters until they are public but there is still an approach that allows you to use them.

Parameters

To pass undocumented parameters to Stripe using stripe-dotnet you need to use the AddExtraParam() method, as shown below:

var options = new CustomerCreateOptions
{
    Email = "[email protected]"
}
options.AddExtraParam("secret_feature_enabled", "true");
options.AddExtraParam("secret_parameter[primary]", "primary value");
options.AddExtraParam("secret_parameter[secondary]", "secondary value");

var service = new CustomerService();
var customer = service.Create(options);

Properties

To retrieve undocumented properties from Stripe using C# you can use an option in the library to return the raw JSON object and return the property. An example of this is shown below:

var service = new CustomerService();
var customer = service.Get("cus_1234");

customer.RawJObject["secret_feature_enabled"];
customer.RawJObject["secret_parameter"]["primary"];
customer.RawJObject["secret_parameter"]["secondary"];

Writing a plugin

If you're writing a plugin that uses the library, we'd appreciate it if you identified using StripeConfiguration.AppInfo:

StripeConfiguration.AppInfo = new AppInfo
{
    Name = "MyAwesomePlugin",
    Url = "https://myawesomeplugin.info",
    Version = "1.2.34",
};

This information is passed along when the library makes calls to the Stripe API. Note that while Name is always required, Url and Version are optional.

Telemetry

By default, the library sends telemetry to Stripe regarding request latency and feature usage. These numbers help Stripe improve the overall latency of its API for all users, and improve popular features.

You can disable this behavior if you prefer:

StripeConfiguration.EnableTelemetry = false;

Beta SDKs

Stripe has features in the beta phase that can be accessed via the beta version of this package. We would love for you to try these and share feedback with us before these features reach the stable phase. To install a beta version of Stripe.net use the version parameter with dotnet add package command:

dotnet add package Stripe.net --version 40.3.0-beta.1

Note There can be breaking changes between beta versions. Therefore we recommend pinning the package version to a specific beta version in your project file. This way you can install the same version each time without breaking changes unless you are intentionally looking for the latest beta version.

We highly recommend keeping an eye on when the beta feature you are interested in goes from beta to stable so that you can move from using a beta version of the SDK to the stable version.

If your beta feature requires a Stripe-Version header to be sent, set the StripeConfiguration.ApiVersion property with the StripeConfiguration.AddBetaVersion function:

Note The ApiVersion can only be set in beta versions of the library.

StripeConfiguration.AddBetaVersion("feature_beta", "v3");

Support

New features and bug fixes are released on the latest major version of the Stripe .NET client library. If you are on an older major version, we recommend that you upgrade to the latest in order to use the new features and bug fixes including those for security vulnerabilities. Older major versions of the package will continue to be available for use, but will not be receiving any updates.

Development

.NET 8 is required to build and test Stripe.net SDK, you can install it from get.dot.net.

The test suite depends on stripe-mock, so make sure to fetch and run it from a background terminal (stripe-mock's README also contains instructions for installing via Homebrew and other methods):

go install github.com/stripe/stripe-mock@latest
stripe-mock

Run all tests from the src/StripeTests directory:

dotnet test src

Run some tests, filtering by name:

dotnet test src --filter FullyQualifiedName~InvoiceServiceTest

Run tests for a single target framework:

dotnet test src --framework net8.0

The library uses dotnet-format for code formatting. Code must be formatted before PRs are submitted, otherwise CI will fail. Run the formatter with:

dotnet format src/Stripe.net.sln

For any requests, bug or comments, please open an issue or submit a pull request.

More Repositories

1

stripe-node

Node.js library for the Stripe API.
TypeScript
3,591
star
2

stripe-php

PHP library for the Stripe API.
PHP
3,558
star
3

stripe-ios

Stripe iOS SDK
Swift
2,023
star
4

stripe-go

Go library for the Stripe API.
Go
1,948
star
5

stripe-ruby

Ruby library for the Stripe API.
Ruby
1,866
star
6

veneur

A distributed, fault-tolerant pipeline for observability data
Go
1,690
star
7

react-stripe-js

React components for Stripe.js and Stripe Elements
TypeScript
1,612
star
8

stripe-cli

A command-line tool for Stripe
Go
1,545
star
9

stripe-python

Python library for the Stripe API.
Python
1,507
star
10

stripe-mock

stripe-mock is a mock HTTP server that responds like the real Stripe API. It can be used instead of Stripe's testmode to make test suites integrating with Stripe faster and less brittle.
Go
1,278
star
11

stripe-android

Stripe Android SDK
Kotlin
1,207
star
12

stripe-react-native

React Native library for Stripe.
TypeScript
1,200
star
13

smokescreen

A simple HTTP proxy that fogs over naughty URLs
Go
988
star
14

elements-examples

Stripe Elements examples.
HTML
987
star
15

stripe-java

Java library for the Stripe API.
Java
735
star
16

skycfg

Skycfg is an extension library for the Starlark language that adds support for constructing Protocol Buffer messages.
Go
629
star
17

stripe-connect-rocketrides

Sample on-demand platform built on Stripe: Connect onboarding for pilots, iOS app for passengers to request rides.
Swift
614
star
18

stripe-js

Loading wrapper for Stripe.js
TypeScript
561
star
19

poncho

Easily create REST APIs
Ruby
518
star
20

rainier

Bayesian inference in Scala.
Scala
435
star
21

openapi

An OpenAPI specification for the Stripe API.
351
star
22

stripe-billing-typographic

⚡️Typographic is a webfont service (and demo) built with Stripe Billing.
JavaScript
216
star
23

subprocess

A port of Python's subprocess module to Ruby
Ruby
193
star
24

carbon-removal-source-materials

Source materials supporting Stripe Climate carbon removal purchases (http://stripe.com/climate)
189
star
25

dagon

Tools for rewriting and optimizing DAGs (directed-acyclic graphs) in Scala
Scala
148
star
26

bonsai

Beautiful trees, without the landscaping.
Scala
142
star
27

pg-schema-diff

Go library for diffing Postgres schemas and generating SQL migrations
Go
141
star
28

ios-dashboard-ui

[DEPRECATED] UI components from the Stripe Dashboard iOS app
Swift
136
star
29

stripe-apps

Stripe Apps lets you embed custom user experiences directly in the Stripe Dashboard and orchestrate the Stripe API.
TypeScript
134
star
30

vscode-stripe

Stripe for Visual Studio Code
TypeScript
117
star
31

example-mobile-backend

A simple, easy-to-deploy backend that you can use to demo our example mobile apps.
Ruby
105
star
32

stripe.github.io

A landing page for Stripe's GitHub organization
HTML
94
star
33

stripe-terminal-ios

Stripe Terminal iOS SDK
Objective-C
92
star
34

stripe-demo-connect-roastery-saas-platform

Roastery demo SaaS platform using Stripe Connect
JavaScript
89
star
35

stripe-terminal-react-native

React Native SDK for Stripe Terminal
TypeScript
84
star
36

example-terminal-backend

A simple, easy-to-deploy backend that you can use to run the Stripe Terminal example apps
Ruby
79
star
37

stripe-terminal-android

Stripe Terminal Android SDK
Java
77
star
38

unilog

A logger for use with daemontools.
Go
77
star
39

stripe-terminal-js-demo

Demo app for the Stripe Terminal JS SDK
JavaScript
75
star
40

stripe-postman

Postman collection for Stripe's API
73
star
41

goforit

A feature flags client library for Go
Go
68
star
42

stripe-connect-custom-rocketdeliveries

Sample on-demand platform built on Stripe Connect: Custom Accounts and Connect Onboarding for deliveries. https://rocketdeliveries.io
JavaScript
62
star
43

tracer-objc

Generic record & playback framework for Objective-C
Objective-C
51
star
44

mobile-viewport-control

Dynamically control the mobile viewport
JavaScript
47
star
45

log4j-remediation-tools

Tools for remediating the recent log4j2 RCE vulnerability (CVE-2021-44228)
Go
41
star
46

terminal-js

Loading wrapper for the Terminal JS SDK
TypeScript
30
star
47

stripe-reachability

A bash script to test access to the Stripe API
Shell
29
star
48

krl

OpenSSH Key Revocation List support for Go
Go
29
star
49

stripe-identity-react-native

React Native library for Stripe Identity
TypeScript
28
star
50

stripe-magento2-releases

22
star
51

checkout-sales-demo

Sales demo of Stripe Checkout with different locales around the world.
HTML
12
star
52

stripe-ios-spm

Swift Package Manager mirror for the Stripe iOS SDK. See http://github.com/stripe/stripe-ios for details.
12
star
53

connect-js

Loading wrapper for Connect.js
TypeScript
11
star
54

react-connect-js

React components for Connect.js and Connect embedded components
TypeScript
11
star
55

salesforce-connector-examples

Stripe Salesforce Connector examples
JavaScript
10
star
56

stripe-mirakl-connector

Official Stripe Mirakl Connector
PHP
10
star
57

homebrew-stripe-mock

Homebrew tap for stripestub
Ruby
6
star
58

homebrew-stripe-cli

Ruby
6
star
59

.github

Stripe uses the Contributor Covenant Code of Conduct for our open-source community.
6
star
60

scoop-stripe-cli

4
star
61

ssf-ruby

A Ruby client for the Sensor Sensibility Format
Ruby
4
star
62

stripe-sfcc-b2c-connector

JavaScript
2
star