stripe/resources/generated/
customer_session.rs

1// ======================================
2// This file was automatically generated.
3// ======================================
4
5use crate::client::{Client, Response};
6use crate::ids::CustomerId;
7use crate::params::{Expand, Expandable, Object, Timestamp};
8use crate::resources::Customer;
9use serde::{Deserialize, Serialize};
10
11/// The resource representing a Stripe "CustomerSessionResourceCustomerSession".
12///
13/// For more details see <https://stripe.com/docs/api/customer_sessions/object>
14#[derive(Clone, Debug, Default, Deserialize, Serialize)]
15pub struct CustomerSession {
16    /// The client secret of this customer session.
17    ///
18    /// Used on the client to set up secure access to the given `customer`.  The client secret can be used to provide access to `customer` from your frontend.
19    /// It should not be stored, logged, or exposed to anyone other than the relevant customer.
20    /// Make sure that you have TLS enabled on any page that includes the client secret.
21    pub client_secret: String,
22
23    #[serde(skip_serializing_if = "Option::is_none")]
24    pub components: Option<CustomerSessionResourceComponents>,
25
26    /// Time at which the object was created.
27    ///
28    /// Measured in seconds since the Unix epoch.
29    pub created: Timestamp,
30
31    /// The customer the customer session was created for.
32    pub customer: Expandable<Customer>,
33
34    /// The timestamp at which this customer session will expire.
35    pub expires_at: Timestamp,
36
37    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
38    pub livemode: bool,
39}
40
41impl CustomerSession {
42    /// Creates a customer session object that includes a single-use client secret that you can use on your front-end to grant client-side API access for certain customer resources.
43    pub fn create(client: &Client, params: CreateCustomerSession<'_>) -> Response<CustomerSession> {
44        #[allow(clippy::needless_borrows_for_generic_args)]
45        client.post_form("/customer_sessions", &params)
46    }
47}
48
49impl Object for CustomerSession {
50    type Id = ();
51    fn id(&self) -> Self::Id {}
52    fn object(&self) -> &'static str {
53        "customer_session"
54    }
55}
56
57#[derive(Clone, Debug, Default, Deserialize, Serialize)]
58pub struct CustomerSessionResourceComponents {
59    pub buy_button: CustomerSessionResourceComponentsResourceBuyButton,
60
61    pub pricing_table: CustomerSessionResourceComponentsResourcePricingTable,
62}
63
64#[derive(Clone, Debug, Default, Deserialize, Serialize)]
65pub struct CustomerSessionResourceComponentsResourceBuyButton {
66    /// Whether the buy button is enabled.
67    pub enabled: bool,
68}
69
70#[derive(Clone, Debug, Default, Deserialize, Serialize)]
71pub struct CustomerSessionResourceComponentsResourcePricingTable {
72    /// Whether the pricing table is enabled.
73    pub enabled: bool,
74}
75
76/// The parameters for `CustomerSession::create`.
77#[derive(Clone, Debug, Serialize)]
78pub struct CreateCustomerSession<'a> {
79    /// Configuration for each component.
80    ///
81    /// Exactly 1 component must be enabled.
82    pub components: CreateCustomerSessionComponents,
83
84    /// The ID of an existing customer for which to create the customer session.
85    pub customer: CustomerId,
86
87    /// Specifies which fields in the response should be expanded.
88    #[serde(skip_serializing_if = "Expand::is_empty")]
89    pub expand: &'a [&'a str],
90}
91
92impl<'a> CreateCustomerSession<'a> {
93    pub fn new(components: CreateCustomerSessionComponents, customer: CustomerId) -> Self {
94        CreateCustomerSession { components, customer, expand: Default::default() }
95    }
96}
97
98#[derive(Clone, Debug, Default, Deserialize, Serialize)]
99pub struct CreateCustomerSessionComponents {
100    /// Configuration for buy button.
101    #[serde(skip_serializing_if = "Option::is_none")]
102    pub buy_button: Option<CreateCustomerSessionComponentsBuyButton>,
103
104    /// Configuration for the pricing table.
105    #[serde(skip_serializing_if = "Option::is_none")]
106    pub pricing_table: Option<CreateCustomerSessionComponentsPricingTable>,
107}
108
109#[derive(Clone, Debug, Default, Deserialize, Serialize)]
110pub struct CreateCustomerSessionComponentsBuyButton {
111    /// Whether the buy button is enabled.
112    pub enabled: bool,
113}
114
115#[derive(Clone, Debug, Default, Deserialize, Serialize)]
116pub struct CreateCustomerSessionComponentsPricingTable {
117    /// Whether the pricing table is enabled.
118    pub enabled: bool,
119}