Skip to content

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

License

Notifications You must be signed in to change notification settings

ahm322/stripe-dotnet

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stripe.net Build status NuGet

The official Stripe library, supporting .NET Standard 1.2+, .NET Core 1.0+, and .NET Framework 4.5+

Documentation

See the .NET API docs.

Installation

Install Stripe.net via NuGet

From the command line:

nuget install Stripe.net

From Package Manager:

PM> 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.

Set the API Key for your project

You can configure the Stripe.net package to use your secret API key in one of two ways:

a) In your application initialization, set your API key (only once once during startup):

StripeConfiguration.SetApiKey("[your api key here]");

b) Pass the API key to StripeRequestOptions:

var planService = new StripePlanService();
planService.Get(*planId*, new StripeRequestOptions() { ApiKey = "[your api key here]" });

You can obtain your secret API key from the API Settings in the Dashboard.

Xamarin/Mono Developers (Optional)

If you are using Xamarin/Mono, you may want to provide your own HttpMessageHandler. You can do so by passing an instance to StripeConfiguration.HttpMessageHandler on your application's startup. See this thread for details.

Additional Resources

Support

Helpful Library Information

Request Options

All of the service methods accept an optional StripeRequestOptions object. This is used if you need 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 StripeRequestOptions();
requestOptions.ApiKey = "SECRET API KEY";                        // (optional) set the api key on a per-request basis
requestOptions.IdempotencyKey = "SOME STRING";                   // (optional) create an idempotent request
requestOptions.StripeConnectAccountId = "CONNECTED ACCOUNT ID";  // (optional) authenticate as a connected account

Responses

The StripeResponse object is an attribute (with the same name) attached to all entities in Stripe.net when they are returned from a service call.

Example: Access the StripeResponse

var chargeService = new StripeChargeService();
StripeCharge charge = chargeService.Create(...);
StripeResponse response = charge.StripeResponse;

The information that can be derived from the StripeResponse is available from the StripeResponse Class.

public class StripeResponse
{
	// ResponseJson will always tell you the complete json Stripe returned to Stripe.net.
	// this will be the same as the ObjectJson when you execute a create/get/delete call.
	// however, if you execute a List() method, the ResponseJson will have the full api result
	// from Stripe (a charge list with 10 charges, for example).
	public string ResponseJson { get; set; }

	// when you call a List() method, the object json is the object in the response array that represents
	// the entity. The ResponseJson will be the full array returned from Stripe on every entity, however,
	// since that was the full response from Stripe. ObjectJson is always the same as ResponseJson when
	// you are doing a regular create/get/delete, because you are dealing with a single object.
	public string ObjectJson { get; set; }

	// this is the request id of the call, as seen in the Stripe dashboard. I would recommend logging
	// this and/or saving it to your database. this is very useful to help you find your request
	// in the dashboard, or ask Stripe a question about your api call
	public string RequestId { get; set; }

	// this is the request date and time of the call. I would also recommend logging this and/or
	// saving it to your database, as it tells you when Stripe processed the request.
	public DateTime RequestDate { get; set; }
}

Date Filtering

Many of the List()-methods support parameters to filter by date. You can use the StripeDateFilter class to combine the filters to make more interesting and complex queries.

Example: Interesting Queries with StripeDateFilter

var chargeService = new StripeChargeService();

var chargesToday = chargeService.List(new StripeChargeListOptions {
	Created = new StripeDateFilter { GreaterThanOrEqual = DateTime.UtcNow.Date }
});

var chargesYesterday = chargeService.List(new StripeChargeListOptions {
	Created = new StripeDateFilter {
		GreaterThanOrEqual = DateTime.Now.AddDays(-1).Date,
		LessThan = DateTime.Now.Date
	}
});

Contribution Guidelines

We welcome contributions from anyone interested in Stripe or Stripe.net development. If you'd like to submit a pull request, it's best to start with an issue to describe what you'd like to build.

Once you've written your pull request, please make sure you test your changes. We have two test unit suites:

  • A test suite in the Stripe.net.Test project.
  • Another test suite in the Stripe.Test.XUnit project.

Since we're moving to XUnit as the preferred testing suite, please try and build tests against that project. If you need help, you can open an issue.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%