stripe/model/checkout_session.rs
1use serde::{Serialize, Deserialize};
2use super::{
3 PaymentPagesCheckoutSessionAutomaticTax, PaymentPagesCheckoutSessionCustomFields,
4 PaymentPagesCheckoutSessionCustomText, PaymentPagesCheckoutSessionListLineItems,
5 PaymentPagesCheckoutSessionPhoneNumberCollection,
6 PaymentPagesCheckoutSessionShippingOption, PaymentPagesCheckoutSessionTaxIdCollection,
7};
8/**A Checkout Session represents your customer's session as they pay for
9one-time purchases or subscriptions through [Checkout](https://stripe.com/docs/payments/checkout)
10or [Payment Links](https://stripe.com/docs/payments/payment-links). We recommend creating a
11new Session each time your customer attempts to pay.
12
13Once payment is successful, the Checkout Session will contain a reference
14to the [Customer](https://stripe.com/docs/api/customers), and either the successful
15[PaymentIntent](https://stripe.com/docs/api/payment_intents) or an active
16[Subscription](https://stripe.com/docs/api/subscriptions).
17
18You can create a Checkout Session on your server and redirect to its URL
19to begin Checkout.
20
21Related guide: [Checkout quickstart](https://stripe.com/docs/checkout/quickstart)*/
22#[derive(Debug, Clone, Serialize, Deserialize, Default)]
23pub struct CheckoutSession {
24 ///When set, provides configuration for actions to take if this Checkout Session expires.
25 #[serde(skip_serializing_if = "Option::is_none")]
26 pub after_expiration: Option<serde_json::Value>,
27 ///Enables user redeemable promotion codes.
28 #[serde(skip_serializing_if = "Option::is_none")]
29 pub allow_promotion_codes: Option<bool>,
30 ///Total of all items before discounts or taxes are applied.
31 #[serde(skip_serializing_if = "Option::is_none")]
32 pub amount_subtotal: Option<i64>,
33 ///Total of all items after discounts and taxes are applied.
34 #[serde(skip_serializing_if = "Option::is_none")]
35 pub amount_total: Option<i64>,
36 ///
37 pub automatic_tax: PaymentPagesCheckoutSessionAutomaticTax,
38 ///Describes whether Checkout should collect the customer's billing address.
39 #[serde(skip_serializing_if = "Option::is_none")]
40 pub billing_address_collection: Option<String>,
41 ///If set, Checkout displays a back button and customers will be directed to this URL if they decide to cancel payment and return to your website.
42 #[serde(skip_serializing_if = "Option::is_none")]
43 pub cancel_url: Option<String>,
44 /**A unique string to reference the Checkout Session. This can be a
45customer ID, a cart ID, or similar, and can be used to reconcile the
46Session with your internal systems.*/
47 #[serde(skip_serializing_if = "Option::is_none")]
48 pub client_reference_id: Option<String>,
49 ///Client secret to be used when initializing Stripe.js embedded checkout.
50 #[serde(skip_serializing_if = "Option::is_none")]
51 pub client_secret: Option<String>,
52 ///Results of `consent_collection` for this session.
53 #[serde(skip_serializing_if = "Option::is_none")]
54 pub consent: Option<serde_json::Value>,
55 ///When set, provides configuration for the Checkout Session to gather active consent from customers.
56 #[serde(skip_serializing_if = "Option::is_none")]
57 pub consent_collection: Option<serde_json::Value>,
58 ///Time at which the object was created. Measured in seconds since the Unix epoch.
59 pub created: i64,
60 ///Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase. Must be a [supported currency](https://stripe.com/docs/currencies).
61 #[serde(skip_serializing_if = "Option::is_none")]
62 pub currency: Option<String>,
63 ///Currency conversion details for automatic currency conversion sessions
64 #[serde(skip_serializing_if = "Option::is_none")]
65 pub currency_conversion: Option<serde_json::Value>,
66 ///Collect additional information from your customer using custom fields. Up to 2 fields are supported.
67 pub custom_fields: Vec<PaymentPagesCheckoutSessionCustomFields>,
68 ///
69 pub custom_text: PaymentPagesCheckoutSessionCustomText,
70 /**The ID of the customer for this Session.
71For Checkout Sessions in `subscription` mode or Checkout Sessions with `customer_creation` set as `always` in `payment` mode, Checkout
72will create a new customer object based on information provided
73during the payment flow unless an existing customer was provided when
74the Session was created.*/
75 #[serde(skip_serializing_if = "Option::is_none")]
76 pub customer: Option<serde_json::Value>,
77 ///Configure whether a Checkout Session creates a Customer when the Checkout Session completes.
78 #[serde(skip_serializing_if = "Option::is_none")]
79 pub customer_creation: Option<String>,
80 ///The customer details including the customer's tax exempt status and the customer's tax IDs. Only the customer's email is present on Sessions in `setup` mode.
81 #[serde(skip_serializing_if = "Option::is_none")]
82 pub customer_details: Option<serde_json::Value>,
83 /**If provided, this value will be used when the Customer object is created.
84If not provided, customers will be asked to enter their email address.
85Use this parameter to prefill customer data if you already have an email
86on file. To access information about the customer once the payment flow is
87complete, use the `customer` attribute.*/
88 #[serde(skip_serializing_if = "Option::is_none")]
89 pub customer_email: Option<String>,
90 ///The timestamp at which the Checkout Session will expire.
91 pub expires_at: i64,
92 ///Unique identifier for the object.
93 pub id: String,
94 ///ID of the invoice created by the Checkout Session, if it exists.
95 #[serde(skip_serializing_if = "Option::is_none")]
96 pub invoice: Option<serde_json::Value>,
97 ///Details on the state of invoice creation for the Checkout Session.
98 #[serde(skip_serializing_if = "Option::is_none")]
99 pub invoice_creation: Option<serde_json::Value>,
100 ///The line items purchased by the customer.
101 #[serde(skip_serializing_if = "Option::is_none")]
102 pub line_items: Option<PaymentPagesCheckoutSessionListLineItems>,
103 ///Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
104 pub livemode: bool,
105 ///The IETF language tag of the locale Checkout is displayed in. If blank or `auto`, the browser's locale is used.
106 #[serde(skip_serializing_if = "Option::is_none")]
107 pub locale: Option<String>,
108 ///Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
109 #[serde(skip_serializing_if = "Option::is_none")]
110 pub metadata: Option<serde_json::Value>,
111 ///The mode of the Checkout Session.
112 pub mode: String,
113 ///String representing the object's type. Objects of the same type share the same value.
114 pub object: String,
115 ///The ID of the PaymentIntent for Checkout Sessions in `payment` mode.
116 #[serde(skip_serializing_if = "Option::is_none")]
117 pub payment_intent: Option<serde_json::Value>,
118 ///The ID of the Payment Link that created this Session.
119 #[serde(skip_serializing_if = "Option::is_none")]
120 pub payment_link: Option<serde_json::Value>,
121 ///Configure whether a Checkout Session should collect a payment method.
122 #[serde(skip_serializing_if = "Option::is_none")]
123 pub payment_method_collection: Option<String>,
124 ///Information about the payment method configuration used for this Checkout session if using dynamic payment methods.
125 #[serde(skip_serializing_if = "Option::is_none")]
126 pub payment_method_configuration_details: Option<serde_json::Value>,
127 ///Payment-method-specific configuration for the PaymentIntent or SetupIntent of this CheckoutSession.
128 #[serde(skip_serializing_if = "Option::is_none")]
129 pub payment_method_options: Option<serde_json::Value>,
130 /**A list of the types of payment methods (e.g. card) this Checkout
131Session is allowed to accept.*/
132 pub payment_method_types: Vec<String>,
133 /**The payment status of the Checkout Session, one of `paid`, `unpaid`, or `no_payment_required`.
134You can use this value to decide when to fulfill your customer's order.*/
135 pub payment_status: String,
136 ///
137 #[serde(skip_serializing_if = "Option::is_none")]
138 pub phone_number_collection: Option<
139 PaymentPagesCheckoutSessionPhoneNumberCollection,
140 >,
141 ///The ID of the original expired Checkout Session that triggered the recovery flow.
142 #[serde(skip_serializing_if = "Option::is_none")]
143 pub recovered_from: Option<String>,
144 ///Applies to Checkout Sessions with `ui_mode: embedded`. By default, Stripe will always redirect to your return_url after a successful confirmation. If you set `redirect_on_completion: 'if_required'`, then we will only redirect if your user chooses a redirect-based payment method.
145 #[serde(skip_serializing_if = "Option::is_none")]
146 pub redirect_on_completion: Option<String>,
147 ///Applies to Checkout Sessions with `ui_mode: embedded`. The URL to redirect your customer back to after they authenticate or cancel their payment on the payment method's app or site.
148 #[serde(skip_serializing_if = "Option::is_none")]
149 pub return_url: Option<String>,
150 ///The ID of the SetupIntent for Checkout Sessions in `setup` mode.
151 #[serde(skip_serializing_if = "Option::is_none")]
152 pub setup_intent: Option<serde_json::Value>,
153 ///When set, provides configuration for Checkout to collect a shipping address from a customer.
154 #[serde(skip_serializing_if = "Option::is_none")]
155 pub shipping_address_collection: Option<serde_json::Value>,
156 ///The details of the customer cost of shipping, including the customer chosen ShippingRate.
157 #[serde(skip_serializing_if = "Option::is_none")]
158 pub shipping_cost: Option<serde_json::Value>,
159 ///Shipping information for this Checkout Session.
160 #[serde(skip_serializing_if = "Option::is_none")]
161 pub shipping_details: Option<serde_json::Value>,
162 ///The shipping rate options applied to this Session.
163 pub shipping_options: Vec<PaymentPagesCheckoutSessionShippingOption>,
164 ///The status of the Checkout Session, one of `open`, `complete`, or `expired`.
165 #[serde(skip_serializing_if = "Option::is_none")]
166 pub status: Option<String>,
167 /**Describes the type of transaction being performed by Checkout in order to customize
168relevant text on the page, such as the submit button. `submit_type` can only be
169specified on Checkout Sessions in `payment` mode, but not Checkout Sessions
170in `subscription` or `setup` mode.*/
171 #[serde(skip_serializing_if = "Option::is_none")]
172 pub submit_type: Option<String>,
173 ///The ID of the subscription for Checkout Sessions in `subscription` mode.
174 #[serde(skip_serializing_if = "Option::is_none")]
175 pub subscription: Option<serde_json::Value>,
176 /**The URL the customer will be directed to after the payment or
177subscription creation is successful.*/
178 #[serde(skip_serializing_if = "Option::is_none")]
179 pub success_url: Option<String>,
180 ///
181 #[serde(skip_serializing_if = "Option::is_none")]
182 pub tax_id_collection: Option<PaymentPagesCheckoutSessionTaxIdCollection>,
183 ///Tax and discount details for the computed total amount.
184 #[serde(skip_serializing_if = "Option::is_none")]
185 pub total_details: Option<serde_json::Value>,
186 ///The UI mode of the Session. Can be `hosted` (default) or `embedded`.
187 #[serde(skip_serializing_if = "Option::is_none")]
188 pub ui_mode: Option<String>,
189 /**The URL to the Checkout Session. Redirect customers to this URL to take them to Checkout. If you’re using [Custom Domains](https://stripe.com/docs/payments/checkout/custom-domains), the URL will use your subdomain. Otherwise, it’ll use `checkout.stripe.com.`
190This value is only present when the session is active.*/
191 #[serde(skip_serializing_if = "Option::is_none")]
192 pub url: Option<String>,
193}
194impl std::fmt::Display for CheckoutSession {
195 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
196 write!(f, "{}", serde_json::to_string(self).unwrap())
197 }
198}