stripe/resources/
setup_intent_ext.rs

1use serde::Serialize;
2
3use crate::client::{Client, Response};
4use crate::params::Expand;
5use crate::resources::SetupIntent;
6use crate::{PaymentMethodId, SetupIntentCancellationReason, SetupIntentId};
7
8/// The set of parameters that can be used when confirming a setup_intent object.
9///
10/// For more details see <https://stripe.com/docs/api/setup_intents/confirm>
11#[derive(Clone, Debug, Serialize)]
12pub struct ConfirmSetupIntent {
13    /// ID of the payment method (a PaymentMethod, Card, or saved Source object) to attach to this SetupIntent.
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub payment_method: Option<PaymentMethodId>,
16
17    /// This hash contains details about the mandate to create
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub mandate_data: Option<MandateData>,
20
21    /// When included, this hash creates a PaymentMethod that is set as the payment_method value in the SetupIntent.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub payment_method_data: Option<crate::UpdatePaymentIntentPaymentMethodData>,
24
25    /// Payment method-specific configuration for this SetupIntent.
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub payment_method_options: Option<crate::UpdatePaymentIntentPaymentMethodOptions>,
28
29    /// The URL to redirect your customer back to after they authenticate on the payment method’s app or site.
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub return_url: Option<String>,
32
33    /// Set to `true` when confirming server-side and using Stripe.js, iOS, or Android client-side SDKs to handle the next actions.
34    pub use_stripe_sdk: bool,
35}
36
37#[derive(Clone, Debug, Default, Serialize)]
38pub struct MandateData {
39    pub customer_acceptance: crate::CustomerAcceptance,
40}
41
42/// The set of parameters that can be used when canceling a setup_intent object.
43///
44/// For more details see <https://stripe.com/docs/api/setup_intents/cancel>
45#[derive(Clone, Debug, Default, Serialize)]
46pub struct CancelSetupIntent {
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub cancellation_reason: Option<SetupIntentCancellationReason>,
49}
50
51/// Verifies microdeposits on a SetupIntent object.
52///
53/// For more details see <https://stripe.com/docs/api/setup_intents/verify_microdeposits>
54#[derive(Clone, Debug, Default, Serialize)]
55pub struct VerifyMicrodeposits<'a> {
56    /// Two positive integers, in cents, equal to the values of the microdeposits sent to the bank account.
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub amounts: Option<Vec<i64>>,
59
60    /// A six-character code starting with SM present in the microdeposit sent to the bank account.
61    #[serde(skip_serializing_if = "Option::is_none")]
62    pub descriptor_code: Option<&'a str>,
63
64    /// Specifies which fields in the response should be expanded.
65    #[serde(skip_serializing_if = "Expand::is_empty")]
66    pub expand: &'a [&'a str],
67}
68
69impl SetupIntent {
70    pub fn confirm(
71        client: &Client,
72        setup_id: &SetupIntentId,
73        params: ConfirmSetupIntent,
74    ) -> Response<SetupIntent> {
75        #[allow(clippy::needless_borrows_for_generic_args)]
76        client.post_form(&format!("/setup_intents/{}/confirm", setup_id), &params)
77    }
78
79    pub fn verify_micro_deposits(
80        client: &Client,
81        setup_id: &SetupIntentId,
82        params: VerifyMicrodeposits,
83    ) -> Response<SetupIntent> {
84        #[allow(clippy::needless_borrows_for_generic_args)]
85        client.post_form(&format!("/setup_intents/{}/verify_microdeposits", setup_id), &params)
86    }
87
88    /// A SetupIntent object can be canceled when it is in one of these statuses: requires_payment_method, requires_confirmation, or requires_action.
89    ///
90    /// For more details see <https://stripe.com/docs/api/setup_intents/cancel>.
91    pub fn cancel(
92        client: &Client,
93        setup_id: &SetupIntentId,
94        params: CancelSetupIntent,
95    ) -> Response<SetupIntent> {
96        client.post_form(&format!("/setup_intents/{}/cancel", setup_id), params)
97    }
98}
99
100#[cfg(test)]
101mod test {}