Skip to main content

stripe_product/promotion_code/
requests.rs

1use stripe_client_core::{
2    RequestBuilder, StripeBlockingClient, StripeClient, StripeMethod, StripeRequest,
3};
4
5#[derive(Clone, Eq, PartialEq)]
6#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
7#[derive(serde::Serialize)]
8struct ListPromotionCodeBuilder {
9    #[serde(skip_serializing_if = "Option::is_none")]
10    active: Option<bool>,
11    #[serde(skip_serializing_if = "Option::is_none")]
12    code: Option<String>,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    coupon: Option<String>,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    created: Option<stripe_types::RangeQueryTs>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    customer: Option<String>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    customer_account: Option<String>,
21    #[serde(skip_serializing_if = "Option::is_none")]
22    ending_before: Option<String>,
23    #[serde(skip_serializing_if = "Option::is_none")]
24    expand: Option<Vec<String>>,
25    #[serde(skip_serializing_if = "Option::is_none")]
26    limit: Option<i64>,
27    #[serde(skip_serializing_if = "Option::is_none")]
28    starting_after: Option<String>,
29}
30#[cfg(feature = "redact-generated-debug")]
31impl std::fmt::Debug for ListPromotionCodeBuilder {
32    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
33        f.debug_struct("ListPromotionCodeBuilder").finish_non_exhaustive()
34    }
35}
36impl ListPromotionCodeBuilder {
37    fn new() -> Self {
38        Self {
39            active: None,
40            code: None,
41            coupon: None,
42            created: None,
43            customer: None,
44            customer_account: None,
45            ending_before: None,
46            expand: None,
47            limit: None,
48            starting_after: None,
49        }
50    }
51}
52/// Returns a list of your promotion codes.
53#[derive(Clone)]
54#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
55#[derive(serde::Serialize)]
56pub struct ListPromotionCode {
57    inner: ListPromotionCodeBuilder,
58}
59#[cfg(feature = "redact-generated-debug")]
60impl std::fmt::Debug for ListPromotionCode {
61    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
62        f.debug_struct("ListPromotionCode").finish_non_exhaustive()
63    }
64}
65impl ListPromotionCode {
66    /// Construct a new `ListPromotionCode`.
67    pub fn new() -> Self {
68        Self { inner: ListPromotionCodeBuilder::new() }
69    }
70    /// Filter promotion codes by whether they are active.
71    pub fn active(mut self, active: impl Into<bool>) -> Self {
72        self.inner.active = Some(active.into());
73        self
74    }
75    /// Only return promotion codes that have this case-insensitive code.
76    pub fn code(mut self, code: impl Into<String>) -> Self {
77        self.inner.code = Some(code.into());
78        self
79    }
80    /// Only return promotion codes for this coupon.
81    pub fn coupon(mut self, coupon: impl Into<String>) -> Self {
82        self.inner.coupon = Some(coupon.into());
83        self
84    }
85    /// A filter on the list, based on the object `created` field.
86    /// The value can be a string with an integer Unix timestamp, or it can be a dictionary with a number of different query options.
87    pub fn created(mut self, created: impl Into<stripe_types::RangeQueryTs>) -> Self {
88        self.inner.created = Some(created.into());
89        self
90    }
91    /// Only return promotion codes that are restricted to this customer.
92    pub fn customer(mut self, customer: impl Into<String>) -> Self {
93        self.inner.customer = Some(customer.into());
94        self
95    }
96    /// Only return promotion codes that are restricted to this account representing the customer.
97    pub fn customer_account(mut self, customer_account: impl Into<String>) -> Self {
98        self.inner.customer_account = Some(customer_account.into());
99        self
100    }
101    /// A cursor for use in pagination.
102    /// `ending_before` is an object ID that defines your place in the list.
103    /// 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.
104    pub fn ending_before(mut self, ending_before: impl Into<String>) -> Self {
105        self.inner.ending_before = Some(ending_before.into());
106        self
107    }
108    /// Specifies which fields in the response should be expanded.
109    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
110        self.inner.expand = Some(expand.into());
111        self
112    }
113    /// A limit on the number of objects to be returned.
114    /// Limit can range between 1 and 100, and the default is 10.
115    pub fn limit(mut self, limit: impl Into<i64>) -> Self {
116        self.inner.limit = Some(limit.into());
117        self
118    }
119    /// A cursor for use in pagination.
120    /// `starting_after` is an object ID that defines your place in the list.
121    /// 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.
122    pub fn starting_after(mut self, starting_after: impl Into<String>) -> Self {
123        self.inner.starting_after = Some(starting_after.into());
124        self
125    }
126}
127impl Default for ListPromotionCode {
128    fn default() -> Self {
129        Self::new()
130    }
131}
132impl ListPromotionCode {
133    /// Send the request and return the deserialized response.
134    pub async fn send<C: StripeClient>(
135        &self,
136        client: &C,
137    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
138        self.customize().send(client).await
139    }
140
141    /// Send the request and return the deserialized response, blocking until completion.
142    pub fn send_blocking<C: StripeBlockingClient>(
143        &self,
144        client: &C,
145    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
146        self.customize().send_blocking(client)
147    }
148
149    pub fn paginate(
150        &self,
151    ) -> stripe_client_core::ListPaginator<stripe_types::List<stripe_shared::PromotionCode>> {
152        stripe_client_core::ListPaginator::new_list("/promotion_codes", &self.inner)
153    }
154}
155
156impl StripeRequest for ListPromotionCode {
157    type Output = stripe_types::List<stripe_shared::PromotionCode>;
158
159    fn build(&self) -> RequestBuilder {
160        RequestBuilder::new(StripeMethod::Get, "/promotion_codes").query(&self.inner)
161    }
162}
163#[derive(Clone, Eq, PartialEq)]
164#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
165#[derive(serde::Serialize)]
166struct RetrievePromotionCodeBuilder {
167    #[serde(skip_serializing_if = "Option::is_none")]
168    expand: Option<Vec<String>>,
169}
170#[cfg(feature = "redact-generated-debug")]
171impl std::fmt::Debug for RetrievePromotionCodeBuilder {
172    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
173        f.debug_struct("RetrievePromotionCodeBuilder").finish_non_exhaustive()
174    }
175}
176impl RetrievePromotionCodeBuilder {
177    fn new() -> Self {
178        Self { expand: None }
179    }
180}
181/// Retrieves the promotion code with the given ID.
182/// In order to retrieve a promotion code by the customer-facing `code` use [list](https://stripe.com/docs/api/promotion_codes/list) with the desired `code`.
183#[derive(Clone)]
184#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
185#[derive(serde::Serialize)]
186pub struct RetrievePromotionCode {
187    inner: RetrievePromotionCodeBuilder,
188    promotion_code: stripe_shared::PromotionCodeId,
189}
190#[cfg(feature = "redact-generated-debug")]
191impl std::fmt::Debug for RetrievePromotionCode {
192    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
193        f.debug_struct("RetrievePromotionCode").finish_non_exhaustive()
194    }
195}
196impl RetrievePromotionCode {
197    /// Construct a new `RetrievePromotionCode`.
198    pub fn new(promotion_code: impl Into<stripe_shared::PromotionCodeId>) -> Self {
199        Self { promotion_code: promotion_code.into(), inner: RetrievePromotionCodeBuilder::new() }
200    }
201    /// Specifies which fields in the response should be expanded.
202    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
203        self.inner.expand = Some(expand.into());
204        self
205    }
206}
207impl RetrievePromotionCode {
208    /// Send the request and return the deserialized response.
209    pub async fn send<C: StripeClient>(
210        &self,
211        client: &C,
212    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
213        self.customize().send(client).await
214    }
215
216    /// Send the request and return the deserialized response, blocking until completion.
217    pub fn send_blocking<C: StripeBlockingClient>(
218        &self,
219        client: &C,
220    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
221        self.customize().send_blocking(client)
222    }
223}
224
225impl StripeRequest for RetrievePromotionCode {
226    type Output = stripe_shared::PromotionCode;
227
228    fn build(&self) -> RequestBuilder {
229        let promotion_code = &self.promotion_code;
230        RequestBuilder::new(StripeMethod::Get, format!("/promotion_codes/{promotion_code}"))
231            .query(&self.inner)
232    }
233}
234#[derive(Clone)]
235#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
236#[derive(serde::Serialize)]
237struct CreatePromotionCodeBuilder {
238    #[serde(skip_serializing_if = "Option::is_none")]
239    active: Option<bool>,
240    #[serde(skip_serializing_if = "Option::is_none")]
241    code: Option<String>,
242    #[serde(skip_serializing_if = "Option::is_none")]
243    customer: Option<String>,
244    #[serde(skip_serializing_if = "Option::is_none")]
245    customer_account: Option<String>,
246    #[serde(skip_serializing_if = "Option::is_none")]
247    expand: Option<Vec<String>>,
248    #[serde(skip_serializing_if = "Option::is_none")]
249    expires_at: Option<stripe_types::Timestamp>,
250    #[serde(skip_serializing_if = "Option::is_none")]
251    max_redemptions: Option<i64>,
252    #[serde(skip_serializing_if = "Option::is_none")]
253    metadata: Option<std::collections::HashMap<String, String>>,
254    promotion: CreatePromotionCodePromotion,
255    #[serde(skip_serializing_if = "Option::is_none")]
256    restrictions: Option<CreatePromotionCodeRestrictions>,
257}
258#[cfg(feature = "redact-generated-debug")]
259impl std::fmt::Debug for CreatePromotionCodeBuilder {
260    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
261        f.debug_struct("CreatePromotionCodeBuilder").finish_non_exhaustive()
262    }
263}
264impl CreatePromotionCodeBuilder {
265    fn new(promotion: impl Into<CreatePromotionCodePromotion>) -> Self {
266        Self {
267            active: None,
268            code: None,
269            customer: None,
270            customer_account: None,
271            expand: None,
272            expires_at: None,
273            max_redemptions: None,
274            metadata: None,
275            promotion: promotion.into(),
276            restrictions: None,
277        }
278    }
279}
280/// The promotion referenced by this promotion code.
281#[derive(Clone, Eq, PartialEq)]
282#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
283#[derive(serde::Serialize)]
284pub struct CreatePromotionCodePromotion {
285    /// If promotion `type` is `coupon`, the coupon for this promotion code.
286    #[serde(skip_serializing_if = "Option::is_none")]
287    pub coupon: Option<String>,
288    /// Specifies the type of promotion.
289    #[serde(rename = "type")]
290    pub type_: CreatePromotionCodePromotionType,
291}
292#[cfg(feature = "redact-generated-debug")]
293impl std::fmt::Debug for CreatePromotionCodePromotion {
294    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
295        f.debug_struct("CreatePromotionCodePromotion").finish_non_exhaustive()
296    }
297}
298impl CreatePromotionCodePromotion {
299    pub fn new(type_: impl Into<CreatePromotionCodePromotionType>) -> Self {
300        Self { coupon: None, type_: type_.into() }
301    }
302}
303/// Specifies the type of promotion.
304#[derive(Clone, Eq, PartialEq)]
305#[non_exhaustive]
306pub enum CreatePromotionCodePromotionType {
307    Coupon,
308    /// An unrecognized value from Stripe. Should not be used as a request parameter.
309    Unknown(String),
310}
311impl CreatePromotionCodePromotionType {
312    pub fn as_str(&self) -> &str {
313        use CreatePromotionCodePromotionType::*;
314        match self {
315            Coupon => "coupon",
316            Unknown(v) => v,
317        }
318    }
319}
320
321impl std::str::FromStr for CreatePromotionCodePromotionType {
322    type Err = std::convert::Infallible;
323    fn from_str(s: &str) -> Result<Self, Self::Err> {
324        use CreatePromotionCodePromotionType::*;
325        match s {
326            "coupon" => Ok(Coupon),
327            v => {
328                tracing::warn!(
329                    "Unknown value '{}' for enum '{}'",
330                    v,
331                    "CreatePromotionCodePromotionType"
332                );
333                Ok(Unknown(v.to_owned()))
334            }
335        }
336    }
337}
338impl std::fmt::Display for CreatePromotionCodePromotionType {
339    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
340        f.write_str(self.as_str())
341    }
342}
343
344#[cfg(not(feature = "redact-generated-debug"))]
345impl std::fmt::Debug for CreatePromotionCodePromotionType {
346    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
347        f.write_str(self.as_str())
348    }
349}
350#[cfg(feature = "redact-generated-debug")]
351impl std::fmt::Debug for CreatePromotionCodePromotionType {
352    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
353        f.debug_struct(stringify!(CreatePromotionCodePromotionType)).finish_non_exhaustive()
354    }
355}
356impl serde::Serialize for CreatePromotionCodePromotionType {
357    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
358    where
359        S: serde::Serializer,
360    {
361        serializer.serialize_str(self.as_str())
362    }
363}
364#[cfg(feature = "deserialize")]
365impl<'de> serde::Deserialize<'de> for CreatePromotionCodePromotionType {
366    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
367        use std::str::FromStr;
368        let s: std::borrow::Cow<'de, str> = serde::Deserialize::deserialize(deserializer)?;
369        Ok(Self::from_str(&s).expect("infallible"))
370    }
371}
372/// Settings that restrict the redemption of the promotion code.
373#[derive(Clone)]
374#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
375#[derive(serde::Serialize)]
376pub struct CreatePromotionCodeRestrictions {
377    /// Promotion codes defined in each available currency option.
378    /// Each key must be a three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html) and a [supported currency](https://stripe.com/docs/currencies).
379    #[serde(skip_serializing_if = "Option::is_none")]
380    pub currency_options: Option<std::collections::HashMap<stripe_types::Currency, CurrencyOption>>,
381    /// A Boolean indicating if the Promotion Code should only be redeemed for Customers without any successful payments or invoices.
382    #[serde(skip_serializing_if = "Option::is_none")]
383    pub first_time_transaction: Option<bool>,
384    /// Minimum amount required to redeem this Promotion Code into a Coupon (e.g., a purchase must be $100 or more to work).
385    #[serde(skip_serializing_if = "Option::is_none")]
386    pub minimum_amount: Option<i64>,
387    /// Three-letter [ISO code](https://stripe.com/docs/currencies) for minimum_amount
388    #[serde(skip_serializing_if = "Option::is_none")]
389    pub minimum_amount_currency: Option<stripe_types::Currency>,
390}
391#[cfg(feature = "redact-generated-debug")]
392impl std::fmt::Debug for CreatePromotionCodeRestrictions {
393    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
394        f.debug_struct("CreatePromotionCodeRestrictions").finish_non_exhaustive()
395    }
396}
397impl CreatePromotionCodeRestrictions {
398    pub fn new() -> Self {
399        Self {
400            currency_options: None,
401            first_time_transaction: None,
402            minimum_amount: None,
403            minimum_amount_currency: None,
404        }
405    }
406}
407impl Default for CreatePromotionCodeRestrictions {
408    fn default() -> Self {
409        Self::new()
410    }
411}
412/// A promotion code points to an underlying promotion.
413/// You can optionally restrict the code to a specific customer, redemption limit, and expiration date.
414#[derive(Clone)]
415#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
416#[derive(serde::Serialize)]
417pub struct CreatePromotionCode {
418    inner: CreatePromotionCodeBuilder,
419}
420#[cfg(feature = "redact-generated-debug")]
421impl std::fmt::Debug for CreatePromotionCode {
422    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
423        f.debug_struct("CreatePromotionCode").finish_non_exhaustive()
424    }
425}
426impl CreatePromotionCode {
427    /// Construct a new `CreatePromotionCode`.
428    pub fn new(promotion: impl Into<CreatePromotionCodePromotion>) -> Self {
429        Self { inner: CreatePromotionCodeBuilder::new(promotion.into()) }
430    }
431    /// Whether the promotion code is currently active.
432    pub fn active(mut self, active: impl Into<bool>) -> Self {
433        self.inner.active = Some(active.into());
434        self
435    }
436    /// The customer-facing code.
437    /// Regardless of case, this code must be unique across all active promotion codes for a specific customer.
438    /// Valid characters are lower case letters (a-z), upper case letters (A-Z), digits (0-9), and dashes (-).
439    ///
440    /// If left blank, we will generate one automatically.
441    pub fn code(mut self, code: impl Into<String>) -> Self {
442        self.inner.code = Some(code.into());
443        self
444    }
445    /// The customer who can use this promotion code. If not set, all customers can use the promotion code.
446    pub fn customer(mut self, customer: impl Into<String>) -> Self {
447        self.inner.customer = Some(customer.into());
448        self
449    }
450    /// The account representing the customer who can use this promotion code.
451    /// If not set, all customers can use the promotion code.
452    pub fn customer_account(mut self, customer_account: impl Into<String>) -> Self {
453        self.inner.customer_account = Some(customer_account.into());
454        self
455    }
456    /// Specifies which fields in the response should be expanded.
457    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
458        self.inner.expand = Some(expand.into());
459        self
460    }
461    /// The timestamp at which this promotion code will expire.
462    /// If the coupon has specified a `redeems_by`, then this value cannot be after the coupon's `redeems_by`.
463    pub fn expires_at(mut self, expires_at: impl Into<stripe_types::Timestamp>) -> Self {
464        self.inner.expires_at = Some(expires_at.into());
465        self
466    }
467    /// A positive integer specifying the number of times the promotion code can be redeemed.
468    /// If the coupon has specified a `max_redemptions`, then this value cannot be greater than the coupon's `max_redemptions`.
469    pub fn max_redemptions(mut self, max_redemptions: impl Into<i64>) -> Self {
470        self.inner.max_redemptions = Some(max_redemptions.into());
471        self
472    }
473    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
474    /// This can be useful for storing additional information about the object in a structured format.
475    /// Individual keys can be unset by posting an empty value to them.
476    /// All keys can be unset by posting an empty value to `metadata`.
477    pub fn metadata(
478        mut self,
479        metadata: impl Into<std::collections::HashMap<String, String>>,
480    ) -> Self {
481        self.inner.metadata = Some(metadata.into());
482        self
483    }
484    /// Settings that restrict the redemption of the promotion code.
485    pub fn restrictions(
486        mut self,
487        restrictions: impl Into<CreatePromotionCodeRestrictions>,
488    ) -> Self {
489        self.inner.restrictions = Some(restrictions.into());
490        self
491    }
492}
493impl CreatePromotionCode {
494    /// Send the request and return the deserialized response.
495    pub async fn send<C: StripeClient>(
496        &self,
497        client: &C,
498    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
499        self.customize().send(client).await
500    }
501
502    /// Send the request and return the deserialized response, blocking until completion.
503    pub fn send_blocking<C: StripeBlockingClient>(
504        &self,
505        client: &C,
506    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
507        self.customize().send_blocking(client)
508    }
509}
510
511impl StripeRequest for CreatePromotionCode {
512    type Output = stripe_shared::PromotionCode;
513
514    fn build(&self) -> RequestBuilder {
515        RequestBuilder::new(StripeMethod::Post, "/promotion_codes").form(&self.inner)
516    }
517}
518#[derive(Clone)]
519#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
520#[derive(serde::Serialize)]
521struct UpdatePromotionCodeBuilder {
522    #[serde(skip_serializing_if = "Option::is_none")]
523    active: Option<bool>,
524    #[serde(skip_serializing_if = "Option::is_none")]
525    expand: Option<Vec<String>>,
526    #[serde(skip_serializing_if = "Option::is_none")]
527    metadata: Option<std::collections::HashMap<String, String>>,
528    #[serde(skip_serializing_if = "Option::is_none")]
529    restrictions: Option<UpdatePromotionCodeRestrictions>,
530}
531#[cfg(feature = "redact-generated-debug")]
532impl std::fmt::Debug for UpdatePromotionCodeBuilder {
533    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
534        f.debug_struct("UpdatePromotionCodeBuilder").finish_non_exhaustive()
535    }
536}
537impl UpdatePromotionCodeBuilder {
538    fn new() -> Self {
539        Self { active: None, expand: None, metadata: None, restrictions: None }
540    }
541}
542/// Settings that restrict the redemption of the promotion code.
543#[derive(Clone)]
544#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
545#[derive(serde::Serialize)]
546pub struct UpdatePromotionCodeRestrictions {
547    /// Promotion codes defined in each available currency option.
548    /// Each key must be a three-letter [ISO currency code](https://www.iso.org/iso-4217-currency-codes.html) and a [supported currency](https://stripe.com/docs/currencies).
549    #[serde(skip_serializing_if = "Option::is_none")]
550    pub currency_options: Option<std::collections::HashMap<stripe_types::Currency, CurrencyOption>>,
551}
552#[cfg(feature = "redact-generated-debug")]
553impl std::fmt::Debug for UpdatePromotionCodeRestrictions {
554    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
555        f.debug_struct("UpdatePromotionCodeRestrictions").finish_non_exhaustive()
556    }
557}
558impl UpdatePromotionCodeRestrictions {
559    pub fn new() -> Self {
560        Self { currency_options: None }
561    }
562}
563impl Default for UpdatePromotionCodeRestrictions {
564    fn default() -> Self {
565        Self::new()
566    }
567}
568/// Updates the specified promotion code by setting the values of the parameters passed.
569/// Most fields are, by design, not editable.
570#[derive(Clone)]
571#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
572#[derive(serde::Serialize)]
573pub struct UpdatePromotionCode {
574    inner: UpdatePromotionCodeBuilder,
575    promotion_code: stripe_shared::PromotionCodeId,
576}
577#[cfg(feature = "redact-generated-debug")]
578impl std::fmt::Debug for UpdatePromotionCode {
579    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
580        f.debug_struct("UpdatePromotionCode").finish_non_exhaustive()
581    }
582}
583impl UpdatePromotionCode {
584    /// Construct a new `UpdatePromotionCode`.
585    pub fn new(promotion_code: impl Into<stripe_shared::PromotionCodeId>) -> Self {
586        Self { promotion_code: promotion_code.into(), inner: UpdatePromotionCodeBuilder::new() }
587    }
588    /// Whether the promotion code is currently active.
589    /// A promotion code can only be reactivated when the coupon is still valid and the promotion code is otherwise redeemable.
590    pub fn active(mut self, active: impl Into<bool>) -> Self {
591        self.inner.active = Some(active.into());
592        self
593    }
594    /// Specifies which fields in the response should be expanded.
595    pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
596        self.inner.expand = Some(expand.into());
597        self
598    }
599    /// Set of [key-value pairs](https://docs.stripe.com/api/metadata) that you can attach to an object.
600    /// This can be useful for storing additional information about the object in a structured format.
601    /// Individual keys can be unset by posting an empty value to them.
602    /// All keys can be unset by posting an empty value to `metadata`.
603    pub fn metadata(
604        mut self,
605        metadata: impl Into<std::collections::HashMap<String, String>>,
606    ) -> Self {
607        self.inner.metadata = Some(metadata.into());
608        self
609    }
610    /// Settings that restrict the redemption of the promotion code.
611    pub fn restrictions(
612        mut self,
613        restrictions: impl Into<UpdatePromotionCodeRestrictions>,
614    ) -> Self {
615        self.inner.restrictions = Some(restrictions.into());
616        self
617    }
618}
619impl UpdatePromotionCode {
620    /// Send the request and return the deserialized response.
621    pub async fn send<C: StripeClient>(
622        &self,
623        client: &C,
624    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
625        self.customize().send(client).await
626    }
627
628    /// Send the request and return the deserialized response, blocking until completion.
629    pub fn send_blocking<C: StripeBlockingClient>(
630        &self,
631        client: &C,
632    ) -> Result<<Self as StripeRequest>::Output, C::Err> {
633        self.customize().send_blocking(client)
634    }
635}
636
637impl StripeRequest for UpdatePromotionCode {
638    type Output = stripe_shared::PromotionCode;
639
640    fn build(&self) -> RequestBuilder {
641        let promotion_code = &self.promotion_code;
642        RequestBuilder::new(StripeMethod::Post, format!("/promotion_codes/{promotion_code}"))
643            .form(&self.inner)
644    }
645}
646
647#[derive(Copy, Clone, Eq, PartialEq)]
648#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
649#[derive(serde::Serialize)]
650pub struct CurrencyOption {
651    /// Minimum amount required to redeem this Promotion Code into a Coupon (e.g., a purchase must be $100 or more to work).
652    #[serde(skip_serializing_if = "Option::is_none")]
653    pub minimum_amount: Option<i64>,
654}
655#[cfg(feature = "redact-generated-debug")]
656impl std::fmt::Debug for CurrencyOption {
657    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
658        f.debug_struct("CurrencyOption").finish_non_exhaustive()
659    }
660}
661impl CurrencyOption {
662    pub fn new() -> Self {
663        Self { minimum_amount: None }
664    }
665}
666impl Default for CurrencyOption {
667    fn default() -> Self {
668        Self::new()
669    }
670}