1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
use stripe::{Card, BankAccount, CardParam, BankAccountParam}; use util::Result; use Client; use serde; #[derive(Deserialize, Debug)] pub struct Tokens { pub id: String, pub object: String, pub card: Option<Card>, pub bank_account: Option<BankAccount>, pub client_ip: Option<String>, pub created: i64, pub livemode: bool, #[serde(rename="type")] pub token_type: TokenType, pub used: bool } #[derive(Deserialize, Debug)] pub enum TokenType { #[serde(rename="card")] Card, #[serde(rename="bank_account")] BankAccount } #[derive(Default, Serialize, Debug)] pub struct TokenParam<'a> { #[serde(skip_serializing_if = "Option::is_none")] pub card: Option<CardParam<'a>>, #[serde(skip_serializing_if = "Option::is_none")] pub bank_account: Option<BankAccountParam<'a>>, #[serde(skip_serializing_if = "Option::is_none")] pub pii: Option<PIIParam<'a>>, #[serde(skip_serializing_if = "Option::is_none")] pub customer: Option<&'a str> } #[derive(Default, Serialize, Debug)] pub struct PIIParam<'a> { pub personal_id_number: &'a str } impl Tokens { pub fn create<B: serde::Serialize>(client: &Client, param: B) -> Result<Tokens> { client.post("/tokens", param) } pub fn retrieve(client: &Client, token: &str) -> Result<Tokens> { client.get_empty(&format!("/tokens/{}", token)) } }