-
-
Notifications
You must be signed in to change notification settings - Fork 139
/
Copy pathcustomer.rs
70 lines (58 loc) · 2.13 KB
/
customer.rs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! Customer
//! ========
//!
//! Reference: <https://stripe.com/docs/api/customers>
//!
//! This example shows how to create and list customers.
use futures_util::StreamExt;
use futures_util::TryStreamExt;
use stripe::{Client, CreateCustomer, Customer, ListCustomers};
#[tokio::main]
async fn main() {
let secret_key = std::env::var("STRIPE_SECRET_KEY").expect("Missing STRIPE_SECRET_KEY in env");
let client = Client::new(secret_key);
let customer = Customer::create(
&client,
CreateCustomer {
name: Some("Alexander Lyon"),
email: Some("[email protected]"),
description: Some(
"A fake customer that is used to illustrate the examples in async-stripe.",
),
metadata: Some(std::collections::HashMap::from([(
String::from("async-stripe"),
String::from("true"),
)])),
..Default::default()
},
)
.await
.unwrap();
println!("created a customer at https://dashboard.stripe.com/test/customers/{}", customer.id);
let customer = Customer::create(
&client,
CreateCustomer {
name: Some("Someone Else"),
email: Some("[email protected]"),
description: Some(
"A fake customer that is used to illustrate the examples in async-stripe.",
),
metadata: Some(std::collections::HashMap::from([(
String::from("async-stripe"),
String::from("true"),
)])),
..Default::default()
},
)
.await
.unwrap();
println!("created a customer at https://dashboard.stripe.com/test/customers/{}", customer.id);
let params = ListCustomers { ..Default::default() };
let paginator = Customer::list(&client, ¶ms).await.unwrap().paginate(params);
let mut stream = paginator.stream(&client);
// get the next customer
let _next = stream.next().await.unwrap();
// or collect them
let customers = stream.try_collect::<Vec<_>>().await.unwrap();
println!("fetched {} customers: {:?}", customers.len(), customers);
}