Code Monkey home page Code Monkey logo

stripe-dotnet's Introduction

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.

stripe-dotnet's People

Contributors

jaymedavis avatar remi-stripe avatar ob-stripe avatar brandur-stripe avatar marydavis avatar brandur avatar jslaybaugh avatar anelder-stripe avatar khalidabuhakmeh avatar dplarina avatar winzig avatar richardlawley avatar jt000 avatar pedropaf avatar flagbug avatar danielcrenna avatar daniel-cohen-deltatre avatar praboud avatar ahm322 avatar matthewschrager avatar oystehei avatar whitwaldo avatar tghw avatar rwhitmire avatar yeurch avatar ryn0 avatar philiprieck avatar nick-lucas avatar chizzl avatar xt0rted avatar

Watchers

James Cloos avatar Jonas Mosbech avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.