1use crate::client::{Client, Response};
6use crate::ids::{BillingPortalSessionId, CustomerId};
7use crate::params::{Expand, Expandable, Object, Timestamp};
8use crate::resources::BillingPortalConfiguration;
9use serde::{Deserialize, Serialize};
10
11#[derive(Clone, Debug, Default, Deserialize, Serialize)]
13pub struct BillingPortalSession {
14 pub id: BillingPortalSessionId,
16
17 pub configuration: Expandable<BillingPortalConfiguration>,
19
20 pub created: Timestamp,
24
25 pub customer: String,
27
28 pub flow: Option<PortalFlowsFlow>,
32
33 pub livemode: bool,
35
36 pub locale: Option<BillingPortalSessionLocale>,
40
41 pub on_behalf_of: Option<String>,
47
48 pub return_url: Option<String>,
50
51 pub url: String,
53}
54
55impl BillingPortalSession {
56 pub fn create(
58 client: &Client,
59 params: CreateBillingPortalSession<'_>,
60 ) -> Response<BillingPortalSession> {
61 #[allow(clippy::needless_borrows_for_generic_args)]
62 client.post_form("/billing_portal/sessions", ¶ms)
63 }
64}
65
66impl Object for BillingPortalSession {
67 type Id = BillingPortalSessionId;
68 fn id(&self) -> Self::Id {
69 self.id.clone()
70 }
71 fn object(&self) -> &'static str {
72 "billing_portal.session"
73 }
74}
75
76#[derive(Clone, Debug, Default, Deserialize, Serialize)]
77pub struct PortalFlowsFlow {
78 pub after_completion: PortalFlowsFlowAfterCompletion,
79
80 pub subscription_cancel: Option<PortalFlowsFlowSubscriptionCancel>,
82
83 pub subscription_update: Option<PortalFlowsFlowSubscriptionUpdate>,
85
86 pub subscription_update_confirm: Option<PortalFlowsFlowSubscriptionUpdateConfirm>,
88
89 #[serde(rename = "type")]
91 pub type_: PortalFlowsFlowType,
92}
93
94#[derive(Clone, Debug, Default, Deserialize, Serialize)]
95pub struct PortalFlowsFlowAfterCompletion {
96 pub hosted_confirmation: Option<PortalFlowsAfterCompletionHostedConfirmation>,
98
99 pub redirect: Option<PortalFlowsAfterCompletionRedirect>,
101
102 #[serde(rename = "type")]
104 pub type_: PortalFlowsFlowAfterCompletionType,
105}
106
107#[derive(Clone, Debug, Default, Deserialize, Serialize)]
108pub struct PortalFlowsAfterCompletionHostedConfirmation {
109 pub custom_message: Option<String>,
111}
112
113#[derive(Clone, Debug, Default, Deserialize, Serialize)]
114pub struct PortalFlowsAfterCompletionRedirect {
115 pub return_url: String,
117}
118
119#[derive(Clone, Debug, Default, Deserialize, Serialize)]
120pub struct PortalFlowsFlowSubscriptionCancel {
121 pub retention: Option<PortalFlowsRetention>,
123
124 pub subscription: String,
126}
127
128#[derive(Clone, Debug, Default, Deserialize, Serialize)]
129pub struct PortalFlowsFlowSubscriptionUpdate {
130 pub subscription: String,
132}
133
134#[derive(Clone, Debug, Default, Deserialize, Serialize)]
135pub struct PortalFlowsFlowSubscriptionUpdateConfirm {
136 pub discounts: Option<Vec<PortalFlowsSubscriptionUpdateConfirmDiscount>>,
140
141 pub items: Vec<PortalFlowsSubscriptionUpdateConfirmItem>,
145
146 pub subscription: String,
148}
149
150#[derive(Clone, Debug, Default, Deserialize, Serialize)]
151pub struct PortalFlowsRetention {
152 pub coupon_offer: Option<PortalFlowsCouponOffer>,
154
155 #[serde(rename = "type")]
157 pub type_: PortalFlowsRetentionType,
158}
159
160#[derive(Clone, Debug, Default, Deserialize, Serialize)]
161pub struct PortalFlowsCouponOffer {
162 pub coupon: String,
164}
165
166#[derive(Clone, Debug, Default, Deserialize, Serialize)]
167pub struct PortalFlowsSubscriptionUpdateConfirmDiscount {
168 pub coupon: Option<String>,
170
171 pub promotion_code: Option<String>,
173}
174
175#[derive(Clone, Debug, Default, Deserialize, Serialize)]
176pub struct PortalFlowsSubscriptionUpdateConfirmItem {
177 pub id: Option<String>,
179
180 pub price: Option<String>,
184
185 #[serde(skip_serializing_if = "Option::is_none")]
187 pub quantity: Option<u64>,
188}
189
190#[derive(Clone, Debug, Serialize)]
192pub struct CreateBillingPortalSession<'a> {
193 #[serde(skip_serializing_if = "Option::is_none")]
197 pub configuration: Option<&'a str>,
198
199 pub customer: CustomerId,
201
202 #[serde(skip_serializing_if = "Expand::is_empty")]
204 pub expand: &'a [&'a str],
205
206 #[serde(skip_serializing_if = "Option::is_none")]
210 pub flow_data: Option<CreateBillingPortalSessionFlowData>,
211
212 #[serde(skip_serializing_if = "Option::is_none")]
216 pub locale: Option<BillingPortalSessionLocale>,
217
218 #[serde(skip_serializing_if = "Option::is_none")]
224 pub on_behalf_of: Option<&'a str>,
225
226 #[serde(skip_serializing_if = "Option::is_none")]
228 pub return_url: Option<&'a str>,
229}
230
231impl<'a> CreateBillingPortalSession<'a> {
232 pub fn new(customer: CustomerId) -> Self {
233 CreateBillingPortalSession {
234 configuration: Default::default(),
235 customer,
236 expand: Default::default(),
237 flow_data: Default::default(),
238 locale: Default::default(),
239 on_behalf_of: Default::default(),
240 return_url: Default::default(),
241 }
242 }
243}
244
245#[derive(Clone, Debug, Default, Deserialize, Serialize)]
246pub struct CreateBillingPortalSessionFlowData {
247 #[serde(skip_serializing_if = "Option::is_none")]
249 pub after_completion: Option<CreateBillingPortalSessionFlowDataAfterCompletion>,
250
251 #[serde(skip_serializing_if = "Option::is_none")]
253 pub subscription_cancel: Option<CreateBillingPortalSessionFlowDataSubscriptionCancel>,
254
255 #[serde(skip_serializing_if = "Option::is_none")]
257 pub subscription_update: Option<CreateBillingPortalSessionFlowDataSubscriptionUpdate>,
258
259 #[serde(skip_serializing_if = "Option::is_none")]
261 pub subscription_update_confirm:
262 Option<CreateBillingPortalSessionFlowDataSubscriptionUpdateConfirm>,
263
264 #[serde(rename = "type")]
266 pub type_: CreateBillingPortalSessionFlowDataType,
267}
268
269#[derive(Clone, Debug, Default, Deserialize, Serialize)]
270pub struct CreateBillingPortalSessionFlowDataAfterCompletion {
271 #[serde(skip_serializing_if = "Option::is_none")]
273 pub hosted_confirmation:
274 Option<CreateBillingPortalSessionFlowDataAfterCompletionHostedConfirmation>,
275
276 #[serde(skip_serializing_if = "Option::is_none")]
278 pub redirect: Option<CreateBillingPortalSessionFlowDataAfterCompletionRedirect>,
279
280 #[serde(rename = "type")]
282 pub type_: CreateBillingPortalSessionFlowDataAfterCompletionType,
283}
284
285#[derive(Clone, Debug, Default, Deserialize, Serialize)]
286pub struct CreateBillingPortalSessionFlowDataSubscriptionCancel {
287 #[serde(skip_serializing_if = "Option::is_none")]
289 pub retention: Option<CreateBillingPortalSessionFlowDataSubscriptionCancelRetention>,
290
291 pub subscription: String,
293}
294
295#[derive(Clone, Debug, Default, Deserialize, Serialize)]
296pub struct CreateBillingPortalSessionFlowDataSubscriptionUpdate {
297 pub subscription: String,
299}
300
301#[derive(Clone, Debug, Default, Deserialize, Serialize)]
302pub struct CreateBillingPortalSessionFlowDataSubscriptionUpdateConfirm {
303 #[serde(skip_serializing_if = "Option::is_none")]
307 pub discounts:
308 Option<Vec<CreateBillingPortalSessionFlowDataSubscriptionUpdateConfirmDiscounts>>,
309
310 pub items: Vec<CreateBillingPortalSessionFlowDataSubscriptionUpdateConfirmItems>,
314
315 pub subscription: String,
317}
318
319#[derive(Clone, Debug, Default, Deserialize, Serialize)]
320pub struct CreateBillingPortalSessionFlowDataAfterCompletionHostedConfirmation {
321 #[serde(skip_serializing_if = "Option::is_none")]
323 pub custom_message: Option<String>,
324}
325
326#[derive(Clone, Debug, Default, Deserialize, Serialize)]
327pub struct CreateBillingPortalSessionFlowDataAfterCompletionRedirect {
328 pub return_url: String,
330}
331
332#[derive(Clone, Debug, Default, Deserialize, Serialize)]
333pub struct CreateBillingPortalSessionFlowDataSubscriptionCancelRetention {
334 pub coupon_offer: CreateBillingPortalSessionFlowDataSubscriptionCancelRetentionCouponOffer,
336
337 #[serde(rename = "type")]
339 pub type_: CreateBillingPortalSessionFlowDataSubscriptionCancelRetentionType,
340}
341
342#[derive(Clone, Debug, Default, Deserialize, Serialize)]
343pub struct CreateBillingPortalSessionFlowDataSubscriptionUpdateConfirmDiscounts {
344 #[serde(skip_serializing_if = "Option::is_none")]
346 pub coupon: Option<String>,
347
348 #[serde(skip_serializing_if = "Option::is_none")]
350 pub promotion_code: Option<String>,
351}
352
353#[derive(Clone, Debug, Default, Deserialize, Serialize)]
354pub struct CreateBillingPortalSessionFlowDataSubscriptionUpdateConfirmItems {
355 pub id: String,
357
358 #[serde(skip_serializing_if = "Option::is_none")]
362 pub price: Option<String>,
363
364 #[serde(skip_serializing_if = "Option::is_none")]
366 pub quantity: Option<u64>,
367}
368
369#[derive(Clone, Debug, Default, Deserialize, Serialize)]
370pub struct CreateBillingPortalSessionFlowDataSubscriptionCancelRetentionCouponOffer {
371 pub coupon: String,
373}
374
375#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
377#[serde(rename_all = "snake_case")]
378pub enum BillingPortalSessionLocale {
379 Auto,
380 Bg,
381 Cs,
382 Da,
383 De,
384 El,
385 En,
386 #[serde(rename = "en-AU")]
387 EnAu,
388 #[serde(rename = "en-CA")]
389 EnCa,
390 #[serde(rename = "en-GB")]
391 EnGb,
392 #[serde(rename = "en-IE")]
393 EnIe,
394 #[serde(rename = "en-IN")]
395 EnIn,
396 #[serde(rename = "en-NZ")]
397 EnNz,
398 #[serde(rename = "en-SG")]
399 EnSg,
400 Es,
401 #[serde(rename = "es-419")]
402 Es419,
403 Et,
404 Fi,
405 Fil,
406 Fr,
407 #[serde(rename = "fr-CA")]
408 FrCa,
409 Hr,
410 Hu,
411 Id,
412 It,
413 Ja,
414 Ko,
415 Lt,
416 Lv,
417 Ms,
418 Mt,
419 Nb,
420 Nl,
421 Pl,
422 Pt,
423 #[serde(rename = "pt-BR")]
424 PtBr,
425 Ro,
426 Ru,
427 Sk,
428 Sl,
429 Sv,
430 Th,
431 Tr,
432 Vi,
433 Zh,
434 #[serde(rename = "zh-HK")]
435 ZhHk,
436 #[serde(rename = "zh-TW")]
437 ZhTw,
438}
439
440impl BillingPortalSessionLocale {
441 pub fn as_str(self) -> &'static str {
442 match self {
443 BillingPortalSessionLocale::Auto => "auto",
444 BillingPortalSessionLocale::Bg => "bg",
445 BillingPortalSessionLocale::Cs => "cs",
446 BillingPortalSessionLocale::Da => "da",
447 BillingPortalSessionLocale::De => "de",
448 BillingPortalSessionLocale::El => "el",
449 BillingPortalSessionLocale::En => "en",
450 BillingPortalSessionLocale::EnAu => "en-AU",
451 BillingPortalSessionLocale::EnCa => "en-CA",
452 BillingPortalSessionLocale::EnGb => "en-GB",
453 BillingPortalSessionLocale::EnIe => "en-IE",
454 BillingPortalSessionLocale::EnIn => "en-IN",
455 BillingPortalSessionLocale::EnNz => "en-NZ",
456 BillingPortalSessionLocale::EnSg => "en-SG",
457 BillingPortalSessionLocale::Es => "es",
458 BillingPortalSessionLocale::Es419 => "es-419",
459 BillingPortalSessionLocale::Et => "et",
460 BillingPortalSessionLocale::Fi => "fi",
461 BillingPortalSessionLocale::Fil => "fil",
462 BillingPortalSessionLocale::Fr => "fr",
463 BillingPortalSessionLocale::FrCa => "fr-CA",
464 BillingPortalSessionLocale::Hr => "hr",
465 BillingPortalSessionLocale::Hu => "hu",
466 BillingPortalSessionLocale::Id => "id",
467 BillingPortalSessionLocale::It => "it",
468 BillingPortalSessionLocale::Ja => "ja",
469 BillingPortalSessionLocale::Ko => "ko",
470 BillingPortalSessionLocale::Lt => "lt",
471 BillingPortalSessionLocale::Lv => "lv",
472 BillingPortalSessionLocale::Ms => "ms",
473 BillingPortalSessionLocale::Mt => "mt",
474 BillingPortalSessionLocale::Nb => "nb",
475 BillingPortalSessionLocale::Nl => "nl",
476 BillingPortalSessionLocale::Pl => "pl",
477 BillingPortalSessionLocale::Pt => "pt",
478 BillingPortalSessionLocale::PtBr => "pt-BR",
479 BillingPortalSessionLocale::Ro => "ro",
480 BillingPortalSessionLocale::Ru => "ru",
481 BillingPortalSessionLocale::Sk => "sk",
482 BillingPortalSessionLocale::Sl => "sl",
483 BillingPortalSessionLocale::Sv => "sv",
484 BillingPortalSessionLocale::Th => "th",
485 BillingPortalSessionLocale::Tr => "tr",
486 BillingPortalSessionLocale::Vi => "vi",
487 BillingPortalSessionLocale::Zh => "zh",
488 BillingPortalSessionLocale::ZhHk => "zh-HK",
489 BillingPortalSessionLocale::ZhTw => "zh-TW",
490 }
491 }
492}
493
494impl AsRef<str> for BillingPortalSessionLocale {
495 fn as_ref(&self) -> &str {
496 self.as_str()
497 }
498}
499
500impl std::fmt::Display for BillingPortalSessionLocale {
501 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
502 self.as_str().fmt(f)
503 }
504}
505impl std::default::Default for BillingPortalSessionLocale {
506 fn default() -> Self {
507 Self::Auto
508 }
509}
510
511#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
513#[serde(rename_all = "snake_case")]
514pub enum CreateBillingPortalSessionFlowDataAfterCompletionType {
515 HostedConfirmation,
516 PortalHomepage,
517 Redirect,
518}
519
520impl CreateBillingPortalSessionFlowDataAfterCompletionType {
521 pub fn as_str(self) -> &'static str {
522 match self {
523 CreateBillingPortalSessionFlowDataAfterCompletionType::HostedConfirmation => {
524 "hosted_confirmation"
525 }
526 CreateBillingPortalSessionFlowDataAfterCompletionType::PortalHomepage => {
527 "portal_homepage"
528 }
529 CreateBillingPortalSessionFlowDataAfterCompletionType::Redirect => "redirect",
530 }
531 }
532}
533
534impl AsRef<str> for CreateBillingPortalSessionFlowDataAfterCompletionType {
535 fn as_ref(&self) -> &str {
536 self.as_str()
537 }
538}
539
540impl std::fmt::Display for CreateBillingPortalSessionFlowDataAfterCompletionType {
541 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
542 self.as_str().fmt(f)
543 }
544}
545impl std::default::Default for CreateBillingPortalSessionFlowDataAfterCompletionType {
546 fn default() -> Self {
547 Self::HostedConfirmation
548 }
549}
550
551#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
553#[serde(rename_all = "snake_case")]
554pub enum CreateBillingPortalSessionFlowDataSubscriptionCancelRetentionType {
555 CouponOffer,
556}
557
558impl CreateBillingPortalSessionFlowDataSubscriptionCancelRetentionType {
559 pub fn as_str(self) -> &'static str {
560 match self {
561 CreateBillingPortalSessionFlowDataSubscriptionCancelRetentionType::CouponOffer => {
562 "coupon_offer"
563 }
564 }
565 }
566}
567
568impl AsRef<str> for CreateBillingPortalSessionFlowDataSubscriptionCancelRetentionType {
569 fn as_ref(&self) -> &str {
570 self.as_str()
571 }
572}
573
574impl std::fmt::Display for CreateBillingPortalSessionFlowDataSubscriptionCancelRetentionType {
575 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
576 self.as_str().fmt(f)
577 }
578}
579impl std::default::Default for CreateBillingPortalSessionFlowDataSubscriptionCancelRetentionType {
580 fn default() -> Self {
581 Self::CouponOffer
582 }
583}
584
585#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
587#[serde(rename_all = "snake_case")]
588pub enum CreateBillingPortalSessionFlowDataType {
589 PaymentMethodUpdate,
590 SubscriptionCancel,
591 SubscriptionUpdate,
592 SubscriptionUpdateConfirm,
593}
594
595impl CreateBillingPortalSessionFlowDataType {
596 pub fn as_str(self) -> &'static str {
597 match self {
598 CreateBillingPortalSessionFlowDataType::PaymentMethodUpdate => "payment_method_update",
599 CreateBillingPortalSessionFlowDataType::SubscriptionCancel => "subscription_cancel",
600 CreateBillingPortalSessionFlowDataType::SubscriptionUpdate => "subscription_update",
601 CreateBillingPortalSessionFlowDataType::SubscriptionUpdateConfirm => {
602 "subscription_update_confirm"
603 }
604 }
605 }
606}
607
608impl AsRef<str> for CreateBillingPortalSessionFlowDataType {
609 fn as_ref(&self) -> &str {
610 self.as_str()
611 }
612}
613
614impl std::fmt::Display for CreateBillingPortalSessionFlowDataType {
615 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
616 self.as_str().fmt(f)
617 }
618}
619impl std::default::Default for CreateBillingPortalSessionFlowDataType {
620 fn default() -> Self {
621 Self::PaymentMethodUpdate
622 }
623}
624
625#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
627#[serde(rename_all = "snake_case")]
628pub enum PortalFlowsFlowAfterCompletionType {
629 HostedConfirmation,
630 PortalHomepage,
631 Redirect,
632}
633
634impl PortalFlowsFlowAfterCompletionType {
635 pub fn as_str(self) -> &'static str {
636 match self {
637 PortalFlowsFlowAfterCompletionType::HostedConfirmation => "hosted_confirmation",
638 PortalFlowsFlowAfterCompletionType::PortalHomepage => "portal_homepage",
639 PortalFlowsFlowAfterCompletionType::Redirect => "redirect",
640 }
641 }
642}
643
644impl AsRef<str> for PortalFlowsFlowAfterCompletionType {
645 fn as_ref(&self) -> &str {
646 self.as_str()
647 }
648}
649
650impl std::fmt::Display for PortalFlowsFlowAfterCompletionType {
651 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
652 self.as_str().fmt(f)
653 }
654}
655impl std::default::Default for PortalFlowsFlowAfterCompletionType {
656 fn default() -> Self {
657 Self::HostedConfirmation
658 }
659}
660
661#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
663#[serde(rename_all = "snake_case")]
664pub enum PortalFlowsFlowType {
665 PaymentMethodUpdate,
666 SubscriptionCancel,
667 SubscriptionUpdate,
668 SubscriptionUpdateConfirm,
669}
670
671impl PortalFlowsFlowType {
672 pub fn as_str(self) -> &'static str {
673 match self {
674 PortalFlowsFlowType::PaymentMethodUpdate => "payment_method_update",
675 PortalFlowsFlowType::SubscriptionCancel => "subscription_cancel",
676 PortalFlowsFlowType::SubscriptionUpdate => "subscription_update",
677 PortalFlowsFlowType::SubscriptionUpdateConfirm => "subscription_update_confirm",
678 }
679 }
680}
681
682impl AsRef<str> for PortalFlowsFlowType {
683 fn as_ref(&self) -> &str {
684 self.as_str()
685 }
686}
687
688impl std::fmt::Display for PortalFlowsFlowType {
689 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
690 self.as_str().fmt(f)
691 }
692}
693impl std::default::Default for PortalFlowsFlowType {
694 fn default() -> Self {
695 Self::PaymentMethodUpdate
696 }
697}
698
699#[derive(Copy, Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
701#[serde(rename_all = "snake_case")]
702pub enum PortalFlowsRetentionType {
703 CouponOffer,
704}
705
706impl PortalFlowsRetentionType {
707 pub fn as_str(self) -> &'static str {
708 match self {
709 PortalFlowsRetentionType::CouponOffer => "coupon_offer",
710 }
711 }
712}
713
714impl AsRef<str> for PortalFlowsRetentionType {
715 fn as_ref(&self) -> &str {
716 self.as_str()
717 }
718}
719
720impl std::fmt::Display for PortalFlowsRetentionType {
721 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
722 self.as_str().fmt(f)
723 }
724}
725impl std::default::Default for PortalFlowsRetentionType {
726 fn default() -> Self {
727 Self::CouponOffer
728 }
729}