stripe_core/charge/
requests.rs

1use stripe_client_core::{
2    RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5#[derive(Clone, Debug, serde::Serialize)]
6struct ListChargeBuilder {
7    #[serde(skip_serializing_if = "Option::is_none")]
8    created: Option<stripe_types::RangeQueryTs>,
9    #[serde(skip_serializing_if = "Option::is_none")]
10    customer: Option<String>,
11    #[serde(skip_serializing_if = "Option::is_none")]
12    ending_before: Option<String>,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    expand: Option<Vec<String>>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    limit: Option<i64>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    payment_intent: Option<String>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    starting_after: Option<String>,
21    #[serde(skip_serializing_if = "Option::is_none")]
22    transfer_group: Option<String>,
23}
24impl ListChargeBuilder {
25    fn new() -> Self {
26        Self {
27            created: None,
28            customer: None,
29            ending_before: None,
30            expand: None,
31            limit: None,
32            payment_intent: None,
33            starting_after: None,
34            transfer_group: None,
35        }
36    }
37}
38/// Returns a list of charges you’ve previously created.
39/// The charges are returned in sorted order, with the most recent charges appearing first.
40#[derive(Clone, Debug, serde::Serialize)]
41pub struct ListCharge {
42    inner: ListChargeBuilder,
43}
44impl ListCharge {
45    /// Construct a new `ListCharge`.
46    pub fn new() -> Self {
47        Self { inner: ListChargeBuilder::new() }
48    }
49    /// Only return charges that were created during the given date interval.
50    pub fn created(mut self, created: impl Into<stripe_types::RangeQueryTs>) -> Self {
51        self.inner.created = Some(created.into());
52        self
53    }
54    /// Only return charges for the customer specified by this customer ID.
55    pub fn customer(mut self, customer: impl Into<String>) -> Self {
56        self.inner.customer = Some(customer.into());
57        self
58    }
59    /// A cursor for use in pagination.
60    /// `ending_before` is an object ID that defines your place in the list.
61    /// 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.
62    pub fn ending_before(mut self, ending_before: impl Into<String>) -> Self {
63        self.inner.ending_before = Some(ending_before.into());
64        self
65    }
66    /// Specifies which fields in the response should be expanded.
67    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
68        self.inner.expand = Some(expand.into());
69        self
70    }
71    /// A limit on the number of objects to be returned.
72    /// Limit can range between 1 and 100, and the default is 10.
73    pub fn limit(mut self, limit: impl Into<i64>) -> Self {
74        self.inner.limit = Some(limit.into());
75        self
76    }
77    /// Only return charges that were created by the PaymentIntent specified by this PaymentIntent ID.
78    pub fn payment_intent(mut self, payment_intent: impl Into<String>) -> Self {
79        self.inner.payment_intent = Some(payment_intent.into());
80        self
81    }
82    /// A cursor for use in pagination.
83    /// `starting_after` is an object ID that defines your place in the list.
84    /// 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.
85    pub fn starting_after(mut self, starting_after: impl Into<String>) -> Self {
86        self.inner.starting_after = Some(starting_after.into());
87        self
88    }
89    /// Only return charges for this transfer group, limited to 100.
90    pub fn transfer_group(mut self, transfer_group: impl Into<String>) -> Self {
91        self.inner.transfer_group = Some(transfer_group.into());
92        self
93    }
94}
95impl Default for ListCharge {
96    fn default() -> Self {
97        Self::new()
98    }
99}
100impl ListCharge {
101    /// Send the request and return the deserialized response.
102    pub async fn send<C: StripeClient>(
103        &self,
104        client: &C,
105    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
106        self.customize().send(client).await
107    }
108
109    /// Send the request and return the deserialized response, blocking until completion.
110    pub fn send_blocking<C: StripeBlockingClient>(
111        &self,
112        client: &C,
113    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
114        self.customize().send_blocking(client)
115    }
116
117    pub fn paginate(
118        &self,
119    ) -> stripe_client_core::ListPaginator<stripe_types::List<stripe_shared::Charge>> {
120        stripe_client_core::ListPaginator::new_list("/charges", &self.inner)
121    }
122}
123
124impl StripeRequest for ListCharge {
125    type Output = stripe_types::List<stripe_shared::Charge>;
126
127    fn build(&self) -> RequestBuilder {
128        RequestBuilder::new(StripeMethod::Get, "/charges").query(&self.inner)
129    }
130}
131#[derive(Clone, Debug, serde::Serialize)]
132struct RetrieveChargeBuilder {
133    #[serde(skip_serializing_if = "Option::is_none")]
134    expand: Option<Vec<String>>,
135}
136impl RetrieveChargeBuilder {
137    fn new() -> Self {
138        Self { expand: None }
139    }
140}
141/// Retrieves the details of a charge that has previously been created.
142/// Supply the unique charge ID that was returned from your previous request, and Stripe will return the corresponding charge information.
143/// The same information is returned when creating or refunding the charge.
144#[derive(Clone, Debug, serde::Serialize)]
145pub struct RetrieveCharge {
146    inner: RetrieveChargeBuilder,
147    charge: stripe_shared::ChargeId,
148}
149impl RetrieveCharge {
150    /// Construct a new `RetrieveCharge`.
151    pub fn new(charge: impl Into<stripe_shared::ChargeId>) -> Self {
152        Self { charge: charge.into(), inner: RetrieveChargeBuilder::new() }
153    }
154    /// Specifies which fields in the response should be expanded.
155    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
156        self.inner.expand = Some(expand.into());
157        self
158    }
159}
160impl RetrieveCharge {
161    /// Send the request and return the deserialized response.
162    pub async fn send<C: StripeClient>(
163        &self,
164        client: &C,
165    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
166        self.customize().send(client).await
167    }
168
169    /// Send the request and return the deserialized response, blocking until completion.
170    pub fn send_blocking<C: StripeBlockingClient>(
171        &self,
172        client: &C,
173    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
174        self.customize().send_blocking(client)
175    }
176}
177
178impl StripeRequest for RetrieveCharge {
179    type Output = stripe_shared::Charge;
180
181    fn build(&self) -> RequestBuilder {
182        let charge = &self.charge;
183        RequestBuilder::new(StripeMethod::Get, format!("/charges/{charge}")).query(&self.inner)
184    }
185}
186#[derive(Clone, Debug, serde::Serialize)]
187struct SearchChargeBuilder {
188    #[serde(skip_serializing_if = "Option::is_none")]
189    expand: Option<Vec<String>>,
190    #[serde(skip_serializing_if = "Option::is_none")]
191    limit: Option<i64>,
192    #[serde(skip_serializing_if = "Option::is_none")]
193    page: Option<String>,
194    query: String,
195}
196impl SearchChargeBuilder {
197    fn new(query: impl Into<String>) -> Self {
198        Self { expand: None, limit: None, page: None, query: query.into() }
199    }
200}
201/// Search for charges you’ve previously created using Stripe’s [Search Query Language](https://stripe.com/docs/search#search-query-language).
202/// Don’t use search in read-after-write flows where strict consistency is necessary.
203/// Under normal operating.
204/// conditions, data is searchable in less than a minute.
205/// Occasionally, propagation of new or updated data can be up.
206/// to an hour behind during outages. Search functionality is not available to merchants in India.
207#[derive(Clone, Debug, serde::Serialize)]
208pub struct SearchCharge {
209    inner: SearchChargeBuilder,
210}
211impl SearchCharge {
212    /// Construct a new `SearchCharge`.
213    pub fn new(query: impl Into<String>) -> Self {
214        Self { inner: SearchChargeBuilder::new(query.into()) }
215    }
216    /// Specifies which fields in the response should be expanded.
217    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
218        self.inner.expand = Some(expand.into());
219        self
220    }
221    /// A limit on the number of objects to be returned.
222    /// Limit can range between 1 and 100, and the default is 10.
223    pub fn limit(mut self, limit: impl Into<i64>) -> Self {
224        self.inner.limit = Some(limit.into());
225        self
226    }
227    /// A cursor for pagination across multiple pages of results.
228    /// Don't include this parameter on the first call.
229    /// Use the next_page value returned in a previous response to request subsequent results.
230    pub fn page(mut self, page: impl Into<String>) -> Self {
231        self.inner.page = Some(page.into());
232        self
233    }
234}
235impl SearchCharge {
236    /// Send the request and return the deserialized response.
237    pub async fn send<C: StripeClient>(
238        &self,
239        client: &C,
240    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
241        self.customize().send(client).await
242    }
243
244    /// Send the request and return the deserialized response, blocking until completion.
245    pub fn send_blocking<C: StripeBlockingClient>(
246        &self,
247        client: &C,
248    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
249        self.customize().send_blocking(client)
250    }
251
252    pub fn paginate(
253        &self,
254    ) -> stripe_client_core::ListPaginator<stripe_types::SearchList<stripe_shared::Charge>> {
255        stripe_client_core::ListPaginator::new_search_list("/charges/search", &self.inner)
256    }
257}
258
259impl StripeRequest for SearchCharge {
260    type Output = stripe_types::SearchList<stripe_shared::Charge>;
261
262    fn build(&self) -> RequestBuilder {
263        RequestBuilder::new(StripeMethod::Get, "/charges/search").query(&self.inner)
264    }
265}
266#[derive(Clone, Debug, serde::Serialize)]
267struct CreateChargeBuilder {
268    #[serde(skip_serializing_if = "Option::is_none")]
269    amount: Option<i64>,
270    #[serde(skip_serializing_if = "Option::is_none")]
271    application_fee: Option<i64>,
272    #[serde(skip_serializing_if = "Option::is_none")]
273    application_fee_amount: Option<i64>,
274    #[serde(skip_serializing_if = "Option::is_none")]
275    capture: Option<bool>,
276    #[serde(skip_serializing_if = "Option::is_none")]
277    currency: Option<stripe_types::Currency>,
278    #[serde(skip_serializing_if = "Option::is_none")]
279    customer: Option<String>,
280    #[serde(skip_serializing_if = "Option::is_none")]
281    description: Option<String>,
282    #[serde(skip_serializing_if = "Option::is_none")]
283    destination: Option<CreateChargeDestination>,
284    #[serde(skip_serializing_if = "Option::is_none")]
285    expand: Option<Vec<String>>,
286    #[serde(skip_serializing_if = "Option::is_none")]
287    metadata: Option<std::collections::HashMap<String, String>>,
288    #[serde(skip_serializing_if = "Option::is_none")]
289    on_behalf_of: Option<String>,
290    #[serde(skip_serializing_if = "Option::is_none")]
291    radar_options: Option<CreateChargeRadarOptions>,
292    #[serde(skip_serializing_if = "Option::is_none")]
293    receipt_email: Option<String>,
294    #[serde(skip_serializing_if = "Option::is_none")]
295    shipping: Option<OptionalFieldsShipping>,
296    #[serde(skip_serializing_if = "Option::is_none")]
297    source: Option<String>,
298    #[serde(skip_serializing_if = "Option::is_none")]
299    statement_descriptor: Option<String>,
300    #[serde(skip_serializing_if = "Option::is_none")]
301    statement_descriptor_suffix: Option<String>,
302    #[serde(skip_serializing_if = "Option::is_none")]
303    transfer_data: Option<CreateChargeTransferData>,
304    #[serde(skip_serializing_if = "Option::is_none")]
305    transfer_group: Option<String>,
306}
307impl CreateChargeBuilder {
308    fn new() -> Self {
309        Self {
310            amount: None,
311            application_fee: None,
312            application_fee_amount: None,
313            capture: None,
314            currency: None,
315            customer: None,
316            description: None,
317            destination: None,
318            expand: None,
319            metadata: None,
320            on_behalf_of: None,
321            radar_options: None,
322            receipt_email: None,
323            shipping: None,
324            source: None,
325            statement_descriptor: None,
326            statement_descriptor_suffix: None,
327            transfer_data: None,
328            transfer_group: None,
329        }
330    }
331}
332#[derive(Clone, Debug, serde::Serialize)]
333pub struct CreateChargeDestination {
334    /// ID of an existing, connected Stripe account.
335    pub account: String,
336    /// The amount to transfer to the destination account without creating an `Application Fee` object.
337    /// Cannot be combined with the `application_fee` parameter.
338    /// Must be less than or equal to the charge amount.
339    #[serde(skip_serializing_if = "Option::is_none")]
340    pub amount: Option<i64>,
341}
342impl CreateChargeDestination {
343    pub fn new(account: impl Into<String>) -> Self {
344        Self { account: account.into(), amount: None }
345    }
346}
347/// Options to configure Radar.
348/// See [Radar Session](https://stripe.com/docs/radar/radar-session) for more information.
349#[derive(Clone, Debug, serde::Serialize)]
350pub struct CreateChargeRadarOptions {
351    /// A [Radar Session](https://stripe.com/docs/radar/radar-session) is a snapshot of the browser metadata and device details that help Radar make more accurate predictions on your payments.
352    #[serde(skip_serializing_if = "Option::is_none")]
353    pub session: Option<String>,
354}
355impl CreateChargeRadarOptions {
356    pub fn new() -> Self {
357        Self { session: None }
358    }
359}
360impl Default for CreateChargeRadarOptions {
361    fn default() -> Self {
362        Self::new()
363    }
364}
365/// An optional dictionary including the account to automatically transfer to as part of a destination charge.
366/// [See the Connect documentation](https://stripe.com/docs/connect/destination-charges) for details.
367#[derive(Clone, Debug, serde::Serialize)]
368pub struct CreateChargeTransferData {
369    /// The amount transferred to the destination account, if specified.
370    /// By default, the entire charge amount is transferred to the destination account.
371    #[serde(skip_serializing_if = "Option::is_none")]
372    pub amount: Option<i64>,
373    /// ID of an existing, connected Stripe account.
374    pub destination: String,
375}
376impl CreateChargeTransferData {
377    pub fn new(destination: impl Into<String>) -> Self {
378        Self { amount: None, destination: destination.into() }
379    }
380}
381/// This method is no longer recommended—use the [Payment Intents API](https://stripe.com/docs/api/payment_intents).
382/// to initiate a new payment instead. Confirmation of the PaymentIntent creates the `Charge`
383/// object used to request payment.
384#[derive(Clone, Debug, serde::Serialize)]
385pub struct CreateCharge {
386    inner: CreateChargeBuilder,
387}
388impl CreateCharge {
389    /// Construct a new `CreateCharge`.
390    pub fn new() -> Self {
391        Self { inner: CreateChargeBuilder::new() }
392    }
393    /// Amount intended to be collected by this payment.
394    /// A positive integer representing how much to charge in the [smallest currency unit](https://stripe.com/docs/currencies#zero-decimal) (e.g., 100 cents to charge $1.00 or 100 to charge ¥100, a zero-decimal currency).
395    /// The minimum amount is $0.50 US or [equivalent in charge currency](https://stripe.com/docs/currencies#minimum-and-maximum-charge-amounts).
396    /// The amount value supports up to eight digits (e.g., a value of 99999999 for a USD charge of $999,999.99).
397    pub fn amount(mut self, amount: impl Into<i64>) -> Self {
398        self.inner.amount = Some(amount.into());
399        self
400    }
401    pub fn application_fee(mut self, application_fee: impl Into<i64>) -> Self {
402        self.inner.application_fee = Some(application_fee.into());
403        self
404    }
405    /// A fee in cents (or local equivalent) that will be applied to the charge and transferred to the application owner's Stripe account.
406    /// The request must be made with an OAuth key or the `Stripe-Account` header in order to take an application fee.
407    /// For more information, see the application fees [documentation](https://stripe.com/docs/connect/direct-charges#collect-fees).
408    pub fn application_fee_amount(mut self, application_fee_amount: impl Into<i64>) -> Self {
409        self.inner.application_fee_amount = Some(application_fee_amount.into());
410        self
411    }
412    /// Whether to immediately capture the charge.
413    /// Defaults to `true`.
414    /// When `false`, the charge issues an authorization (or pre-authorization), and will need to be [captured](https://stripe.com/docs/api#capture_charge) later.
415    /// Uncaptured charges expire after a set number of days (7 by default).
416    /// For more information, see the [authorizing charges and settling later](https://stripe.com/docs/charges/placing-a-hold) documentation.
417    pub fn capture(mut self, capture: impl Into<bool>) -> Self {
418        self.inner.capture = Some(capture.into());
419        self
420    }
421    /// Three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html), in lowercase.
422    /// Must be a [supported currency](https://stripe.com/docs/currencies).
423    pub fn currency(mut self, currency: impl Into<stripe_types::Currency>) -> Self {
424        self.inner.currency = Some(currency.into());
425        self
426    }
427    /// The ID of an existing customer that will be charged in this request.
428    pub fn customer(mut self, customer: impl Into<String>) -> Self {
429        self.inner.customer = Some(customer.into());
430        self
431    }
432    /// An arbitrary string which you can attach to a `Charge` object.
433    /// It is displayed when in the web interface alongside the charge.
434    /// Note that if you use Stripe to send automatic email receipts to your customers, your receipt emails will include the `description` of the charge(s) that they are describing.
435    pub fn description(mut self, description: impl Into<String>) -> Self {
436        self.inner.description = Some(description.into());
437        self
438    }
439    pub fn destination(mut self, destination: impl Into<CreateChargeDestination>) -> Self {
440        self.inner.destination = Some(destination.into());
441        self
442    }
443    /// Specifies which fields in the response should be expanded.
444    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
445        self.inner.expand = Some(expand.into());
446        self
447    }
448    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
449    /// This can be useful for storing additional information about the object in a structured format.
450    /// Individual keys can be unset by posting an empty value to them.
451    /// All keys can be unset by posting an empty value to `metadata`.
452    pub fn metadata(
453        mut self,
454        metadata: impl Into<std::collections::HashMap<String, String>>,
455    ) -> Self {
456        self.inner.metadata = Some(metadata.into());
457        self
458    }
459    /// The Stripe account ID for which these funds are intended.
460    /// Automatically set if you use the `destination` parameter.
461    /// For details, see [Creating Separate Charges and Transfers](https://stripe.com/docs/connect/separate-charges-and-transfers#settlement-merchant).
462    pub fn on_behalf_of(mut self, on_behalf_of: impl Into<String>) -> Self {
463        self.inner.on_behalf_of = Some(on_behalf_of.into());
464        self
465    }
466    /// Options to configure Radar.
467    /// See [Radar Session](https://stripe.com/docs/radar/radar-session) for more information.
468    pub fn radar_options(mut self, radar_options: impl Into<CreateChargeRadarOptions>) -> Self {
469        self.inner.radar_options = Some(radar_options.into());
470        self
471    }
472    /// The email address to which this charge's [receipt](https://stripe.com/docs/dashboard/receipts) will be sent.
473    /// The receipt will not be sent until the charge is paid, and no receipts will be sent for test mode charges.
474    /// If this charge is for a [Customer](https://stripe.com/docs/api/customers/object), the email address specified here will override the customer's email address.
475    /// If `receipt_email` is specified for a charge in live mode, a receipt will be sent regardless of your [email settings](https://dashboard.stripe.com/account/emails).
476    pub fn receipt_email(mut self, receipt_email: impl Into<String>) -> Self {
477        self.inner.receipt_email = Some(receipt_email.into());
478        self
479    }
480    /// Shipping information for the charge. Helps prevent fraud on charges for physical goods.
481    pub fn shipping(mut self, shipping: impl Into<OptionalFieldsShipping>) -> Self {
482        self.inner.shipping = Some(shipping.into());
483        self
484    }
485    /// A payment source to be charged.
486    /// This can be the ID of a [card](https://stripe.com/docs/api#cards) (i.e., credit or debit card), a [bank account](https://stripe.com/docs/api#bank_accounts), a [source](https://stripe.com/docs/api#sources), a [token](https://stripe.com/docs/api#tokens), or a [connected account](https://stripe.com/docs/connect/account-debits#charging-a-connected-account).
487    /// For certain sources---namely, [cards](https://stripe.com/docs/api#cards), [bank accounts](https://stripe.com/docs/api#bank_accounts), and attached [sources](https://stripe.com/docs/api#sources)---you must also pass the ID of the associated customer.
488    pub fn source(mut self, source: impl Into<String>) -> Self {
489        self.inner.source = Some(source.into());
490        self
491    }
492    /// For a non-card charge, text that appears on the customer's statement as the statement descriptor.
493    /// This value overrides the account's default statement descriptor.
494    /// For information about requirements, including the 22-character limit, see [the Statement Descriptor docs](https://docs.stripe.com/get-started/account/statement-descriptors).
495    ///
496    /// For a card charge, this value is ignored unless you don't specify a `statement_descriptor_suffix`, in which case this value is used as the suffix.
497    pub fn statement_descriptor(mut self, statement_descriptor: impl Into<String>) -> Self {
498        self.inner.statement_descriptor = Some(statement_descriptor.into());
499        self
500    }
501    /// Provides information about a card charge.
502    /// Concatenated to the account's [statement descriptor prefix](https://docs.stripe.com/get-started/account/statement-descriptors#static) to form the complete statement descriptor that appears on the customer's statement.
503    /// If the account has no prefix value, the suffix is concatenated to the account's statement descriptor.
504    pub fn statement_descriptor_suffix(
505        mut self,
506        statement_descriptor_suffix: impl Into<String>,
507    ) -> Self {
508        self.inner.statement_descriptor_suffix = Some(statement_descriptor_suffix.into());
509        self
510    }
511    /// An optional dictionary including the account to automatically transfer to as part of a destination charge.
512    /// [See the Connect documentation](https://stripe.com/docs/connect/destination-charges) for details.
513    pub fn transfer_data(mut self, transfer_data: impl Into<CreateChargeTransferData>) -> Self {
514        self.inner.transfer_data = Some(transfer_data.into());
515        self
516    }
517    /// A string that identifies this transaction as part of a group.
518    /// For details, see [Grouping transactions](https://stripe.com/docs/connect/separate-charges-and-transfers#transfer-options).
519    pub fn transfer_group(mut self, transfer_group: impl Into<String>) -> Self {
520        self.inner.transfer_group = Some(transfer_group.into());
521        self
522    }
523}
524impl Default for CreateCharge {
525    fn default() -> Self {
526        Self::new()
527    }
528}
529impl CreateCharge {
530    /// Send the request and return the deserialized response.
531    pub async fn send<C: StripeClient>(
532        &self,
533        client: &C,
534    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
535        self.customize().send(client).await
536    }
537
538    /// Send the request and return the deserialized response, blocking until completion.
539    pub fn send_blocking<C: StripeBlockingClient>(
540        &self,
541        client: &C,
542    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
543        self.customize().send_blocking(client)
544    }
545}
546
547impl StripeRequest for CreateCharge {
548    type Output = stripe_shared::Charge;
549
550    fn build(&self) -> RequestBuilder {
551        RequestBuilder::new(StripeMethod::Post, "/charges").form(&self.inner)
552    }
553}
554#[derive(Clone, Debug, serde::Serialize)]
555struct UpdateChargeBuilder {
556    #[serde(skip_serializing_if = "Option::is_none")]
557    customer: Option<String>,
558    #[serde(skip_serializing_if = "Option::is_none")]
559    description: Option<String>,
560    #[serde(skip_serializing_if = "Option::is_none")]
561    expand: Option<Vec<String>>,
562    #[serde(skip_serializing_if = "Option::is_none")]
563    fraud_details: Option<UpdateChargeFraudDetails>,
564    #[serde(skip_serializing_if = "Option::is_none")]
565    metadata: Option<std::collections::HashMap<String, String>>,
566    #[serde(skip_serializing_if = "Option::is_none")]
567    receipt_email: Option<String>,
568    #[serde(skip_serializing_if = "Option::is_none")]
569    shipping: Option<OptionalFieldsShipping>,
570    #[serde(skip_serializing_if = "Option::is_none")]
571    transfer_group: Option<String>,
572}
573impl UpdateChargeBuilder {
574    fn new() -> Self {
575        Self {
576            customer: None,
577            description: None,
578            expand: None,
579            fraud_details: None,
580            metadata: None,
581            receipt_email: None,
582            shipping: None,
583            transfer_group: None,
584        }
585    }
586}
587/// A set of key-value pairs you can attach to a charge giving information about its riskiness.
588/// If you believe a charge is fraudulent, include a `user_report` key with a value of `fraudulent`.
589/// If you believe a charge is safe, include a `user_report` key with a value of `safe`.
590/// Stripe will use the information you send to improve our fraud detection algorithms.
591#[derive(Copy, Clone, Debug, serde::Serialize)]
592pub struct UpdateChargeFraudDetails {
593    /// Either `safe` or `fraudulent`.
594    pub user_report: UpdateChargeFraudDetailsUserReport,
595}
596impl UpdateChargeFraudDetails {
597    pub fn new(user_report: impl Into<UpdateChargeFraudDetailsUserReport>) -> Self {
598        Self { user_report: user_report.into() }
599    }
600}
601/// Either `safe` or `fraudulent`.
602#[derive(Copy, Clone, Eq, PartialEq)]
603pub enum UpdateChargeFraudDetailsUserReport {
604    Fraudulent,
605    Safe,
606}
607impl UpdateChargeFraudDetailsUserReport {
608    pub fn as_str(self) -> &'static str {
609        use UpdateChargeFraudDetailsUserReport::*;
610        match self {
611            Fraudulent => "fraudulent",
612            Safe => "safe",
613        }
614    }
615}
616
617impl std::str::FromStr for UpdateChargeFraudDetailsUserReport {
618    type Err = stripe_types::StripeParseError;
619    fn from_str(s: &str) -> Result<Self, Self::Err> {
620        use UpdateChargeFraudDetailsUserReport::*;
621        match s {
622            "fraudulent" => Ok(Fraudulent),
623            "safe" => Ok(Safe),
624            _ => Err(stripe_types::StripeParseError),
625        }
626    }
627}
628impl std::fmt::Display for UpdateChargeFraudDetailsUserReport {
629    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
630        f.write_str(self.as_str())
631    }
632}
633
634impl std::fmt::Debug for UpdateChargeFraudDetailsUserReport {
635    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
636        f.write_str(self.as_str())
637    }
638}
639impl serde::Serialize for UpdateChargeFraudDetailsUserReport {
640    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
641    where
642        S: serde::Serializer,
643    {
644        serializer.serialize_str(self.as_str())
645    }
646}
647#[cfg(feature = "deserialize")]
648impl<'de> serde::Deserialize<'de> for UpdateChargeFraudDetailsUserReport {
649    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
650        use std::str::FromStr;
651        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
652        Self::from_str(&s).map_err(|_| {
653            serde::de::Error::custom("Unknown value for UpdateChargeFraudDetailsUserReport")
654        })
655    }
656}
657/// Updates the specified charge by setting the values of the parameters passed.
658/// Any parameters not provided will be left unchanged.
659#[derive(Clone, Debug, serde::Serialize)]
660pub struct UpdateCharge {
661    inner: UpdateChargeBuilder,
662    charge: stripe_shared::ChargeId,
663}
664impl UpdateCharge {
665    /// Construct a new `UpdateCharge`.
666    pub fn new(charge: impl Into<stripe_shared::ChargeId>) -> Self {
667        Self { charge: charge.into(), inner: UpdateChargeBuilder::new() }
668    }
669    /// The ID of an existing customer that will be associated with this request.
670    /// This field may only be updated if there is no existing associated customer with this charge.
671    pub fn customer(mut self, customer: impl Into<String>) -> Self {
672        self.inner.customer = Some(customer.into());
673        self
674    }
675    /// An arbitrary string which you can attach to a charge object.
676    /// It is displayed when in the web interface alongside the charge.
677    /// Note that if you use Stripe to send automatic email receipts to your customers, your receipt emails will include the `description` of the charge(s) that they are describing.
678    pub fn description(mut self, description: impl Into<String>) -> Self {
679        self.inner.description = Some(description.into());
680        self
681    }
682    /// Specifies which fields in the response should be expanded.
683    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
684        self.inner.expand = Some(expand.into());
685        self
686    }
687    /// A set of key-value pairs you can attach to a charge giving information about its riskiness.
688    /// If you believe a charge is fraudulent, include a `user_report` key with a value of `fraudulent`.
689    /// If you believe a charge is safe, include a `user_report` key with a value of `safe`.
690    /// Stripe will use the information you send to improve our fraud detection algorithms.
691    pub fn fraud_details(mut self, fraud_details: impl Into<UpdateChargeFraudDetails>) -> Self {
692        self.inner.fraud_details = Some(fraud_details.into());
693        self
694    }
695    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
696    /// This can be useful for storing additional information about the object in a structured format.
697    /// Individual keys can be unset by posting an empty value to them.
698    /// All keys can be unset by posting an empty value to `metadata`.
699    pub fn metadata(
700        mut self,
701        metadata: impl Into<std::collections::HashMap<String, String>>,
702    ) -> Self {
703        self.inner.metadata = Some(metadata.into());
704        self
705    }
706    /// This is the email address that the receipt for this charge will be sent to.
707    /// If this field is updated, then a new email receipt will be sent to the updated address.
708    pub fn receipt_email(mut self, receipt_email: impl Into<String>) -> Self {
709        self.inner.receipt_email = Some(receipt_email.into());
710        self
711    }
712    /// Shipping information for the charge. Helps prevent fraud on charges for physical goods.
713    pub fn shipping(mut self, shipping: impl Into<OptionalFieldsShipping>) -> Self {
714        self.inner.shipping = Some(shipping.into());
715        self
716    }
717    /// A string that identifies this transaction as part of a group.
718    /// `transfer_group` may only be provided if it has not been set.
719    /// See the [Connect documentation](https://stripe.com/docs/connect/separate-charges-and-transfers#transfer-options) for details.
720    pub fn transfer_group(mut self, transfer_group: impl Into<String>) -> Self {
721        self.inner.transfer_group = Some(transfer_group.into());
722        self
723    }
724}
725impl UpdateCharge {
726    /// Send the request and return the deserialized response.
727    pub async fn send<C: StripeClient>(
728        &self,
729        client: &C,
730    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
731        self.customize().send(client).await
732    }
733
734    /// Send the request and return the deserialized response, blocking until completion.
735    pub fn send_blocking<C: StripeBlockingClient>(
736        &self,
737        client: &C,
738    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
739        self.customize().send_blocking(client)
740    }
741}
742
743impl StripeRequest for UpdateCharge {
744    type Output = stripe_shared::Charge;
745
746    fn build(&self) -> RequestBuilder {
747        let charge = &self.charge;
748        RequestBuilder::new(StripeMethod::Post, format!("/charges/{charge}")).form(&self.inner)
749    }
750}
751#[derive(Clone, Debug, serde::Serialize)]
752struct CaptureChargeBuilder {
753    #[serde(skip_serializing_if = "Option::is_none")]
754    amount: Option<i64>,
755    #[serde(skip_serializing_if = "Option::is_none")]
756    application_fee: Option<i64>,
757    #[serde(skip_serializing_if = "Option::is_none")]
758    application_fee_amount: Option<i64>,
759    #[serde(skip_serializing_if = "Option::is_none")]
760    expand: Option<Vec<String>>,
761    #[serde(skip_serializing_if = "Option::is_none")]
762    receipt_email: Option<String>,
763    #[serde(skip_serializing_if = "Option::is_none")]
764    statement_descriptor: Option<String>,
765    #[serde(skip_serializing_if = "Option::is_none")]
766    statement_descriptor_suffix: Option<String>,
767    #[serde(skip_serializing_if = "Option::is_none")]
768    transfer_data: Option<CaptureChargeTransferData>,
769    #[serde(skip_serializing_if = "Option::is_none")]
770    transfer_group: Option<String>,
771}
772impl CaptureChargeBuilder {
773    fn new() -> Self {
774        Self {
775            amount: None,
776            application_fee: None,
777            application_fee_amount: None,
778            expand: None,
779            receipt_email: None,
780            statement_descriptor: None,
781            statement_descriptor_suffix: None,
782            transfer_data: None,
783            transfer_group: None,
784        }
785    }
786}
787/// An optional dictionary including the account to automatically transfer to as part of a destination charge.
788/// [See the Connect documentation](https://stripe.com/docs/connect/destination-charges) for details.
789#[derive(Copy, Clone, Debug, serde::Serialize)]
790pub struct CaptureChargeTransferData {
791    /// The amount transferred to the destination account, if specified.
792    /// By default, the entire charge amount is transferred to the destination account.
793    #[serde(skip_serializing_if = "Option::is_none")]
794    pub amount: Option<i64>,
795}
796impl CaptureChargeTransferData {
797    pub fn new() -> Self {
798        Self { amount: None }
799    }
800}
801impl Default for CaptureChargeTransferData {
802    fn default() -> Self {
803        Self::new()
804    }
805}
806/// Capture the payment of an existing, uncaptured charge that was created with the `capture` option set to false.
807///
808/// Uncaptured payments expire a set number of days after they are created ([7 by default](https://stripe.com/docs/charges/placing-a-hold)), after which they are marked as refunded and capture attempts will fail.
809///
810/// Don’t use this method to capture a PaymentIntent-initiated charge.
811/// Use [Capture a PaymentIntent](https://stripe.com/docs/api/payment_intents/capture).
812#[derive(Clone, Debug, serde::Serialize)]
813pub struct CaptureCharge {
814    inner: CaptureChargeBuilder,
815    charge: stripe_shared::ChargeId,
816}
817impl CaptureCharge {
818    /// Construct a new `CaptureCharge`.
819    pub fn new(charge: impl Into<stripe_shared::ChargeId>) -> Self {
820        Self { charge: charge.into(), inner: CaptureChargeBuilder::new() }
821    }
822    /// The amount to capture, which must be less than or equal to the original amount.
823    pub fn amount(mut self, amount: impl Into<i64>) -> Self {
824        self.inner.amount = Some(amount.into());
825        self
826    }
827    /// An application fee to add on to this charge.
828    pub fn application_fee(mut self, application_fee: impl Into<i64>) -> Self {
829        self.inner.application_fee = Some(application_fee.into());
830        self
831    }
832    /// An application fee amount to add on to this charge, which must be less than or equal to the original amount.
833    pub fn application_fee_amount(mut self, application_fee_amount: impl Into<i64>) -> Self {
834        self.inner.application_fee_amount = Some(application_fee_amount.into());
835        self
836    }
837    /// Specifies which fields in the response should be expanded.
838    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
839        self.inner.expand = Some(expand.into());
840        self
841    }
842    /// The email address to send this charge's receipt to.
843    /// This will override the previously-specified email address for this charge, if one was set.
844    /// Receipts will not be sent in test mode.
845    pub fn receipt_email(mut self, receipt_email: impl Into<String>) -> Self {
846        self.inner.receipt_email = Some(receipt_email.into());
847        self
848    }
849    /// For a non-card charge, text that appears on the customer's statement as the statement descriptor.
850    /// This value overrides the account's default statement descriptor.
851    /// For information about requirements, including the 22-character limit, see [the Statement Descriptor docs](https://docs.stripe.com/get-started/account/statement-descriptors).
852    ///
853    /// For a card charge, this value is ignored unless you don't specify a `statement_descriptor_suffix`, in which case this value is used as the suffix.
854    pub fn statement_descriptor(mut self, statement_descriptor: impl Into<String>) -> Self {
855        self.inner.statement_descriptor = Some(statement_descriptor.into());
856        self
857    }
858    /// Provides information about a card charge.
859    /// Concatenated to the account's [statement descriptor prefix](https://docs.stripe.com/get-started/account/statement-descriptors#static) to form the complete statement descriptor that appears on the customer's statement.
860    /// If the account has no prefix value, the suffix is concatenated to the account's statement descriptor.
861    pub fn statement_descriptor_suffix(
862        mut self,
863        statement_descriptor_suffix: impl Into<String>,
864    ) -> Self {
865        self.inner.statement_descriptor_suffix = Some(statement_descriptor_suffix.into());
866        self
867    }
868    /// An optional dictionary including the account to automatically transfer to as part of a destination charge.
869    /// [See the Connect documentation](https://stripe.com/docs/connect/destination-charges) for details.
870    pub fn transfer_data(mut self, transfer_data: impl Into<CaptureChargeTransferData>) -> Self {
871        self.inner.transfer_data = Some(transfer_data.into());
872        self
873    }
874    /// A string that identifies this transaction as part of a group.
875    /// `transfer_group` may only be provided if it has not been set.
876    /// See the [Connect documentation](https://stripe.com/docs/connect/separate-charges-and-transfers#transfer-options) for details.
877    pub fn transfer_group(mut self, transfer_group: impl Into<String>) -> Self {
878        self.inner.transfer_group = Some(transfer_group.into());
879        self
880    }
881}
882impl CaptureCharge {
883    /// Send the request and return the deserialized response.
884    pub async fn send<C: StripeClient>(
885        &self,
886        client: &C,
887    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
888        self.customize().send(client).await
889    }
890
891    /// Send the request and return the deserialized response, blocking until completion.
892    pub fn send_blocking<C: StripeBlockingClient>(
893        &self,
894        client: &C,
895    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
896        self.customize().send_blocking(client)
897    }
898}
899
900impl StripeRequest for CaptureCharge {
901    type Output = stripe_shared::Charge;
902
903    fn build(&self) -> RequestBuilder {
904        let charge = &self.charge;
905        RequestBuilder::new(StripeMethod::Post, format!("/charges/{charge}/capture"))
906            .form(&self.inner)
907    }
908}
909
910#[derive(Clone, Debug, serde::Serialize)]
911pub struct OptionalFieldsAddress {
912    /// City, district, suburb, town, or village.
913    #[serde(skip_serializing_if = "Option::is_none")]
914    pub city: Option<String>,
915    /// Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
916    #[serde(skip_serializing_if = "Option::is_none")]
917    pub country: Option<String>,
918    /// Address line 1 (e.g., street, PO Box, or company name).
919    #[serde(skip_serializing_if = "Option::is_none")]
920    pub line1: Option<String>,
921    /// Address line 2 (e.g., apartment, suite, unit, or building).
922    #[serde(skip_serializing_if = "Option::is_none")]
923    pub line2: Option<String>,
924    /// ZIP or postal code.
925    #[serde(skip_serializing_if = "Option::is_none")]
926    pub postal_code: Option<String>,
927    /// State, county, province, or region.
928    #[serde(skip_serializing_if = "Option::is_none")]
929    pub state: Option<String>,
930}
931impl OptionalFieldsAddress {
932    pub fn new() -> Self {
933        Self { city: None, country: None, line1: None, line2: None, postal_code: None, state: None }
934    }
935}
936impl Default for OptionalFieldsAddress {
937    fn default() -> Self {
938        Self::new()
939    }
940}
941#[derive(Clone, Debug, serde::Serialize)]
942pub struct OptionalFieldsShipping {
943    /// Shipping address.
944    pub address: OptionalFieldsAddress,
945    /// The delivery service that shipped a physical product, such as Fedex, UPS, USPS, etc.
946    #[serde(skip_serializing_if = "Option::is_none")]
947    pub carrier: Option<String>,
948    /// Recipient name.
949    pub name: String,
950    /// Recipient phone (including extension).
951    #[serde(skip_serializing_if = "Option::is_none")]
952    pub phone: Option<String>,
953    /// The tracking number for a physical product, obtained from the delivery service.
954    /// If multiple tracking numbers were generated for this purchase, please separate them with commas.
955    #[serde(skip_serializing_if = "Option::is_none")]
956    pub tracking_number: Option<String>,
957}
958impl OptionalFieldsShipping {
959    pub fn new(address: impl Into<OptionalFieldsAddress>, name: impl Into<String>) -> Self {
960        Self {
961            address: address.into(),
962            carrier: None,
963            name: name.into(),
964            phone: None,
965            tracking_number: None,
966        }
967    }
968}