stripe/resources/generated/
ephemeral_key.rs

1// ======================================
2// This file was automatically generated.
3// ======================================
4
5use crate::client::{Client, Response};
6use crate::ids::{CustomerId, EphemeralKeyId, IssuingCardId};
7use crate::params::{Deleted, Expand, Object, Timestamp};
8use serde::{Deserialize, Serialize};
9
10/// The resource representing a Stripe "EphemeralKey".
11#[derive(Clone, Debug, Default, Deserialize, Serialize)]
12pub struct EphemeralKey {
13    /// Unique identifier for the object.
14    pub id: EphemeralKeyId,
15
16    /// Time at which the object was created.
17    ///
18    /// Measured in seconds since the Unix epoch.
19    pub created: Timestamp,
20
21    /// Time at which the key will expire.
22    ///
23    /// Measured in seconds since the Unix epoch.
24    pub expires: Timestamp,
25
26    /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
27    pub livemode: bool,
28
29    /// The key's secret.
30    ///
31    /// You can use this value to make authorized requests to the Stripe API.
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub secret: Option<String>,
34}
35
36impl EphemeralKey {
37    /// Creates a short-lived API key for a given resource.
38    pub fn create(client: &Client, params: CreateEphemeralKey<'_>) -> Response<EphemeralKey> {
39        #[allow(clippy::needless_borrows_for_generic_args)]
40        client.post_form("/ephemeral_keys", &params)
41    }
42
43    /// Invalidates a short-lived API key for a given resource.
44    pub fn delete(client: &Client, id: &EphemeralKeyId) -> Response<Deleted<EphemeralKeyId>> {
45        client.delete(&format!("/ephemeral_keys/{}", id))
46    }
47}
48
49impl Object for EphemeralKey {
50    type Id = EphemeralKeyId;
51    fn id(&self) -> Self::Id {
52        self.id.clone()
53    }
54    fn object(&self) -> &'static str {
55        "ephemeral_key"
56    }
57}
58
59/// The parameters for `EphemeralKey::create`.
60#[derive(Clone, Debug, Serialize, Default)]
61pub struct CreateEphemeralKey<'a> {
62    /// The ID of the Customer you'd like to modify using the resulting ephemeral key.
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub customer: Option<CustomerId>,
65
66    /// Specifies which fields in the response should be expanded.
67    #[serde(skip_serializing_if = "Expand::is_empty")]
68    pub expand: &'a [&'a str],
69
70    /// The ID of the Issuing Card you'd like to access using the resulting ephemeral key.
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub issuing_card: Option<IssuingCardId>,
73
74    /// A single-use token, created by Stripe.js, used for creating ephemeral keys for Issuing Cards without exchanging sensitive information.
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub nonce: Option<&'a str>,
77
78    /// The ID of the Identity VerificationSession you'd like to access using the resulting ephemeral key.
79    #[serde(skip_serializing_if = "Option::is_none")]
80    pub verification_session: Option<&'a str>,
81}
82
83impl<'a> CreateEphemeralKey<'a> {
84    pub fn new() -> Self {
85        CreateEphemeralKey {
86            customer: Default::default(),
87            expand: Default::default(),
88            issuing_card: Default::default(),
89            nonce: Default::default(),
90            verification_session: Default::default(),
91        }
92    }
93}