1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
// ====================================== // This file was automatically generated. // ====================================== use crate::config::{Client, Response}; use crate::ids::{CustomerId, PaymentMethodId, SetupIntentId}; use crate::params::{Expand, Expandable, List, Metadata, Object, RangeQuery, Timestamp}; use crate::resources::{Account, ApiErrors, Application, Customer, PaymentMethod}; use serde_derive::{Deserialize, Serialize}; /// The resource representing a Stripe "SetupIntent". /// /// For more details see [https://stripe.com/docs/api/setup_intents/object](https://stripe.com/docs/api/setup_intents/object). #[derive(Clone, Debug, Deserialize, Serialize)] pub struct SetupIntent { /// Unique identifier for the object. pub id: SetupIntentId, /// ID of the Connect application that created the SetupIntent. #[serde(skip_serializing_if = "Option::is_none")] pub application: Option<Expandable<Application>>, /// Reason for cancellation of this SetupIntent, one of `abandoned`, `requested_by_customer`, or `duplicate`. #[serde(skip_serializing_if = "Option::is_none")] pub cancellation_reason: Option<SetupIntentCancellationReason>, /// The client secret of this SetupIntent. /// /// Used for client-side retrieval using a publishable key. The client secret can be used to complete payment setup from your frontend. /// It should not be stored, logged, embedded in URLs, or exposed to anyone other than the customer. /// Make sure that you have TLS enabled on any page that includes the client secret. #[serde(skip_serializing_if = "Option::is_none")] pub client_secret: Option<String>, /// Time at which the object was created. /// /// Measured in seconds since the Unix epoch. pub created: Timestamp, /// ID of the Customer this SetupIntent belongs to, if one exists. /// /// If present, payment methods used with this SetupIntent can only be attached to this Customer, and payment methods attached to other Customers cannot be used with this SetupIntent. #[serde(skip_serializing_if = "Option::is_none")] pub customer: Option<Expandable<Customer>>, /// An arbitrary string attached to the object. /// /// Often useful for displaying to users. #[serde(skip_serializing_if = "Option::is_none")] pub description: Option<String>, /// The error encountered in the previous SetupIntent confirmation. #[serde(skip_serializing_if = "Option::is_none")] pub last_setup_error: Option<ApiErrors>, /// Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode. pub livemode: bool, /// 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. #[serde(default)] pub metadata: Metadata, /// If present, this property tells you what actions you need to take in order for your customer to continue payment setup. #[serde(skip_serializing_if = "Option::is_none")] pub next_action: Option<SetupIntentNextAction>, /// The account (if any) for which the setup is intended. #[serde(skip_serializing_if = "Option::is_none")] pub on_behalf_of: Option<Expandable<Account>>, /// ID of the payment method used with this SetupIntent. #[serde(skip_serializing_if = "Option::is_none")] pub payment_method: Option<Expandable<PaymentMethod>>, /// Payment-method-specific configuration for this SetupIntent. #[serde(skip_serializing_if = "Option::is_none")] pub payment_method_options: Option<SetupIntentPaymentMethodOptions>, /// The list of payment method types (e.g. /// /// card) that this SetupIntent is allowed to set up. pub payment_method_types: Vec<String>, /// [Status](https://stripe.com/docs/payments/intents#intent-statuses) of this SetupIntent, one of `requires_payment_method`, `requires_confirmation`, `requires_action`, `processing`, `canceled`, or `succeeded`. pub status: SetupIntentStatus, /// Indicates how the payment method is intended to be used in the future. /// /// Use `on_session` if you intend to only reuse the payment method when the customer is in your checkout flow. /// /// Use `off_session` if your customer may or may not be in your checkout flow. /// If not provided, this value defaults to `off_session`. pub usage: String, } impl SetupIntent { /// Returns a list of SetupIntents. pub fn list(client: &Client, params: ListSetupIntents<'_>) -> Response<List<SetupIntent>> { client.get_query("/setup_intents", ¶ms) } /// Creates a SetupIntent object. /// /// After the SetupIntent is created, attach a payment method and [confirm](https://stripe.com/docs/api/setup_intents/confirm) /// to collect any required permissions to charge the payment method later. pub fn create(client: &Client, params: CreateSetupIntent<'_>) -> Response<SetupIntent> { client.post_form("/setup_intents", ¶ms) } /// Retrieves the details of a SetupIntent that has previously been created. /// /// Client-side retrieval using a publishable key is allowed when the `client_secret` is provided in the query string. /// When retrieved with a publishable key, only a subset of properties will be returned. /// Please refer to the [SetupIntent](https://stripe.com/docs/api#setup_intent_object) object reference for more details. pub fn retrieve(client: &Client, id: &SetupIntentId, expand: &[&str]) -> Response<SetupIntent> { client.get_query(&format!("/setup_intents/{}", id), &Expand { expand }) } /// Updates a SetupIntent object. pub fn update( client: &Client, id: &SetupIntentId, params: UpdateSetupIntent<'_>, ) -> Response<SetupIntent> { client.post_form(&format!("/setup_intents/{}", id), ¶ms) } } impl Object for SetupIntent { type Id = SetupIntentId; fn id(&self) -> Self::Id { self.id.clone() } fn object(&self) -> &'static str { "setup_intent" } } #[derive(Clone, Debug, Deserialize, Serialize)] pub struct SetupIntentNextAction { #[serde(skip_serializing_if = "Option::is_none")] pub redirect_to_url: Option<SetupIntentNextActionRedirectToUrl>, /// Type of the next action to perform, one of `redirect_to_url` or `use_stripe_sdk`. #[serde(rename = "type")] pub type_: String, /// When confirming a SetupIntent with Stripe.js, Stripe.js depends on the contents of this dictionary to invoke authentication flows. /// /// The shape of the contents is subject to change and is only intended to be used by Stripe.js. #[serde(skip_serializing_if = "Option::is_none")] pub use_stripe_sdk: Option<serde_json::Value>, } #[derive(Clone, Debug, Deserialize, Serialize)] pub struct SetupIntentNextActionRedirectToUrl { /// If the customer does not exit their browser while authenticating, they will be redirected to this specified URL after completion. #[serde(skip_serializing_if = "Option::is_none")] pub return_url: Option<String>, /// The URL you must redirect your customer to in order to authenticate. #[serde(skip_serializing_if = "Option::is_none")] pub url: Option<String>, } #[derive(Clone, Debug, Deserialize, Serialize)] pub struct SetupIntentPaymentMethodOptions { #[serde(skip_serializing_if = "Option::is_none")] pub card: Option<SetupIntentPaymentMethodOptionsCard>, } #[derive(Clone, Debug, Deserialize, Serialize)] pub struct SetupIntentPaymentMethodOptionsCard { /// We strongly recommend that you rely on our SCA Engine to automatically prompt your customers for authentication based on risk level and [other requirements](https://stripe.com/docs/strong-customer-authentication). /// /// However, if you wish to request 3D Secure based on logic from your own fraud engine, provide this option. /// Permitted values include: `automatic` or `any`. /// If not provided, defaults to `automatic`. /// Read our guide on [manually requesting 3D Secure](https://stripe.com/docs/payments/3d-secure#manual-three-ds) for more information on how this configuration interacts with Radar and our SCA Engine. #[serde(skip_serializing_if = "Option::is_none")] pub request_three_d_secure: Option<SetupIntentPaymentMethodOptionsCardRequestThreeDSecure>, } /// The parameters for `SetupIntent::create`. #[derive(Clone, Debug, Serialize, Default)] pub struct CreateSetupIntent<'a> { /// Set to `true` to attempt to confirm this SetupIntent immediately. /// /// This parameter defaults to `false`. /// If the payment method attached is a card, a return_url may be provided in case additional authentication is required. #[serde(skip_serializing_if = "Option::is_none")] pub confirm: Option<bool>, /// ID of the Customer this SetupIntent belongs to, if one exists. /// /// If present, payment methods used with this SetupIntent can only be attached to this Customer, and payment methods attached to other Customers cannot be used with this SetupIntent. #[serde(skip_serializing_if = "Option::is_none")] pub customer: Option<CustomerId>, /// An arbitrary string attached to the object. /// /// Often useful for displaying to users. #[serde(skip_serializing_if = "Option::is_none")] pub description: Option<&'a str>, /// Specifies which fields in the response should be expanded. #[serde(skip_serializing_if = "Expand::is_empty")] pub expand: &'a [&'a str], /// 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. #[serde(skip_serializing_if = "Option::is_none")] pub metadata: Option<Metadata>, /// The Stripe account ID for which this SetupIntent is created. #[serde(skip_serializing_if = "Option::is_none")] pub on_behalf_of: Option<&'a str>, /// ID of the payment method (a PaymentMethod, Card, BankAccount, or saved Source object) to attach to this SetupIntent. #[serde(skip_serializing_if = "Option::is_none")] pub payment_method: Option<PaymentMethodId>, /// Payment-method-specific configuration for this SetupIntent. #[serde(skip_serializing_if = "Option::is_none")] pub payment_method_options: Option<CreateSetupIntentPaymentMethodOptions>, /// The list of payment method types (e.g. /// /// card) that this SetupIntent is allowed to use. /// If this is not provided, defaults to ["card"]. #[serde(skip_serializing_if = "Option::is_none")] pub payment_method_types: Option<Vec<String>>, /// The URL to redirect your customer back to after they authenticate or cancel their payment on the payment method's app or site. /// /// If you'd prefer to redirect to a mobile application, you can alternatively supply an application URI scheme. /// This parameter can only be used with [`confirm=true`](https://stripe.com/docs/api/setup_intents/create#create_setup_intent-confirm). #[serde(skip_serializing_if = "Option::is_none")] pub return_url: Option<&'a str>, } impl<'a> CreateSetupIntent<'a> { pub fn new() -> Self { CreateSetupIntent { confirm: Default::default(), customer: Default::default(), description: Default::default(), expand: Default::default(), metadata: Default::default(), on_behalf_of: Default::default(), payment_method: Default::default(), payment_method_options: Default::default(), payment_method_types: Default::default(), return_url: Default::default(), } } } /// The parameters for `SetupIntent::list`. #[derive(Clone, Debug, Serialize, Default)] pub struct ListSetupIntents<'a> { /// A filter on the list, based on the object `created` field. /// /// The value can be a string with an integer Unix timestamp, or it can be a dictionary with a number of different query options. #[serde(skip_serializing_if = "Option::is_none")] pub created: Option<RangeQuery<Timestamp>>, /// Only return SetupIntents for the customer specified by this customer ID. #[serde(skip_serializing_if = "Option::is_none")] pub customer: Option<CustomerId>, /// A cursor for use in pagination. /// /// `ending_before` is an object ID that defines your place in the list. /// For instance, if you make a list request and receive 100 objects, starting with `obj_bar`, your subsequent call can include `ending_before=obj_bar` in order to fetch the previous page of the list. #[serde(skip_serializing_if = "Option::is_none")] pub ending_before: Option<SetupIntentId>, /// Specifies which fields in the response should be expanded. #[serde(skip_serializing_if = "Expand::is_empty")] pub expand: &'a [&'a str], /// A limit on the number of objects to be returned. /// /// Limit can range between 1 and 100, and the default is 10. #[serde(skip_serializing_if = "Option::is_none")] pub limit: Option<u64>, /// Only return SetupIntents associated with the specified payment method. #[serde(skip_serializing_if = "Option::is_none")] pub payment_method: Option<PaymentMethodId>, /// A cursor for use in pagination. /// /// `starting_after` is an object ID that defines your place in the list. /// For instance, if you make a list request and receive 100 objects, ending with `obj_foo`, your subsequent call can include `starting_after=obj_foo` in order to fetch the next page of the list. #[serde(skip_serializing_if = "Option::is_none")] pub starting_after: Option<SetupIntentId>, } impl<'a> ListSetupIntents<'a> { pub fn new() -> Self { ListSetupIntents { created: Default::default(), customer: Default::default(), ending_before: Default::default(), expand: Default::default(), limit: Default::default(), payment_method: Default::default(), starting_after: Default::default(), } } } /// The parameters for `SetupIntent::update`. #[derive(Clone, Debug, Serialize, Default)] pub struct UpdateSetupIntent<'a> { /// ID of the Customer this SetupIntent belongs to, if one exists. /// /// If present, payment methods used with this SetupIntent can only be attached to this Customer, and payment methods attached to other Customers cannot be used with this SetupIntent. #[serde(skip_serializing_if = "Option::is_none")] pub customer: Option<CustomerId>, /// An arbitrary string attached to the object. /// /// Often useful for displaying to users. #[serde(skip_serializing_if = "Option::is_none")] pub description: Option<&'a str>, /// Specifies which fields in the response should be expanded. #[serde(skip_serializing_if = "Expand::is_empty")] pub expand: &'a [&'a str], /// 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. #[serde(skip_serializing_if = "Option::is_none")] pub metadata: Option<Metadata>, /// ID of the payment method (a PaymentMethod, Card, BankAccount, or saved Source object) to attach to this SetupIntent. #[serde(skip_serializing_if = "Option::is_none")] pub payment_method: Option<PaymentMethodId>, /// The list of payment method types (e.g. /// /// card) that this SetupIntent is allowed to set up. /// If this is not provided, defaults to ["card"]. #[serde(skip_serializing_if = "Option::is_none")] pub payment_method_types: Option<Vec<String>>, } impl<'a> UpdateSetupIntent<'a> { pub fn new() -> Self { UpdateSetupIntent { customer: Default::default(), description: Default::default(), expand: Default::default(), metadata: Default::default(), payment_method: Default::default(), payment_method_types: Default::default(), } } } #[derive(Clone, Debug, Deserialize, Serialize)] pub struct CreateSetupIntentPaymentMethodOptions { #[serde(skip_serializing_if = "Option::is_none")] pub card: Option<CreateSetupIntentPaymentMethodOptionsCard>, } #[derive(Clone, Debug, Deserialize, Serialize)] pub struct CreateSetupIntentPaymentMethodOptionsCard { #[serde(skip_serializing_if = "Option::is_none")] pub request_three_d_secure: Option<CreateSetupIntentPaymentMethodOptionsCardRequestThreeDSecure>, } /// An enum representing the possible values of an `CreateSetupIntentPaymentMethodOptionsCard`'s `request_three_d_secure` field. #[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(rename_all = "snake_case")] pub enum CreateSetupIntentPaymentMethodOptionsCardRequestThreeDSecure { Any, Automatic, } impl CreateSetupIntentPaymentMethodOptionsCardRequestThreeDSecure { pub fn as_str(self) -> &'static str { match self { CreateSetupIntentPaymentMethodOptionsCardRequestThreeDSecure::Any => "any", CreateSetupIntentPaymentMethodOptionsCardRequestThreeDSecure::Automatic => "automatic", } } } impl AsRef<str> for CreateSetupIntentPaymentMethodOptionsCardRequestThreeDSecure { fn as_ref(&self) -> &str { self.as_str() } } impl std::fmt::Display for CreateSetupIntentPaymentMethodOptionsCardRequestThreeDSecure { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { self.as_str().fmt(f) } } /// An enum representing the possible values of an `SetupIntent`'s `cancellation_reason` field. #[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(rename_all = "snake_case")] pub enum SetupIntentCancellationReason { Abandoned, Duplicate, RequestedByCustomer, } impl SetupIntentCancellationReason { pub fn as_str(self) -> &'static str { match self { SetupIntentCancellationReason::Abandoned => "abandoned", SetupIntentCancellationReason::Duplicate => "duplicate", SetupIntentCancellationReason::RequestedByCustomer => "requested_by_customer", } } } impl AsRef<str> for SetupIntentCancellationReason { fn as_ref(&self) -> &str { self.as_str() } } impl std::fmt::Display for SetupIntentCancellationReason { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { self.as_str().fmt(f) } } /// An enum representing the possible values of an `SetupIntentPaymentMethodOptionsCard`'s `request_three_d_secure` field. #[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(rename_all = "snake_case")] pub enum SetupIntentPaymentMethodOptionsCardRequestThreeDSecure { Any, Automatic, ChallengeOnly, } impl SetupIntentPaymentMethodOptionsCardRequestThreeDSecure { pub fn as_str(self) -> &'static str { match self { SetupIntentPaymentMethodOptionsCardRequestThreeDSecure::Any => "any", SetupIntentPaymentMethodOptionsCardRequestThreeDSecure::Automatic => "automatic", SetupIntentPaymentMethodOptionsCardRequestThreeDSecure::ChallengeOnly => { "challenge_only" } } } } impl AsRef<str> for SetupIntentPaymentMethodOptionsCardRequestThreeDSecure { fn as_ref(&self) -> &str { self.as_str() } } impl std::fmt::Display for SetupIntentPaymentMethodOptionsCardRequestThreeDSecure { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { self.as_str().fmt(f) } } /// An enum representing the possible values of an `SetupIntent`'s `status` field. #[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] #[serde(rename_all = "snake_case")] pub enum SetupIntentStatus { Canceled, Processing, RequiresAction, RequiresConfirmation, RequiresPaymentMethod, Succeeded, } impl SetupIntentStatus { pub fn as_str(self) -> &'static str { match self { SetupIntentStatus::Canceled => "canceled", SetupIntentStatus::Processing => "processing", SetupIntentStatus::RequiresAction => "requires_action", SetupIntentStatus::RequiresConfirmation => "requires_confirmation", SetupIntentStatus::RequiresPaymentMethod => "requires_payment_method", SetupIntentStatus::Succeeded => "succeeded", } } } impl AsRef<str> for SetupIntentStatus { fn as_ref(&self) -> &str { self.as_str() } } impl std::fmt::Display for SetupIntentStatus { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { self.as_str().fmt(f) } }