Open mikeumus opened 3 years ago
Hi! Yes, it is a string but CheckoutSessionItemId
uses the newtype pattern to provide type safety.
See here: https://docs.rs/stripe-rust/0.12.3/src/stripe/ids.rs.html#121
Luckily CheckoutSessionItemId
implements FromStr
(so does all the rest of the macro-derived string newtypes here) so you should be able to do the following:
CheckoutSessionItem {
id: CheckoutSessionItemId::from_str("val"),
...
}
This is so we can provide errors when you provide an invalid ID for certain types, as some have required prefixes.
My problem with CheckoutSession
is actually the id
field. I'm creating it so how will I know ahead of time what the id will be?
let client = stripe::Client::new(dotenv!("STRIPE_SECRET"));
let price = Price::retrieve(&client, &PriceId::from_str(dotenv!("STRIPE_PRICE_ID"))?, &[]).await.unwrap();
let mut line_items = List::default();
line_items.data.push(CheckoutSessionItem {
amount_total: None,
amount_subtotal: None,
currency: Currency::EUR,
description: "Subscription".to_string(),
id: CheckoutSessionItemId::from_str("yearly")?,
price,
quantity: Some(1),
taxes: None,
});
let session = CheckoutSession {
billing_address_collection: None,
cancel_url: "/api/v1/payment/cancel".to_string(),
client_reference_id: Some(user.id),
customer: None,
customer_email: Some(user_obj.email),
display_items: None,
id: None,
line_items,
livemode: false,
locale: None,
metadata: Metadata::new(),
mode: Some(CheckoutSessionMode::Subscription),
payment_intent: None,
payment_method_types: vec!["card".to_string()],
setup_intent: None,
shipping: None,
shipping_address_collection: None,
submit_type: None,
subscription: None,
success_url: "/api/v1/payment/success".to_string(),
};
It looks like the CheckoutSession
is not completely implemented, you are missing the create
function which normally takes a CreateCheckoutSession
struct as input.
As an example, see how the PaymentIntent works: https://docs.rs/stripe-rust/0.12.3/stripe/struct.PaymentIntent.html#method.create
or the CheckoutSession in the async-stripe fork: https://docs.rs/async-stripe/latest/stripe/struct.CheckoutSession.html
I've been reading through the source trying to figure it out. Got stuck on the
stripe::CheckoutSessionItem::id
:I found this: https://github.com/wyyerd/stripe-rs/blob/624c97259a07547afc4c2e70adaeb7ce4c25b9b2/src/ids.rs#L487
👆 in the source typed as a
String
but trying to set a String as theid
above gives:Any insight would be greatly appreciated. Thank you 🙇🏻♂️