pub struct CreateCheckoutSession<'a> {
Show 29 fields pub after_expiration: Option<CreateCheckoutSessionAfterExpiration>, pub allow_promotion_codes: Option<bool>, pub automatic_tax: Option<CreateCheckoutSessionAutomaticTax>, pub billing_address_collection: Option<CheckoutSessionBillingAddressCollection>, pub cancel_url: &'a str, pub client_reference_id: Option<&'a str>, pub consent_collection: Option<CreateCheckoutSessionConsentCollection>, pub customer: Option<CustomerId>, pub customer_creation: Option<CheckoutSessionCustomerCreation>, pub customer_email: Option<&'a str>, pub customer_update: Option<CreateCheckoutSessionCustomerUpdate>, pub discounts: Option<Vec<CreateCheckoutSessionDiscounts>>, pub expand: &'a [&'a str], pub expires_at: Option<Timestamp>, pub line_items: Option<Vec<CreateCheckoutSessionLineItems>>, pub locale: Option<CheckoutSessionLocale>, pub metadata: Option<Metadata>, pub mode: Option<CheckoutSessionMode>, pub payment_intent_data: Option<CreateCheckoutSessionPaymentIntentData>, pub payment_method_options: Option<CreateCheckoutSessionPaymentMethodOptions>, pub payment_method_types: Option<Vec<CreateCheckoutSessionPaymentMethodTypes>>, pub phone_number_collection: Option<CreateCheckoutSessionPhoneNumberCollection>, pub setup_intent_data: Option<CreateCheckoutSessionSetupIntentData>, pub shipping_address_collection: Option<CreateCheckoutSessionShippingAddressCollection>, pub shipping_options: Option<Vec<CreateCheckoutSessionShippingOptions>>, pub submit_type: Option<CheckoutSessionSubmitType>, pub subscription_data: Option<CreateCheckoutSessionSubscriptionData>, pub success_url: &'a str, pub tax_id_collection: Option<CreateCheckoutSessionTaxIdCollection>,
}
Expand description

The parameters for CheckoutSession::create.

Fields

after_expiration: Option<CreateCheckoutSessionAfterExpiration>

Configure actions after a Checkout Session has expired.

allow_promotion_codes: Option<bool>

Enables user redeemable promotion codes.

automatic_tax: Option<CreateCheckoutSessionAutomaticTax>

Settings for automatic tax lookup for this session and resulting payments, invoices, and subscriptions.

billing_address_collection: Option<CheckoutSessionBillingAddressCollection>

Specify whether Checkout should collect the customer’s billing address.

cancel_url: &'a str

The URL the customer will be directed to if they decide to cancel payment and return to your website.

client_reference_id: Option<&'a str>

A unique string to reference the Checkout Session.

This can be a customer ID, a cart ID, or similar, and can be used to reconcile the session with your internal systems.

consent_collection: Option<CreateCheckoutSessionConsentCollection>

Configure fields for the Checkout Session to gather active consent from customers.

customer: Option<CustomerId>

ID of an existing Customer, if one exists.

In payment mode, the customer’s most recent card payment method will be used to prefill the email, name, card details, and billing address on the Checkout page. In subscription mode, the customer’s default payment method will be used if it’s a card, and otherwise the most recent card will be used. A valid billing address, billing name and billing email are required on the payment method for Checkout to prefill the customer’s card details. If the Customer already has a valid email set, the email will be prefilled and not editable in Checkout. If the Customer does not have a valid email, Checkout will set the email entered during the session on the Customer. If blank for Checkout Sessions in payment or subscription mode, Checkout will create a new Customer object based on information provided during the payment flow. You can set payment_intent_data.setup_future_usage to have Checkout automatically attach the payment method to the Customer you pass in for future reuse.

customer_creation: Option<CheckoutSessionCustomerCreation>

Configure whether a Checkout Session creates a Customer during Session confirmation.

When a Customer is not created, you can still retrieve email, address, and other customer data entered in Checkout with customer_details.

Sessions that don’t create Customers instead create Guest Customers in the Dashboard.

Promotion codes limited to first time customers will return invalid for these Sessions. Can only be set in payment and setup mode.

customer_email: Option<&'a str>

If provided, this value will be used when the Customer object is created. If not provided, customers will be asked to enter their email address. Use this parameter to prefill customer data if you already have an email on file.

To access information about the customer once a session is complete, use the customer field.

customer_update: Option<CreateCheckoutSessionCustomerUpdate>

Controls what fields on Customer can be updated by the Checkout Session.

Can only be provided when customer is provided.

discounts: Option<Vec<CreateCheckoutSessionDiscounts>>

The coupon or promotion code to apply to this Session.

Currently, only up to one may be specified.

expand: &'a [&'a str]

Specifies which fields in the response should be expanded.

expires_at: Option<Timestamp>

The Epoch time in seconds at which the Checkout Session will expire.

It can be anywhere from 1 to 24 hours after Checkout Session creation. By default, this value is 24 hours from creation.

line_items: Option<Vec<CreateCheckoutSessionLineItems>>

A list of items the customer is purchasing.

Use this parameter to pass one-time or recurring Prices. For payment mode, there is a maximum of 100 line items, however it is recommended to consolidate line items if there are more than a few dozen. For subscription mode, there is a maximum of 20 line items with recurring Prices and 20 line items with one-time Prices. Line items with one-time Prices in will be on the initial invoice only.

locale: Option<CheckoutSessionLocale>

The IETF language tag of the locale Checkout is displayed in.

If blank or auto, the browser’s locale is used.

metadata: Option<Metadata>

Set of key-value pairs that you can attach to an object.

This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to metadata.

mode: Option<CheckoutSessionMode>

The mode of the Checkout Session.

Required when using prices or setup mode. Pass subscription if the Checkout Session includes at least one recurring item.

payment_intent_data: Option<CreateCheckoutSessionPaymentIntentData>

A subset of parameters to be passed to PaymentIntent creation for Checkout Sessions in payment mode.

payment_method_options: Option<CreateCheckoutSessionPaymentMethodOptions>

Payment-method-specific configuration.

payment_method_types: Option<Vec<CreateCheckoutSessionPaymentMethodTypes>>

A list of the types of payment methods (e.g., card) this Checkout Session can accept.

Do not include this attribute if you prefer to manage your payment methods from the Stripe Dashboard.

Read more about the supported payment methods and their requirements in our payment method details guide.

If multiple payment methods are passed, Checkout will dynamically reorder them to prioritize the most relevant payment methods based on the customer’s location and other characteristics.

phone_number_collection: Option<CreateCheckoutSessionPhoneNumberCollection>

Controls phone number collection settings for the session.

We recommend that you review your privacy policy and check with your legal contacts before using this feature.

Learn more about collecting phone numbers with Checkout.

setup_intent_data: Option<CreateCheckoutSessionSetupIntentData>

A subset of parameters to be passed to SetupIntent creation for Checkout Sessions in setup mode.

shipping_address_collection: Option<CreateCheckoutSessionShippingAddressCollection>

When set, provides configuration for Checkout to collect a shipping address from a customer.

shipping_options: Option<Vec<CreateCheckoutSessionShippingOptions>>

The shipping rate options to apply to this Session.

submit_type: Option<CheckoutSessionSubmitType>

Describes the type of transaction being performed by Checkout in order to customize relevant text on the page, such as the submit button.

submit_type can only be specified on Checkout Sessions in payment mode, but not Checkout Sessions in subscription or setup mode.

subscription_data: Option<CreateCheckoutSessionSubscriptionData>

A subset of parameters to be passed to subscription creation for Checkout Sessions in subscription mode.

success_url: &'a str

The URL to which Stripe should send customers when payment or setup is complete. If you’d like to use information from the successful Checkout Session on your page, read the guide on customizing your success page.

tax_id_collection: Option<CreateCheckoutSessionTaxIdCollection>

Controls tax ID collection settings for the session.

Implementations

Examples found in repository?
examples/checkout.rs (line 72)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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("test@async-stripe.com"),
            description: Some(
                "A fake customer that is used to illustrate the examples in async-stripe.",
            ),
            metadata: Some(
                [("async-stripe".to_string(), "true".to_string())].iter().cloned().collect(),
            ),

            ..Default::default()
        },
    )
    .await
    .unwrap();

    println!("created a customer at https://dashboard.stripe.com/test/customers/{}", customer.id);

    // create a new exmaple project
    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()
    };

    // and add a price for it in USD
    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()
    );

    // finally, create a checkout session for this product / price
    let checkout_session = {
        let mut params =
            CreateCheckoutSession::new("http://test.com/cancel", "http://test.com/success");
        params.customer = Some(customer.id);
        params.mode = Some(CheckoutSessionMode::Payment);
        params.line_items = Some(vec![CreateCheckoutSessionLineItems {
            quantity: Some(3),
            price: Some(price.id.to_string()),
            ..Default::default()
        }]);
        params.expand = &["line_items", "line_items.data.price.product"];

        CheckoutSession::create(&client, params).await.unwrap()
    };

    println!(
        "created a {} checkout session for {} {:?} for {} {} at {}",
        checkout_session.payment_status,
        checkout_session.line_items.data[0].quantity.unwrap(),
        match checkout_session.line_items.data[0].price.as_ref().unwrap().product.as_ref().unwrap()
        {
            Expandable::Object(p) => p.name.as_ref().unwrap(),
            _ => panic!("product not found"),
        },
        checkout_session.amount_subtotal.unwrap() / 100,
        checkout_session.line_items.data[0].price.as_ref().unwrap().currency.unwrap(),
        checkout_session.url.unwrap()
    );
}

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more