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
use stripe::{
Client, CreatePaymentLink, CreatePaymentLinkLineItems, CreatePrice, CreateProduct, Currency,
IdOrCreate, PaymentLink, Price, Product,
};
#[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 product = {
let mut create_product = CreateProduct::new("T-Shirt");
create_product.metadata =
Some([("async-stripe".to_string(), "true".to_string())].iter().cloned().collect());
Product::create(&client, create_product).await.unwrap()
};
let price = {
let mut create_price = CreatePrice::new(Currency::USD);
create_price.product = Some(IdOrCreate::Id(&product.id));
create_price.metadata =
Some([("async-stripe".to_string(), "true".to_string())].iter().cloned().collect());
create_price.unit_amount = Some(1000);
create_price.expand = &["product"];
Price::create(&client, create_price).await.unwrap()
};
println!(
"created a product {:?} at price {} {}",
product.name.unwrap(),
price.unit_amount.unwrap() / 100,
price.currency.unwrap()
);
let payment_link = PaymentLink::create(
&client,
CreatePaymentLink::new(vec![CreatePaymentLinkLineItems {
quantity: 3,
price: price.id.to_string(),
..Default::default()
}]),
)
.await
.unwrap();
println!("created a payment link {}", payment_link.url);
}