Code Monkey home page Code Monkey logo

async-stripe's Introduction

async-stripe

CI async-stripe on crates.io async-stripe  on docs.rs

Rust API bindings for the Stripe v1 HTTP API.

This is compatible with all currently supported versions of Stripe's client-side libraries including https://js.stripe.com/v2/ and https://js.stripe.com/v3/.

API Version

The latest supported version of the Stripe API is 2020-08-27. Set the corresponding crate version depending on which version of the Stripe API you are pinned to. If you don't see the specific version you are on, prefer the next available version.

  • 0.13 - stripe version 2020-08-27
  • 0.12 - stripe version 2019-09-09

Install

async-stripe is compatible with the async-std and tokio runtimes and the native-tls and rustls backends. When adding the dependency, you much select a runtime feature.

[dependencies]
async-stripe = { version = "0.13.0-rc3", features = ["runtime-async-std-surf"] }

Feature Flags

Runtimes

  • runtime-tokio-hyper
  • runtime-tokio-hyper-rustls
  • runtime-blocking
  • runtime-blocking-rustls
  • runtime-async-std-surf

API Features

Additionally, since this is a large library, it is possible to conditionally enable features as required to reduce compile times and final binary size. Refer to the Stripe API docs to determine which APIs are included as part of each feature flag.

# Example: Core-only (enough to create a `Charge` or `Card` or `Customer`)
async-stripe = { version = "*", default-features = false, features = ["runtime-async-std-surf"] }

# Example: Support for "Subscriptions" and "Invoices"
async-stripe = { version = "*", default-features = false, features = ["runtime-async-std-surf", "billing"] }

Getting Started

/* Create a Stripe Client */

let client = stripe::Client::new("sk_test_YOUR_STRIPE_SECRET");

/* Create a Stripe Charge */

let token = "TOKEN_FROM_CHECKOUT".parse().expect("token to be valid");
let mut params = stripe::CreateCharge::new();

// NOTE: Stripe represents currency in the lowest denominations (e.g. cents)
params.amount = Some(1095); // e.g. $10.95
params.source = Some(stripe::ChargeSourceParams::Token(token));

// Example: Override currency to be in Canadian Dollars
params.currency = Some(stripe::Currency::CAD);

let charge = stripe::Charge::create(&client, params).unwrap();
println!("{:?}", charge); // =>  Charge { id: "ch_12345", amount: 1095, .. }


/* List Stripe Charges */

let params = stripe::ListCharges::new();
let charges = stripe::Charge::list(&client, params).unwrap();
println!("{:?}", charges); // =>  List { data: [Charge { id: "ch_12345", .. }] }

Most requests for creating or updating a Stripe object use the same Rust struct, so you may frequently need to refer to the official API docs to determine which fields are required for either request.

Using Custom Connect accounts

This crate supports impersonating a custom connect account. To impersonate the account get a new Client and pass in the account id.

let mut headers = stripe::Headers::default();
headers.stripe_account = Some("acct_ABC".to_string());
headers.client_id = Some("ca_XYZ".to_string());
let client = client.with_headers(headers);

// Then, all requests can be made normally
let params = stripe::CustomerListParams::default();
let customers = stripe::Customer::list(&client, params).unwrap();
println!("{:?}", customers); // =>  List { data: [Customer { .. }] }

MSRV

We currently have 1.49.0 pinned in CI, so any version of rustc newer than that should work. If this is not the case, please open an issue.

Contributing

See CONTRIBUTING.md for information on contributing to async-stripe.

License

This project started as a fork of stripe-rs. We would not be here without them! :)

Licensed under either of

at your option.

async-stripe's People

Contributors

agrinman avatar ambaldwin avatar arlyon avatar ava57r avatar brndnmtthws avatar bryanburgers avatar busarovalex avatar daniel-abramov avatar drager avatar erichcompsci avatar fgribreau avatar gperinazzo avatar jayshua avatar jonathankingston avatar kardeiz avatar kdy1 avatar kestred avatar kiljacken avatar marcoslopes avatar ntr-808 avatar okabe-san avatar phayes avatar pocket7878 avatar raulsi avatar ruseinov avatar serejkaaa512 avatar stearnsc avatar terry90 avatar thedodd avatar thoucheese 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.