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(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(Clone, Eq, PartialEq)]
603#[non_exhaustive]
604pub enum UpdateChargeFraudDetailsUserReport {
605    Fraudulent,
606    Safe,
607    /// An unrecognized value from Stripe. Should not be used as a request parameter.
608    Unknown(String),
609}
610impl UpdateChargeFraudDetailsUserReport {
611    pub fn as_str(&self) -> &str {
612        use UpdateChargeFraudDetailsUserReport::*;
613        match self {
614            Fraudulent => "fraudulent",
615            Safe => "safe",
616            Unknown(v) => v,
617        }
618    }
619}
620
621impl std::str::FromStr for UpdateChargeFraudDetailsUserReport {
622    type Err = std::convert::Infallible;
623    fn from_str(s: &str) -> Result<Self, Self::Err> {
624        use UpdateChargeFraudDetailsUserReport::*;
625        match s {
626            "fraudulent" => Ok(Fraudulent),
627            "safe" => Ok(Safe),
628            v => {
629                tracing::warn!(
630                    "Unknown value '{}' for enum '{}'",
631                    v,
632                    "UpdateChargeFraudDetailsUserReport"
633                );
634                Ok(Unknown(v.to_owned()))
635            }
636        }
637    }
638}
639impl std::fmt::Display for UpdateChargeFraudDetailsUserReport {
640    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
641        f.write_str(self.as_str())
642    }
643}
644
645impl std::fmt::Debug for UpdateChargeFraudDetailsUserReport {
646    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
647        f.write_str(self.as_str())
648    }
649}
650impl serde::Serialize for UpdateChargeFraudDetailsUserReport {
651    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
652    where
653        S: serde::Serializer,
654    {
655        serializer.serialize_str(self.as_str())
656    }
657}
658#[cfg(feature = "deserialize")]
659impl<'de> serde::Deserialize<'de> for UpdateChargeFraudDetailsUserReport {
660    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
661        use std::str::FromStr;
662        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
663        Ok(Self::from_str(&s).expect("infallible"))
664    }
665}
666/// Updates the specified charge by setting the values of the parameters passed.
667/// Any parameters not provided will be left unchanged.
668#[derive(Clone, Debug, serde::Serialize)]
669pub struct UpdateCharge {
670    inner: UpdateChargeBuilder,
671    charge: stripe_shared::ChargeId,
672}
673impl UpdateCharge {
674    /// Construct a new `UpdateCharge`.
675    pub fn new(charge: impl Into<stripe_shared::ChargeId>) -> Self {
676        Self { charge: charge.into(), inner: UpdateChargeBuilder::new() }
677    }
678    /// The ID of an existing customer that will be associated with this request.
679    /// This field may only be updated if there is no existing associated customer with this charge.
680    pub fn customer(mut self, customer: impl Into<String>) -> Self {
681        self.inner.customer = Some(customer.into());
682        self
683    }
684    /// An arbitrary string which you can attach to a charge object.
685    /// It is displayed when in the web interface alongside the charge.
686    /// 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.
687    pub fn description(mut self, description: impl Into<String>) -> Self {
688        self.inner.description = Some(description.into());
689        self
690    }
691    /// Specifies which fields in the response should be expanded.
692    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
693        self.inner.expand = Some(expand.into());
694        self
695    }
696    /// A set of key-value pairs you can attach to a charge giving information about its riskiness.
697    /// If you believe a charge is fraudulent, include a `user_report` key with a value of `fraudulent`.
698    /// If you believe a charge is safe, include a `user_report` key with a value of `safe`.
699    /// Stripe will use the information you send to improve our fraud detection algorithms.
700    pub fn fraud_details(mut self, fraud_details: impl Into<UpdateChargeFraudDetails>) -> Self {
701        self.inner.fraud_details = Some(fraud_details.into());
702        self
703    }
704    /// Set of [key-value pairs](https://stripe.com/docs/api/metadata) that you can attach to an object.
705    /// This can be useful for storing additional information about the object in a structured format.
706    /// Individual keys can be unset by posting an empty value to them.
707    /// All keys can be unset by posting an empty value to `metadata`.
708    pub fn metadata(
709        mut self,
710        metadata: impl Into<std::collections::HashMap<String, String>>,
711    ) -> Self {
712        self.inner.metadata = Some(metadata.into());
713        self
714    }
715    /// This is the email address that the receipt for this charge will be sent to.
716    /// If this field is updated, then a new email receipt will be sent to the updated address.
717    pub fn receipt_email(mut self, receipt_email: impl Into<String>) -> Self {
718        self.inner.receipt_email = Some(receipt_email.into());
719        self
720    }
721    /// Shipping information for the charge. Helps prevent fraud on charges for physical goods.
722    pub fn shipping(mut self, shipping: impl Into<OptionalFieldsShipping>) -> Self {
723        self.inner.shipping = Some(shipping.into());
724        self
725    }
726    /// A string that identifies this transaction as part of a group.
727    /// `transfer_group` may only be provided if it has not been set.
728    /// See the [Connect documentation](https://stripe.com/docs/connect/separate-charges-and-transfers#transfer-options) for details.
729    pub fn transfer_group(mut self, transfer_group: impl Into<String>) -> Self {
730        self.inner.transfer_group = Some(transfer_group.into());
731        self
732    }
733}
734impl UpdateCharge {
735    /// Send the request and return the deserialized response.
736    pub async fn send<C: StripeClient>(
737        &self,
738        client: &C,
739    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
740        self.customize().send(client).await
741    }
742
743    /// Send the request and return the deserialized response, blocking until completion.
744    pub fn send_blocking<C: StripeBlockingClient>(
745        &self,
746        client: &C,
747    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
748        self.customize().send_blocking(client)
749    }
750}
751
752impl StripeRequest for UpdateCharge {
753    type Output = stripe_shared::Charge;
754
755    fn build(&self) -> RequestBuilder {
756        let charge = &self.charge;
757        RequestBuilder::new(StripeMethod::Post, format!("/charges/{charge}")).form(&self.inner)
758    }
759}
760#[derive(Clone, Debug, serde::Serialize)]
761struct CaptureChargeBuilder {
762    #[serde(skip_serializing_if = "Option::is_none")]
763    amount: Option<i64>,
764    #[serde(skip_serializing_if = "Option::is_none")]
765    application_fee: Option<i64>,
766    #[serde(skip_serializing_if = "Option::is_none")]
767    application_fee_amount: Option<i64>,
768    #[serde(skip_serializing_if = "Option::is_none")]
769    expand: Option<Vec<String>>,
770    #[serde(skip_serializing_if = "Option::is_none")]
771    receipt_email: Option<String>,
772    #[serde(skip_serializing_if = "Option::is_none")]
773    statement_descriptor: Option<String>,
774    #[serde(skip_serializing_if = "Option::is_none")]
775    statement_descriptor_suffix: Option<String>,
776    #[serde(skip_serializing_if = "Option::is_none")]
777    transfer_data: Option<CaptureChargeTransferData>,
778    #[serde(skip_serializing_if = "Option::is_none")]
779    transfer_group: Option<String>,
780}
781impl CaptureChargeBuilder {
782    fn new() -> Self {
783        Self {
784            amount: None,
785            application_fee: None,
786            application_fee_amount: None,
787            expand: None,
788            receipt_email: None,
789            statement_descriptor: None,
790            statement_descriptor_suffix: None,
791            transfer_data: None,
792            transfer_group: None,
793        }
794    }
795}
796/// An optional dictionary including the account to automatically transfer to as part of a destination charge.
797/// [See the Connect documentation](https://stripe.com/docs/connect/destination-charges) for details.
798#[derive(Copy, Clone, Debug, serde::Serialize)]
799pub struct CaptureChargeTransferData {
800    /// The amount transferred to the destination account, if specified.
801    /// By default, the entire charge amount is transferred to the destination account.
802    #[serde(skip_serializing_if = "Option::is_none")]
803    pub amount: Option<i64>,
804}
805impl CaptureChargeTransferData {
806    pub fn new() -> Self {
807        Self { amount: None }
808    }
809}
810impl Default for CaptureChargeTransferData {
811    fn default() -> Self {
812        Self::new()
813    }
814}
815/// Capture the payment of an existing, uncaptured charge that was created with the `capture` option set to false.
816///
817/// 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.
818///
819/// Don’t use this method to capture a PaymentIntent-initiated charge.
820/// Use [Capture a PaymentIntent](https://stripe.com/docs/api/payment_intents/capture).
821#[derive(Clone, Debug, serde::Serialize)]
822pub struct CaptureCharge {
823    inner: CaptureChargeBuilder,
824    charge: stripe_shared::ChargeId,
825}
826impl CaptureCharge {
827    /// Construct a new `CaptureCharge`.
828    pub fn new(charge: impl Into<stripe_shared::ChargeId>) -> Self {
829        Self { charge: charge.into(), inner: CaptureChargeBuilder::new() }
830    }
831    /// The amount to capture, which must be less than or equal to the original amount.
832    pub fn amount(mut self, amount: impl Into<i64>) -> Self {
833        self.inner.amount = Some(amount.into());
834        self
835    }
836    /// An application fee to add on to this charge.
837    pub fn application_fee(mut self, application_fee: impl Into<i64>) -> Self {
838        self.inner.application_fee = Some(application_fee.into());
839        self
840    }
841    /// An application fee amount to add on to this charge, which must be less than or equal to the original amount.
842    pub fn application_fee_amount(mut self, application_fee_amount: impl Into<i64>) -> Self {
843        self.inner.application_fee_amount = Some(application_fee_amount.into());
844        self
845    }
846    /// Specifies which fields in the response should be expanded.
847    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
848        self.inner.expand = Some(expand.into());
849        self
850    }
851    /// The email address to send this charge's receipt to.
852    /// This will override the previously-specified email address for this charge, if one was set.
853    /// Receipts will not be sent in test mode.
854    pub fn receipt_email(mut self, receipt_email: impl Into<String>) -> Self {
855        self.inner.receipt_email = Some(receipt_email.into());
856        self
857    }
858    /// For a non-card charge, text that appears on the customer's statement as the statement descriptor.
859    /// This value overrides the account's default statement descriptor.
860    /// For information about requirements, including the 22-character limit, see [the Statement Descriptor docs](https://docs.stripe.com/get-started/account/statement-descriptors).
861    ///
862    /// 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.
863    pub fn statement_descriptor(mut self, statement_descriptor: impl Into<String>) -> Self {
864        self.inner.statement_descriptor = Some(statement_descriptor.into());
865        self
866    }
867    /// Provides information about a card charge.
868    /// 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.
869    /// If the account has no prefix value, the suffix is concatenated to the account's statement descriptor.
870    pub fn statement_descriptor_suffix(
871        mut self,
872        statement_descriptor_suffix: impl Into<String>,
873    ) -> Self {
874        self.inner.statement_descriptor_suffix = Some(statement_descriptor_suffix.into());
875        self
876    }
877    /// An optional dictionary including the account to automatically transfer to as part of a destination charge.
878    /// [See the Connect documentation](https://stripe.com/docs/connect/destination-charges) for details.
879    pub fn transfer_data(mut self, transfer_data: impl Into<CaptureChargeTransferData>) -> Self {
880        self.inner.transfer_data = Some(transfer_data.into());
881        self
882    }
883    /// A string that identifies this transaction as part of a group.
884    /// `transfer_group` may only be provided if it has not been set.
885    /// See the [Connect documentation](https://stripe.com/docs/connect/separate-charges-and-transfers#transfer-options) for details.
886    pub fn transfer_group(mut self, transfer_group: impl Into<String>) -> Self {
887        self.inner.transfer_group = Some(transfer_group.into());
888        self
889    }
890}
891impl CaptureCharge {
892    /// Send the request and return the deserialized response.
893    pub async fn send<C: StripeClient>(
894        &self,
895        client: &C,
896    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
897        self.customize().send(client).await
898    }
899
900    /// Send the request and return the deserialized response, blocking until completion.
901    pub fn send_blocking<C: StripeBlockingClient>(
902        &self,
903        client: &C,
904    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
905        self.customize().send_blocking(client)
906    }
907}
908
909impl StripeRequest for CaptureCharge {
910    type Output = stripe_shared::Charge;
911
912    fn build(&self) -> RequestBuilder {
913        let charge = &self.charge;
914        RequestBuilder::new(StripeMethod::Post, format!("/charges/{charge}/capture"))
915            .form(&self.inner)
916    }
917}
918
919#[derive(Clone, Debug, serde::Serialize)]
920pub struct OptionalFieldsAddress {
921    /// City, district, suburb, town, or village.
922    #[serde(skip_serializing_if = "Option::is_none")]
923    pub city: Option<String>,
924    /// Two-letter country code ([ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)).
925    #[serde(skip_serializing_if = "Option::is_none")]
926    pub country: Option<String>,
927    /// Address line 1, such as the street, PO Box, or company name.
928    #[serde(skip_serializing_if = "Option::is_none")]
929    pub line1: Option<String>,
930    /// Address line 2, such as the apartment, suite, unit, or building.
931    #[serde(skip_serializing_if = "Option::is_none")]
932    pub line2: Option<String>,
933    /// ZIP or postal code.
934    #[serde(skip_serializing_if = "Option::is_none")]
935    pub postal_code: Option<String>,
936    /// State, county, province, or region.
937    #[serde(skip_serializing_if = "Option::is_none")]
938    pub state: Option<String>,
939}
940impl OptionalFieldsAddress {
941    pub fn new() -> Self {
942        Self { city: None, country: None, line1: None, line2: None, postal_code: None, state: None }
943    }
944}
945impl Default for OptionalFieldsAddress {
946    fn default() -> Self {
947        Self::new()
948    }
949}
950#[derive(Clone, Debug, serde::Serialize)]
951pub struct OptionalFieldsShipping {
952    /// Shipping address.
953    pub address: OptionalFieldsAddress,
954    /// The delivery service that shipped a physical product, such as Fedex, UPS, USPS, etc.
955    #[serde(skip_serializing_if = "Option::is_none")]
956    pub carrier: Option<String>,
957    /// Recipient name.
958    pub name: String,
959    /// Recipient phone (including extension).
960    #[serde(skip_serializing_if = "Option::is_none")]
961    pub phone: Option<String>,
962    /// The tracking number for a physical product, obtained from the delivery service.
963    /// If multiple tracking numbers were generated for this purchase, please separate them with commas.
964    #[serde(skip_serializing_if = "Option::is_none")]
965    pub tracking_number: Option<String>,
966}
967impl OptionalFieldsShipping {
968    pub fn new(address: impl Into<OptionalFieldsAddress>, name: impl Into<String>) -> Self {
969        Self {
970            address: address.into(),
971            carrier: None,
972            name: name.into(),
973            phone: None,
974            tracking_number: None,
975        }
976    }
977}