-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #597 from lasantosr/owned-requests
feat(next): owned types on requests
- Loading branch information
Showing
142 changed files
with
20,401 additions
and
18,558 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,27 +18,28 @@ use stripe_product::product::CreateProduct; | |
use stripe_types::{Currency, Expandable}; | ||
|
||
pub async fn run_checkout_session_example(client: &stripe::Client) -> Result<(), StripeError> { | ||
let metadata = | ||
std::collections::HashMap::from([(String::from("async-stripe"), String::from("true"))]); | ||
let customer = CreateCustomer::new() | ||
.name("Alexander Lyon") | ||
.email("[email protected]") | ||
.description("A fake customer that is used to illustrate the examples in async-stripe.") | ||
.metadata(&metadata) | ||
.metadata([(String::from("async-stripe"), String::from("true"))]) | ||
.send(client) | ||
.await?; | ||
|
||
println!("created a customer at https://dashboard.stripe.com/test/customers/{}", customer.id); | ||
|
||
// create a new example product | ||
let product = CreateProduct::new("T-Shirt").metadata(&metadata).send(client).await?; | ||
let product = CreateProduct::new("T-Shirt") | ||
.metadata([(String::from("async-stripe"), String::from("true"))]) | ||
.send(client) | ||
.await?; | ||
|
||
// and add a price for it in USD | ||
let price = CreatePrice::new(Currency::USD) | ||
.product(product.id.as_str()) | ||
.metadata(&metadata) | ||
.metadata([(String::from("async-stripe"), String::from("true"))]) | ||
.unit_amount(1000) | ||
.expand(&["product"]) | ||
.expand([String::from("product")]) | ||
.send(client) | ||
.await?; | ||
|
||
|
@@ -52,15 +53,15 @@ pub async fn run_checkout_session_example(client: &stripe::Client) -> Result<(), | |
// finally, create a checkout session for this product / price | ||
let line_items = vec![CreateCheckoutSessionLineItems { | ||
quantity: Some(3), | ||
price: Some(&price.id), | ||
price: Some(price.id.to_string()), | ||
..Default::default() | ||
}]; | ||
let checkout_session = CreateCheckoutSession::new() | ||
.cancel_url("http://test.com/cancel") | ||
.customer(customer.id.as_str()) | ||
.mode(CheckoutSessionMode::Payment) | ||
.line_items(&line_items) | ||
.expand(&["line_items", "line_items.data.price.product"]) | ||
.line_items(line_items) | ||
.expand([String::from("line_items"), String::from("line_items.data.price.product")]) | ||
.send(client) | ||
.await?; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,13 +11,11 @@ use stripe::{Client, StripeError}; | |
use stripe_core::customer::{CreateCustomer, ListCustomer}; | ||
|
||
pub async fn run_customer_example(client: &Client) -> Result<(), StripeError> { | ||
let meta = | ||
std::collections::HashMap::from([(String::from("async-stripe"), String::from("true"))]); | ||
let customer = CreateCustomer::new() | ||
.name("Alexander Lyon") | ||
.email("[email protected]") | ||
.description("A fake customer that is used to illustrate the examples in async-stripe.") | ||
.metadata(&meta) | ||
.metadata([(String::from("async-stripe"), String::from("true"))]) | ||
.send(client) | ||
.await?; | ||
|
||
|
@@ -27,7 +25,7 @@ pub async fn run_customer_example(client: &Client) -> Result<(), StripeError> { | |
.name("Someone Else") | ||
.email("[email protected]") | ||
.description("A fake customer that is used to illustrate the examples in async-stripe.") | ||
.metadata(&meta) | ||
.metadata([(String::from("async-stripe"), String::from("true"))]) | ||
.send(client) | ||
.await?; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,24 +17,21 @@ use stripe_payment::payment_method::{ | |
use stripe_types::Currency; | ||
|
||
pub async fn run_payment_intent_example(client: &Client) -> Result<(), StripeError> { | ||
let meta = | ||
std::collections::HashMap::from([(String::from("async-stripe"), String::from("true"))]); | ||
let customer = CreateCustomer::new() | ||
.name("Alexander Lyon") | ||
.email("[email protected]") | ||
.description("A fake customer that is used to illustrate the examples in async-stripe.") | ||
.metadata(&meta) | ||
.metadata([(String::from("async-stripe"), String::from("true"))]) | ||
.send(client) | ||
.await?; | ||
|
||
println!("created a customer at https://dashboard.stripe.com/test/customers/{}", customer.id); | ||
|
||
// we create an intent to pay | ||
let meta = [("color".to_string(), "red".to_string())].iter().cloned().collect(); | ||
let payment_intent = CreatePaymentIntent::new(1000, Currency::USD) | ||
.payment_method_types(&["card"]) | ||
.payment_method_types([String::from("card")]) | ||
.statement_descriptor("Purchasing a new car") | ||
.metadata(&meta) | ||
.metadata([("color".to_string(), "red".to_string())]) | ||
.send(client) | ||
.await?; | ||
|
||
|
@@ -46,16 +43,16 @@ pub async fn run_payment_intent_example(client: &Client) -> Result<(), StripeErr | |
let payment_method = CreatePaymentMethod::new() | ||
.type_(CreatePaymentMethodType::Card) | ||
.card(CreatePaymentMethodCard::CardDetailsParams(CreatePaymentMethodCardDetailsParams { | ||
number: "4000008260000000", // UK visa | ||
number: String::from("4000008260000000"), // UK visa | ||
exp_year: 2025, | ||
exp_month: 1, | ||
cvc: Some("123"), | ||
cvc: Some(String::from("123")), | ||
networks: None, | ||
})) | ||
.send(client) | ||
.await?; | ||
|
||
AttachPaymentMethod::new(&payment_method.id, &customer.id).send(client).await?; | ||
AttachPaymentMethod::new(payment_method.id.clone(), &customer.id).send(client).await?; | ||
|
||
println!( | ||
"created a payment method with id {} and attached it to {}", | ||
|
@@ -64,7 +61,7 @@ pub async fn run_payment_intent_example(client: &Client) -> Result<(), StripeErr | |
); | ||
|
||
// lets update the payment intent with their details | ||
let payment_intent = UpdatePaymentIntent::new(&payment_intent.id) | ||
let payment_intent = UpdatePaymentIntent::new(payment_intent.id) | ||
.payment_method(payment_method.id.as_str()) | ||
// this is not strictly required but good practice to ensure we have the right person | ||
.customer(customer.id.as_str()) | ||
|
@@ -73,7 +70,7 @@ pub async fn run_payment_intent_example(client: &Client) -> Result<(), StripeErr | |
|
||
println!("updated payment intent with status '{}'", payment_intent.status); | ||
|
||
let payment_intent = ConfirmPaymentIntent::new(&payment_intent.id).send(client).await?; | ||
let payment_intent = ConfirmPaymentIntent::new(payment_intent.id).send(client).await?; | ||
println!("completed payment intent with status {}", payment_intent.status); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,29 +18,27 @@ use stripe_product::product::CreateProduct; | |
use stripe_types::{Currency, Expandable}; | ||
|
||
pub async fn run_subscriptions_example(client: &Client) -> Result<(), StripeError> { | ||
let meta = | ||
std::collections::HashMap::from([(String::from("async-stripe"), String::from("true"))]); | ||
let customer = CreateCustomer::new() | ||
.name("Alexander Lyon") | ||
.email("[email protected]") | ||
.description("A fake customer that is used to illustrate the examples in async-stripe.") | ||
.metadata(&meta) | ||
.metadata([(String::from("async-stripe"), String::from("true"))]) | ||
.send(client) | ||
.await?; | ||
|
||
println!("created a customer at https://dashboard.stripe.com/test/customers/{}", customer.id); | ||
let payment_method = CreatePaymentMethod::new() | ||
.type_(CreatePaymentMethodType::Card) | ||
.card(CreatePaymentMethodCard::CardDetailsParams(CreatePaymentMethodCardDetailsParams { | ||
number: "4000008260000000", // UK visa | ||
number: String::from("4000008260000000"), // UK visa | ||
exp_year: 2025, | ||
exp_month: 1, | ||
cvc: Some("123"), | ||
cvc: Some(String::from("123")), | ||
networks: None, | ||
})) | ||
.send(client) | ||
.await?; | ||
AttachPaymentMethod::new(&payment_method.id, &customer.id).send(client).await?; | ||
AttachPaymentMethod::new(payment_method.id.clone(), &customer.id).send(client).await?; | ||
|
||
println!( | ||
"created a payment method with id {} and attached it to {}", | ||
|
@@ -49,16 +47,18 @@ pub async fn run_subscriptions_example(client: &Client) -> Result<(), StripeErro | |
); | ||
|
||
// create a new example product | ||
let product = | ||
CreateProduct::new("Monthly T-Shirt Subscription").metadata(&meta).send(client).await?; | ||
let product = CreateProduct::new("Monthly T-Shirt Subscription") | ||
.metadata([(String::from("async-stripe"), String::from("true"))]) | ||
.send(client) | ||
.await?; | ||
|
||
// and add a price for it in USD | ||
let price = CreatePrice::new(Currency::USD) | ||
.product(&product.id) | ||
.metadata(&meta) | ||
.metadata([(String::from("async-stripe"), String::from("true"))]) | ||
.unit_amount(1000) | ||
.recurring(CreatePriceRecurring::new(CreatePriceRecurringInterval::Month)) | ||
.expand(&["product"]) | ||
.expand([String::from("product")]) | ||
.send(client) | ||
.await?; | ||
|
||
|
@@ -69,11 +69,17 @@ pub async fn run_subscriptions_example(client: &Client) -> Result<(), StripeErro | |
price.currency, | ||
); | ||
|
||
let create_items = [CreateSubscriptionItems { price: Some(&price.id), ..Default::default() }]; | ||
let subscription = CreateSubscription::new(&customer.id) | ||
.items(&create_items) | ||
.items(vec![CreateSubscriptionItems { | ||
price: Some(price.id.to_string()), | ||
..Default::default() | ||
}]) | ||
.default_payment_method(&payment_method.id) | ||
.expand(&["items", "items.data.price.product", "schedule"]) | ||
.expand([ | ||
String::from("items"), | ||
String::from("items.data.price.product"), | ||
String::from("schedule"), | ||
]) | ||
.send(client) | ||
.await?; | ||
|
||
|
Oops, something went wrong.