Coder Social home page Coder Social logo

zacharykeeping / stripe-dotnet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stripe/stripe-dotnet

0.0 1.0 0.0 28.54 MB

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

License: Apache License 2.0

C# 100.00%

stripe-dotnet's Introduction

Stripe.net

Build status NuGet Coverage Status

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 RequestOptions:

var planService = new PlanService();
planService.Get(*planId*, new RequestOptions { 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 RequestOptions 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 RequestOptions();
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 ChargeService();
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 DateFilter class to combine the filters to make more interesting and complex queries.

Example: Interesting Queries with DateFilter

var chargeService = new ChargeService();

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

var chargesYesterday = chargeService.List(new ChargeListOptions {
	Created = new DateFilter {
		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.

stripe-dotnet's People

Contributors

ahm322 avatar alexander-stripe avatar anelder-stripe avatar brandur avatar brandur-stripe avatar daniel-cohen-deltatre avatar danielcrenna avatar dplarina avatar flagbug avatar fred-stripe avatar jaymedavis avatar jslaybaugh avatar jt000 avatar karlr-stripe avatar khalidabuhakmeh avatar marydavis avatar matthewschrager avatar mitch528 avatar ob-stripe avatar oystehei avatar pedropaf avatar praboud avatar remi-stripe avatar richardlawley avatar rwhitmire avatar sedouard avatar spastorelli-stripe avatar tghw avatar whitwaldo avatar winzig avatar

Watchers

 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.