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#[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 pub fn new() -> Self {
68 Self { inner: ListPromotionCodeBuilder::new() }
69 }
70 pub fn active(mut self, active: impl Into<bool>) -> Self {
72 self.inner.active = Some(active.into());
73 self
74 }
75 pub fn code(mut self, code: impl Into<String>) -> Self {
77 self.inner.code = Some(code.into());
78 self
79 }
80 pub fn coupon(mut self, coupon: impl Into<String>) -> Self {
82 self.inner.coupon = Some(coupon.into());
83 self
84 }
85 pub fn created(mut self, created: impl Into<stripe_types::RangeQueryTs>) -> Self {
88 self.inner.created = Some(created.into());
89 self
90 }
91 pub fn customer(mut self, customer: impl Into<String>) -> Self {
93 self.inner.customer = Some(customer.into());
94 self
95 }
96 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 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 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
110 self.inner.expand = Some(expand.into());
111 self
112 }
113 pub fn limit(mut self, limit: impl Into<i64>) -> Self {
116 self.inner.limit = Some(limit.into());
117 self
118 }
119 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 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 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#[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 pub fn new(promotion_code: impl Into<stripe_shared::PromotionCodeId>) -> Self {
199 Self { promotion_code: promotion_code.into(), inner: RetrievePromotionCodeBuilder::new() }
200 }
201 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 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 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#[derive(Clone, Eq, PartialEq)]
282#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
283#[derive(serde::Serialize)]
284pub struct CreatePromotionCodePromotion {
285 #[serde(skip_serializing_if = "Option::is_none")]
287 pub coupon: Option<String>,
288 #[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#[derive(Clone, Eq, PartialEq)]
305#[non_exhaustive]
306pub enum CreatePromotionCodePromotionType {
307 Coupon,
308 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#[derive(Clone)]
374#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
375#[derive(serde::Serialize)]
376pub struct CreatePromotionCodeRestrictions {
377 #[serde(skip_serializing_if = "Option::is_none")]
380 pub currency_options: Option<std::collections::HashMap<stripe_types::Currency, CurrencyOption>>,
381 #[serde(skip_serializing_if = "Option::is_none")]
383 pub first_time_transaction: Option<bool>,
384 #[serde(skip_serializing_if = "Option::is_none")]
386 pub minimum_amount: Option<i64>,
387 #[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#[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 pub fn new(promotion: impl Into<CreatePromotionCodePromotion>) -> Self {
429 Self { inner: CreatePromotionCodeBuilder::new(promotion.into()) }
430 }
431 pub fn active(mut self, active: impl Into<bool>) -> Self {
433 self.inner.active = Some(active.into());
434 self
435 }
436 pub fn code(mut self, code: impl Into<String>) -> Self {
442 self.inner.code = Some(code.into());
443 self
444 }
445 pub fn customer(mut self, customer: impl Into<String>) -> Self {
447 self.inner.customer = Some(customer.into());
448 self
449 }
450 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 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
458 self.inner.expand = Some(expand.into());
459 self
460 }
461 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 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 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 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 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 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#[derive(Clone)]
544#[cfg_attr(not(feature = "redact-generated-debug"), derive(Debug))]
545#[derive(serde::Serialize)]
546pub struct UpdatePromotionCodeRestrictions {
547 #[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#[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 pub fn new(promotion_code: impl Into<stripe_shared::PromotionCodeId>) -> Self {
586 Self { promotion_code: promotion_code.into(), inner: UpdatePromotionCodeBuilder::new() }
587 }
588 pub fn active(mut self, active: impl Into<bool>) -> Self {
591 self.inner.active = Some(active.into());
592 self
593 }
594 pub fn expand(mut self, expand: impl Into<Vec<String>>) -> Self {
596 self.inner.expand = Some(expand.into());
597 self
598 }
599 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 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 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 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 #[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}