Crate braintree [] [src]

Bindings to Braintree's API.

For those unfamiliar with Braintree or payments processing, Braintree's homepage is a good place to start to learn more, along with the developer documentation which provides a good overview of the available tools and API's.

Note that this is an unofficial library, with no direct support from Braintree themselves. The goal is to provide a set of reasonably-complete bindings to core functionality, but naturally a lot of it will be incomplete. Pull requests are welcome!

The first thing you'll need to do is create a sandbox account, which you can use to test your integration without needing to go through the full application process. Once you've created an account, follow these instructions to retrieve your Merchant ID, Public Key, and Private Key. Once you have those, you should be able to create your first transaction! Naturally you'll need to substitute those three values in for the placeholders below, and it bears repeating that you should never commit those credentials to source control:

extern crate braintree;
 
use braintree::{Braintree, CreditCard, Environment};
use braintree::transaction;
use std::error::Error;
 
fn main() {
    // Create a handle to the Braintree API.
    let bt = Braintree::new(
        Environment::Sandbox,
        "<merchant_id>",
        "<public_key>",
        "<private_key>",
    );
 
    // Attempt to charge the provided credit card $10.
    let result = bt.transaction().create(transaction::Request{
        amount: String::from("10.00"),
        credit_card: Some(CreditCard{
            number: Some(String::from("4111111111111111")),
            expiration_date: Some(String::from("10/20")),
            ..Default::default()
        }),
        options: Some(transaction::Options{
            submit_for_settlement: Some(true),
            ..Default::default()
        }),
        ..Default::default()
    });
 
    // Check to see if it worked.
    match result {
        Ok(transaction) => println!("Created transaction: {}", transaction.id),
        Err(err) => println!("Error: {}", err.description()),
    }
}

Once you've decided that your integration is good to go live, you'll need to get a separate set of production credentials by signing up on Braintree's main site. Remember to also change Environment::Sandbox to Environment::Production when you make the switch.

Stability Note

This crate is very much in a pre-alpha state, and as such the design of its API is subject to change. You have been forewarned!

Reexports

pub use address::Address;
pub use credit_card::CreditCard;
pub use descriptor::Descriptor;
pub use customer::Customer;
pub use error::Error;

Modules

address
client_token
credit_card
customer
descriptor
error
transaction

Structs

Braintree
ClientTokenGateway
TestingGateway
TransactionGateway
XApiVersion

Enums

Environment