1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
//! The shop's customer portal, as the buyer reaches it with a portal grant:
//! the session, contact details, purchases, refund requests, subscriptions,
//! plans and invoices.
//!
//! Enumerated values arrive as strings, so a value added later does not break
//! decoding. `Debug` on the types that carry the buyer's contact details, or a
//! payment's client secret, prints none of them.
use std::fmt;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::core::models::common::AddressDetails;
use crate::core::models::product::ProductPriceTaxBehavior;
/// What a portal grant lets the buyer do.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalPermissions {
/// Whether the buyer may change subscriptions.
#[serde(default)]
pub subscription_changes: Option<bool>,
/// Which subscription actions the buyer may take.
#[serde(default)]
pub subscription_actions: Option<BuyerPortalSubscriptionPermissions>,
/// Whether the buyer may change their contact and billing details.
#[serde(default)]
pub profile_changes: Option<bool>,
/// How the buyer may change their email address: `read_only`,
/// `notify_previous`, `confirm_new` or `confirm_new_and_notify_previous`.
#[serde(default)]
pub email_policy: Option<String>,
/// Whether the buyer may ask for refunds.
#[serde(default)]
pub refund_requests: Option<bool>,
/// Whether the buyer may ask for refunds of subscription renewals.
#[serde(default)]
pub refund_requests_for_renewals: Option<bool>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// Which subscription actions a portal grant allows, each independently.
///
/// Read on a portal session and on an issued link, and sent to narrow a new
/// link.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalSubscriptionPermissions {
/// Pause a subscription.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub pause: Option<bool>,
/// Resume a paused subscription.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub resume: Option<bool>,
/// Cancel at the end of the current period.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cancel_at_period_end: Option<bool>,
/// Cancel immediately.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cancel_immediately: Option<bool>,
/// Change the plan.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub change_plan: Option<bool>,
/// Any additional fields: sent verbatim, and the response fields not
/// modeled above.
#[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub extra: serde_json::Map<String, Value>,
}
impl BuyerPortalSubscriptionPermissions {
/// No action set; set the ones you want to allow or forbid.
pub fn new() -> Self {
Self::default()
}
/// Allow or forbid pausing.
#[must_use]
pub fn pause(mut self, allowed: bool) -> Self {
self.pause = Some(allowed);
self
}
/// Allow or forbid resuming.
#[must_use]
pub fn resume(mut self, allowed: bool) -> Self {
self.resume = Some(allowed);
self
}
/// Allow or forbid cancelling at the end of the period.
#[must_use]
pub fn cancel_at_period_end(mut self, allowed: bool) -> Self {
self.cancel_at_period_end = Some(allowed);
self
}
/// Allow or forbid cancelling immediately.
#[must_use]
pub fn cancel_immediately(mut self, allowed: bool) -> Self {
self.cancel_immediately = Some(allowed);
self
}
/// Allow or forbid changing the plan.
#[must_use]
pub fn change_plan(mut self, allowed: bool) -> Self {
self.change_plan = Some(allowed);
self
}
}
/// The portal session: the shop's look and what the grant allows.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalSession {
/// The shop's name.
#[serde(default)]
pub shop_name: Option<String>,
/// The shop.
#[serde(default)]
pub profile_id: Option<String>,
/// The shop's logo URL.
#[serde(default)]
pub logo: Option<String>,
/// The shop's accent color.
#[serde(default)]
pub accent_color: Option<String>,
/// The buyer's language.
#[serde(default)]
pub locale: Option<String>,
/// The buyer's name.
#[serde(default)]
pub customer_name: Option<String>,
/// When the grant expires, in Unix seconds.
pub expires_at: i64,
/// Whether subscription self-service is offered.
#[serde(default)]
pub subscription_self_service: bool,
/// What the grant allows.
pub permissions: BuyerPortalPermissions,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
impl fmt::Debug for BuyerPortalSession {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("BuyerPortalSession")
.field("shop_name", &self.shop_name)
.field("profile_id", &self.profile_id)
.field("locale", &self.locale)
.field(
"customer_name",
&self.customer_name.as_ref().map(|_| "<redacted>"),
)
.field("expires_at", &self.expires_at)
.field("subscription_self_service", &self.subscription_self_service)
.field("permissions", &self.permissions)
.finish_non_exhaustive()
}
}
/// The buyer's contact and billing details, and what they may change.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalProfile {
/// Name.
#[serde(default)]
pub name: Option<String>,
/// Email address.
#[serde(default)]
pub email: Option<String>,
/// Phone number.
#[serde(default)]
pub phone: Option<String>,
/// Dialing code, e.g. `"+49"`.
#[serde(default)]
pub phone_country_code: Option<String>,
/// VAT or tax registration ID.
#[serde(default)]
pub tax_registration_id: Option<String>,
/// Billing address.
#[serde(default)]
pub address: Option<AddressDetails>,
/// Whether the buyer may change these details.
#[serde(default)]
pub profile_changes: bool,
/// How the buyer may change their email address: `read_only`,
/// `notify_previous`, `confirm_new` or `confirm_new_and_notify_previous`.
pub email_policy: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
impl fmt::Debug for BuyerPortalProfile {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let redacted = |set: bool| if set { Some("<redacted>") } else { None };
f.debug_struct("BuyerPortalProfile")
.field("name", &redacted(self.name.is_some()))
.field("email", &redacted(self.email.is_some()))
.field("phone", &redacted(self.phone.is_some()))
.field("phone_country_code", &self.phone_country_code)
.field(
"tax_registration_id",
&redacted(self.tax_registration_id.is_some()),
)
.field("address", &redacted(self.address.is_some()))
.field("profile_changes", &self.profile_changes)
.field("email_policy", &self.email_policy)
.finish_non_exhaustive()
}
}
/// Where the messages of an email change stand.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalContactEmailDelivery {
/// The message to the new address: `not_required`, `pending`, `sent`,
/// `unavailable` or `uncertain`.
pub confirmation: String,
/// The notice to the previous address, with the same values.
pub previous_notice: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// What became of an email change.
///
/// `status` is `pending_confirmation` (the proof was sent to the new
/// address), `applied`, `refused` (`reason` says why) or `uncertain`.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalContactEmailOutcome {
/// `pending_confirmation`, `applied`, `refused` or `uncertain`.
pub status: String,
/// The operation, as sent. Absent on a refusal.
#[serde(default)]
pub operation_id: Option<String>,
/// Where the messages stand, when pending or applied.
#[serde(default)]
pub delivery: Option<BuyerPortalContactEmailDelivery>,
/// Why a change was refused: `unavailable`, `access_changed`, `changed`,
/// `expired`, `invalid_proof`, `conflicting_operation` or
/// `unsupported_storage`.
#[serde(default)]
pub reason: Option<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One line of a purchase.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalPurchaseLine {
/// What was bought.
pub description: String,
/// How many.
pub quantity: i32,
/// Price of one, in minor units.
pub unit_amount: i64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A refund request the buyer sent.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalRefundRequest {
/// Request id.
pub id: String,
/// `requested`, `approved` or `declined`.
pub status: String,
/// `not_received`, `not_as_described`, `duplicate`, `cancelled_order` or
/// `other`.
pub reason: String,
/// What went wrong, in the buyer's words.
pub message: String,
/// The amount asked for, in minor units.
pub amount: i64,
/// ISO 4217 currency of the amounts.
pub currency: String,
/// The amount the shop approved, in minor units.
#[serde(default)]
pub approved_amount: Option<i64>,
/// The shop's reply.
#[serde(default)]
pub merchant_reply: Option<String>,
/// When it was sent.
pub created_at: String,
/// When the shop decided.
#[serde(default)]
pub decided_at: Option<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One of the buyer's purchases at the shop.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalPurchase {
/// Purchase id, as a refund request names it.
pub id: String,
/// The kind of purchase.
pub kind: String,
/// Its status.
pub status: String,
/// Amount, in minor units.
pub amount: i64,
/// ISO 4217 currency of the amounts.
pub currency: String,
/// When it was made.
pub created_at: String,
/// The shop's name.
pub shop_name: String,
/// The shop.
#[serde(default)]
pub profile_id: Option<String>,
/// Description.
#[serde(default)]
pub description: Option<String>,
/// Whether it belongs to test mode.
pub test_mode: bool,
/// Refunded so far, in minor units.
#[serde(default)]
pub refunded_amount: Option<i64>,
/// Disputed, in minor units.
#[serde(default)]
pub disputed_amount: Option<i64>,
/// Whether and how a receipt is available.
pub receipt_availability: String,
/// The lines.
#[serde(default)]
pub lines: Vec<BuyerPortalPurchaseLine>,
/// What can still be refunded, in minor units.
#[serde(default)]
pub refundable_amount: Option<i64>,
/// Whether the buyer may ask for a refund of it now.
#[serde(default)]
pub refund_request_allowed: bool,
/// The refund request already sent for it.
#[serde(default)]
pub refund_request: Option<BuyerPortalRefundRequest>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One page of the buyer's purchases.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalPurchasePage {
/// The purchases.
#[serde(default)]
pub data: Vec<BuyerPortalPurchase>,
/// How many there are, over all pages.
pub total_count: i64,
/// The page size used.
pub limit: i64,
/// The offset used.
pub offset: i64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// What the buyer may do with a subscription now.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalSubscriptionCapabilities {
/// Pause at once.
pub pause_immediately: bool,
/// Resume at once.
pub resume_immediately: bool,
/// Cancel at once.
pub cancel_immediately: bool,
/// Cancel at the end of the period.
pub cancel_at_period_end: bool,
/// Change the plan.
pub change_plan: bool,
/// Whether pausing voids the open invoices.
pub pause_voids_invoices: bool,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A failed renewal the buyer can still pay.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalRenewalRecovery {
/// The renewal payment.
pub payment_id: String,
/// Amount due, in minor units.
pub amount: i64,
/// ISO 4217 currency of `amount`.
pub currency: String,
/// Where the buyer pays it.
pub payment_link: String,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One of the buyer's subscriptions at the shop.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalSubscription {
/// Subscription id.
pub id: String,
/// Its status.
pub status: String,
/// The shop's name.
pub shop_name: String,
/// Whether it belongs to test mode.
pub test_mode: bool,
/// The product.
#[serde(default)]
pub product_id: Option<String>,
/// The price.
#[serde(default)]
pub price_id: Option<String>,
/// Where the amount comes from.
pub amount_source: String,
/// Billing interval, e.g. `month`.
#[serde(default)]
pub billing_interval: Option<String>,
/// Intervals per billing cycle.
#[serde(default)]
pub billing_interval_count: Option<i32>,
/// Amount per cycle, in minor units.
#[serde(default)]
pub amount: Option<i64>,
/// ISO 4217 currency of `amount`.
#[serde(default)]
pub currency: Option<String>,
/// `Exclusive` when `amount` is the plan's catalog price and the billing
/// processor adds tax on top of it: show it as "plus tax". `None` from an
/// older API.
#[serde(default)]
pub tax_behavior: Option<ProductPriceTaxBehavior>,
/// When the current period ends.
#[serde(default)]
pub current_period_end: Option<String>,
/// Whether it ends with the current period.
#[serde(default)]
pub cancel_at_period_end: Option<bool>,
/// What the buyer may do with it now.
pub capabilities: BuyerPortalSubscriptionCapabilities,
/// A failed renewal the buyer can still pay.
#[serde(default)]
pub renewal_recovery: Option<BuyerPortalRenewalRecovery>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One page of the buyer's subscriptions.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalSubscriptionPage {
/// The subscriptions.
#[serde(default)]
pub data: Vec<BuyerPortalSubscription>,
/// How many there are, over all pages.
pub total_count: i64,
/// The page size used.
pub limit: i64,
/// The offset used.
pub offset: i64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A plan the buyer can subscribe to or change to.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalPlan {
/// The product.
pub product_id: String,
/// The price.
pub price_id: String,
/// The plan's name.
pub name: String,
/// Amount per cycle, in minor units.
pub amount: i64,
/// ISO 4217 currency of `amount`.
pub currency: String,
/// Billing interval, e.g. `month`.
pub billing_interval: String,
/// Intervals per billing cycle.
pub billing_interval_count: i32,
/// Whether the plan belongs to test mode.
#[serde(default)]
pub test_mode: Option<bool>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One page of plans.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalPlanPage {
/// The plans.
#[serde(default)]
pub data: Vec<BuyerPortalPlan>,
/// Whether more plans follow.
#[serde(default)]
pub has_more: bool,
/// The offset of the next page.
pub next_offset: i64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// The seller or the buyer on an invoice.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct InvoiceParty {
/// Country.
#[serde(default)]
pub country: Option<String>,
/// Region.
#[serde(default)]
pub region: Option<String>,
/// Name.
#[serde(default)]
pub name: Option<String>,
/// Postal address, as printed.
#[serde(default)]
pub address: Option<String>,
/// Email address.
#[serde(default)]
pub email: Option<String>,
/// Phone number.
#[serde(default)]
pub phone: Option<String>,
/// Website.
#[serde(default)]
pub website: Option<String>,
/// Tax id.
#[serde(default)]
pub tax_id: Option<String>,
/// VAT id.
#[serde(default)]
pub vat_id: Option<String>,
/// Company registration.
#[serde(default)]
pub registration: Option<String>,
/// Bank details, as printed.
#[serde(default)]
pub bank_details: Option<String>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
impl fmt::Debug for InvoiceParty {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// A party is often a person: print where they are, never who.
f.debug_struct("InvoiceParty")
.field("country", &self.country)
.field("region", &self.region)
.finish_non_exhaustive()
}
}
/// One line of an invoice.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalInvoiceLine {
/// What was billed.
pub description: String,
/// How many.
pub quantity: i64,
/// Net price of one, in minor units.
pub unit_net_amount: i64,
/// Net amount of the line, in minor units.
pub line_net_amount: i64,
/// Gross amount of the line, in minor units.
pub gross_amount: i64,
/// Tax rate in basis points.
#[serde(default)]
pub tax_rate_bp: Option<i32>,
/// Tax, in minor units.
#[serde(default)]
pub tax_amount: Option<i64>,
/// Why no tax applies.
#[serde(default)]
pub tax_exemption_note: Option<String>,
/// Whether the line is included in the totals.
pub included: bool,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// An issued invoice or credit note of the buyer's.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalInvoice {
/// Invoice id.
pub id: String,
/// The printed number.
#[serde(default)]
pub document_number: Option<String>,
/// `invoice` or `credit_note`.
pub kind: String,
/// `draft`, `issued` or `voided`.
pub status: String,
/// Whether it belongs to test mode.
pub test_mode: bool,
/// The seller.
pub seller: InvoiceParty,
/// The buyer.
pub buyer: InvoiceParty,
/// ISO 4217 currency of the amounts.
pub currency: String,
/// Gross total, in minor units.
pub gross_amount: i64,
/// Net total, in minor units.
pub net_amount: i64,
/// Tax total, in minor units.
#[serde(default)]
pub tax_amount: Option<i64>,
/// Paid so far, in minor units.
#[serde(default)]
pub paid_amount: Option<i64>,
/// Date of supply.
pub supply_date: String,
/// Start of the billed period.
#[serde(default)]
pub period_start: Option<String>,
/// End of the billed period.
#[serde(default)]
pub period_end: Option<String>,
/// When payment is due.
#[serde(default)]
pub due_date: Option<String>,
/// Notes printed on it.
#[serde(default)]
pub notes: Option<String>,
/// The lines.
#[serde(default)]
pub lines: Vec<BuyerPortalInvoiceLine>,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// One page of the buyer's invoices.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalInvoicePage {
/// The invoices.
#[serde(default)]
pub data: Vec<BuyerPortalInvoice>,
/// How many there are, over all pages.
pub total_count: i64,
/// The page size used.
pub limit: i64,
/// The offset used.
pub offset: i64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// Where a subscription enrollment from the portal stands: its first payment.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct NativeEnrollmentResponse {
/// The subscription.
pub subscription_id: String,
/// Its first payment.
pub payment_id: String,
/// That payment's status, e.g. `requires_customer_action`.
pub payment_status: String,
/// Amount, in minor units.
pub amount: i64,
/// ISO 4217 currency of `amount`.
pub currency: String,
/// What the buyer must do next to complete the payment.
#[serde(default)]
pub next_action: Option<Value>,
/// The payment's client secret, for completing it in the browser.
#[serde(default)]
pub client_secret: Option<String>,
/// Whether the subscription is active.
pub active: bool,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
impl fmt::Debug for NativeEnrollmentResponse {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("NativeEnrollmentResponse")
.field("subscription_id", &self.subscription_id)
.field("payment_id", &self.payment_id)
.field("payment_status", &self.payment_status)
.field("amount", &self.amount)
.field("currency", &self.currency)
.field(
"next_action",
&self.next_action.as_ref().map(|_| "<present>"),
)
.field(
"client_secret",
&self.client_secret.as_ref().map(|_| "<redacted>"),
)
.field("active", &self.active)
.finish_non_exhaustive()
}
}
/// Whether an unpaid enrollment was abandoned.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct NativeEnrollmentAbandonResponse {
/// `true` when it was.
pub abandoned: bool,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// A customer portal link, returned once when it is issued.
///
/// [`url`](Self::url) is a credential: share it only with the intended
/// buyer. `Debug` redacts it.
#[derive(Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerInvoiceLink {
/// The link's ID, for revoking it.
pub id: String,
/// The link. The credential is in the fragment, which is not sent to the
/// web server.
pub url: String,
/// When the link expires, in seconds since the Unix epoch.
pub expires_at: i64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
impl std::fmt::Debug for BuyerInvoiceLink {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("BuyerInvoiceLink")
.field("id", &self.id)
.field("url", &"[redacted]")
.field("expires_at", &self.expires_at)
.field("extra", &self.extra.keys().collect::<Vec<_>>())
.finish()
}
}
/// One page of a customer's active portal links.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalLinkPage {
/// The links on this page.
#[serde(default)]
pub data: Vec<BuyerPortalLinkSummary>,
/// Every active link in scope, across pages.
pub total_count: i64,
/// The page size applied.
pub limit: i64,
/// The offset applied.
pub offset: i64,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// An issued portal link, without its URL.
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalLinkSummary {
/// The link's ID, for revoking it.
pub id: String,
/// The shop the link is for.
#[serde(default)]
pub profile_id: Option<String>,
/// When the link expires, in seconds since the Unix epoch.
pub expires_at: i64,
/// Whether the link includes subscription self-service.
pub allow_subscription_changes: bool,
/// The restrictions issued with the link, not a snapshot of current
/// settings.
pub restrictions: BuyerPortalLinkRestrictions,
/// Any additional response fields not modeled above.
#[serde(flatten)]
pub extra: serde_json::Map<String, Value>,
}
/// Restrictions on a portal link. A field left `None` imposes no ceiling; no
/// field can grant what the shop's current portal settings forbid.
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[non_exhaustive]
pub struct BuyerPortalLinkRestrictions {
/// Allow subscription changes.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub subscription_changes: Option<bool>,
/// Which subscription actions are allowed.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub subscription_actions: Option<BuyerPortalSubscriptionPermissions>,
/// Allow the buyer to change their profile.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub profile_changes: Option<bool>,
/// `"read_only"`, `"notify_previous"` or `"confirm_new"`. A link may only
/// narrow the merchant's contact-email requirements, never widen them.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub email_policy: Option<String>,
/// Allow refund requests.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub refund_requests: Option<bool>,
/// Allow refund requests for subscription renewals.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub refund_requests_for_renewals: Option<bool>,
/// Any additional fields: sent verbatim, and the response fields not
/// modeled above.
#[serde(flatten, skip_serializing_if = "serde_json::Map::is_empty")]
pub extra: serde_json::Map<String, Value>,
}
impl BuyerPortalLinkRestrictions {
/// No restrictions; set the ceilings you want.
pub fn new() -> Self {
Self::default()
}
/// Allow or forbid subscription changes.
#[must_use]
pub fn subscription_changes(mut self, allowed: bool) -> Self {
self.subscription_changes = Some(allowed);
self
}
/// Which subscription actions are allowed.
#[must_use]
pub fn subscription_actions(mut self, actions: BuyerPortalSubscriptionPermissions) -> Self {
self.subscription_actions = Some(actions);
self
}
/// Allow or forbid profile changes.
#[must_use]
pub fn profile_changes(mut self, allowed: bool) -> Self {
self.profile_changes = Some(allowed);
self
}
/// Narrow the contact-email policy.
#[must_use]
pub fn email_policy(mut self, policy: impl Into<String>) -> Self {
self.email_policy = Some(policy.into());
self
}
/// Allow or forbid refund requests.
#[must_use]
pub fn refund_requests(mut self, allowed: bool) -> Self {
self.refund_requests = Some(allowed);
self
}
/// Allow or forbid refund requests for renewals.
#[must_use]
pub fn refund_requests_for_renewals(mut self, allowed: bool) -> Self {
self.refund_requests_for_renewals = Some(allowed);
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn link_debug_redacts_the_url() {
let link: BuyerInvoiceLink = serde_json::from_str(
r##"{"id":"bpl_1","url":"https://portal.test/#secret_token","expires_at":1}"##,
)
.unwrap();
let printed = format!("{link:?}");
assert!(!printed.contains("secret_token"), "{printed}");
assert!(printed.contains("bpl_1"));
}
}