pub struct CheckoutSession {
Show 41 fields pub id: CheckoutSessionId, pub after_expiration: Option<PaymentPagesCheckoutSessionAfterExpiration>, pub allow_promotion_codes: Option<bool>, pub amount_subtotal: Option<i64>, pub amount_total: Option<i64>, pub automatic_tax: PaymentPagesCheckoutSessionAutomaticTax, pub billing_address_collection: Option<CheckoutSessionBillingAddressCollection>, pub cancel_url: String, pub client_reference_id: Option<String>, pub consent: Option<PaymentPagesCheckoutSessionConsent>, pub consent_collection: Option<PaymentPagesCheckoutSessionConsentCollection>, pub currency: Option<Currency>, pub customer: Option<Expandable<Customer>>, pub customer_creation: Option<CheckoutSessionCustomerCreation>, pub customer_details: Option<PaymentPagesCheckoutSessionCustomerDetails>, pub customer_email: Option<String>, pub expires_at: Timestamp, pub line_items: List<CheckoutSessionItem>, pub livemode: bool, pub locale: Option<CheckoutSessionLocale>, pub metadata: Metadata, pub mode: CheckoutSessionMode, pub payment_intent: Option<Expandable<PaymentIntent>>, pub payment_link: Option<Expandable<PaymentLink>>, pub payment_method_options: Option<CheckoutSessionPaymentMethodOptions>, pub payment_method_types: Vec<String>, pub payment_status: CheckoutSessionPaymentStatus, pub phone_number_collection: Option<PaymentPagesCheckoutSessionPhoneNumberCollection>, pub recovered_from: Option<String>, pub setup_intent: Option<Expandable<SetupIntent>>, pub shipping: Option<Shipping>, pub shipping_address_collection: Option<PaymentPagesCheckoutSessionShippingAddressCollection>, pub shipping_options: Vec<PaymentPagesCheckoutSessionShippingOption>, pub shipping_rate: Option<Expandable<ShippingRate>>, pub status: Option<CheckoutSessionStatus>, pub submit_type: Option<CheckoutSessionSubmitType>, pub subscription: Option<Expandable<Subscription>>, pub success_url: String, pub tax_id_collection: Option<PaymentPagesCheckoutSessionTaxIdCollection>, pub total_details: Option<PaymentPagesCheckoutSessionTotalDetails>, pub url: Option<String>,
}
Expand description

The resource representing a Stripe “Session”.

Fields

id: CheckoutSessionId

Unique identifier for the object.

Used to pass to redirectToCheckout in Stripe.js.

after_expiration: Option<PaymentPagesCheckoutSessionAfterExpiration>

When set, provides configuration for actions to take if this Checkout Session expires.

allow_promotion_codes: Option<bool>

Enables user redeemable promotion codes.

amount_subtotal: Option<i64>

Total of all items before discounts or taxes are applied.

amount_total: Option<i64>

Total of all items after discounts and taxes are applied.

automatic_tax: PaymentPagesCheckoutSessionAutomaticTaxbilling_address_collection: Option<CheckoutSessionBillingAddressCollection>

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

cancel_url: String

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

client_reference_id: Option<String>

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: Option<PaymentPagesCheckoutSessionConsent>

Results of consent_collection for this session.

consent_collection: Option<PaymentPagesCheckoutSessionConsentCollection>

When set, provides configuration for the Checkout Session to gather active consent from customers.

currency: Option<Currency>

Three-letter ISO currency code, in lowercase.

Must be a supported currency.

customer: Option<Expandable<Customer>>

The ID of the customer for this Session. For Checkout Sessions in payment or subscription mode, Checkout will create a new customer object based on information provided during the payment flow unless an existing customer was provided when the Session was created.

customer_creation: Option<CheckoutSessionCustomerCreation>

Configure whether a Checkout Session creates a Customer when the Checkout Session completes.

customer_details: Option<PaymentPagesCheckoutSessionCustomerDetails>

The customer details including the customer’s tax exempt status and the customer’s tax IDs.

Only present on Sessions in payment or subscription mode.

customer_email: Option<String>

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 the payment flow is complete, use the customer attribute.

expires_at: Timestamp

The timestamp at which the Checkout Session will expire.

line_items: List<CheckoutSessionItem>

The line items purchased by the customer.

livemode: bool

Has the value true if the object exists in live mode or the value false if the object exists in test mode.

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: 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.

mode: CheckoutSessionMode

The mode of the Checkout Session.

payment_intent: Option<Expandable<PaymentIntent>>

The ID of the PaymentIntent for Checkout Sessions in payment mode.

payment_link: Option<Expandable<PaymentLink>>

The ID of the Payment Link that created this Session.

payment_method_options: Option<CheckoutSessionPaymentMethodOptions>

Payment-method-specific configuration for the PaymentIntent or SetupIntent of this CheckoutSession.

payment_method_types: Vec<String>

A list of the types of payment methods (e.g.

card) this Checkout Session is allowed to accept.

payment_status: CheckoutSessionPaymentStatus

The payment status of the Checkout Session, one of paid, unpaid, or no_payment_required. You can use this value to decide when to fulfill your customer’s order.

phone_number_collection: Option<PaymentPagesCheckoutSessionPhoneNumberCollection>recovered_from: Option<String>

The ID of the original expired Checkout Session that triggered the recovery flow.

setup_intent: Option<Expandable<SetupIntent>>

The ID of the SetupIntent for Checkout Sessions in setup mode.

shipping: Option<Shipping>

Shipping information for this Checkout Session.

shipping_address_collection: Option<PaymentPagesCheckoutSessionShippingAddressCollection>

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

shipping_options: Vec<PaymentPagesCheckoutSessionShippingOption>

The shipping rate options applied to this Session.

shipping_rate: Option<Expandable<ShippingRate>>

The ID of the ShippingRate for Checkout Sessions in payment mode.

status: Option<CheckoutSessionStatus>

The status of the Checkout Session, one of open, complete, or expired.

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: Option<Expandable<Subscription>>

The ID of the subscription for Checkout Sessions in subscription mode.

success_url: String

The URL the customer will be directed to after the payment or subscription creation is successful.

tax_id_collection: Option<PaymentPagesCheckoutSessionTaxIdCollection>total_details: Option<PaymentPagesCheckoutSessionTotalDetails>

Tax and discount details for the computed total amount.

url: Option<String>

The URL to the Checkout Session.

Redirect customers to this URL to take them to Checkout. If you’re using Custom Domains, the URL will use your subdomain. Otherwise, it’ll use checkout.stripe.com..

Implementations

Returns a list of Checkout Sessions.

Creates a Session object.

Examples found in repository?
examples/checkout.rs (line 82)
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

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

The canonical id type for this object.

The id of the object.

The object’s type, typically represented in wire format as the object property.

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