forked from orbcorp/orb-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvoice.go
More file actions
1298 lines (1201 loc) · 74.9 KB
/
invoice.go
File metadata and controls
1298 lines (1201 loc) · 74.9 KB
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
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package orb
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"reflect"
"time"
"github.com/orbcorp/orb-go/internal/apijson"
"github.com/orbcorp/orb-go/internal/apiquery"
"github.com/orbcorp/orb-go/internal/param"
"github.com/orbcorp/orb-go/internal/requestconfig"
"github.com/orbcorp/orb-go/option"
"github.com/orbcorp/orb-go/packages/pagination"
"github.com/orbcorp/orb-go/shared"
"github.com/tidwall/gjson"
)
// InvoiceService contains methods and other services that help with interacting
// with the orb API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewInvoiceService] method instead.
type InvoiceService struct {
Options []option.RequestOption
}
// NewInvoiceService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewInvoiceService(opts ...option.RequestOption) (r *InvoiceService) {
r = &InvoiceService{}
r.Options = opts
return
}
// This endpoint is used to create a one-off invoice for a customer.
func (r *InvoiceService) New(ctx context.Context, body InvoiceNewParams, opts ...option.RequestOption) (res *shared.Invoice, err error) {
opts = append(r.Options[:], opts...)
path := "invoices"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// This endpoint allows you to update the `metadata`, `net_terms`, and `due_date`
// properties on an invoice. If you pass null for the metadata value, it will clear
// any existing metadata for that invoice.
//
// `metadata` can be modified regardless of invoice state. `net_terms` and
// `due_date` can only be modified if the invoice is in a `draft` state.
func (r *InvoiceService) Update(ctx context.Context, invoiceID string, body InvoiceUpdateParams, opts ...option.RequestOption) (res *shared.Invoice, err error) {
opts = append(r.Options[:], opts...)
if invoiceID == "" {
err = errors.New("missing required invoice_id parameter")
return
}
path := fmt.Sprintf("invoices/%s", invoiceID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, body, &res, opts...)
return
}
// This endpoint returns a list of all [`Invoice`](/core-concepts#invoice)s for an
// account in a list format.
//
// The list of invoices is ordered starting from the most recently issued invoice
// date. The response also includes
// [`pagination_metadata`](/api-reference/pagination), which lets the caller
// retrieve the next page of results if they exist.
//
// By default, this only returns invoices that are `issued`, `paid`, or `synced`.
//
// When fetching any `draft` invoices, this returns the last-computed invoice
// values for each draft invoice, which may not always be up-to-date since Orb
// regularly refreshes invoices asynchronously.
func (r *InvoiceService) List(ctx context.Context, query InvoiceListParams, opts ...option.RequestOption) (res *pagination.Page[shared.Invoice], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "invoices"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// This endpoint returns a list of all [`Invoice`](/core-concepts#invoice)s for an
// account in a list format.
//
// The list of invoices is ordered starting from the most recently issued invoice
// date. The response also includes
// [`pagination_metadata`](/api-reference/pagination), which lets the caller
// retrieve the next page of results if they exist.
//
// By default, this only returns invoices that are `issued`, `paid`, or `synced`.
//
// When fetching any `draft` invoices, this returns the last-computed invoice
// values for each draft invoice, which may not always be up-to-date since Orb
// regularly refreshes invoices asynchronously.
func (r *InvoiceService) ListAutoPaging(ctx context.Context, query InvoiceListParams, opts ...option.RequestOption) *pagination.PageAutoPager[shared.Invoice] {
return pagination.NewPageAutoPager(r.List(ctx, query, opts...))
}
// This endpoint is used to fetch an [`Invoice`](/core-concepts#invoice) given an
// identifier.
func (r *InvoiceService) Fetch(ctx context.Context, invoiceID string, opts ...option.RequestOption) (res *shared.Invoice, err error) {
opts = append(r.Options[:], opts...)
if invoiceID == "" {
err = errors.New("missing required invoice_id parameter")
return
}
path := fmt.Sprintf("invoices/%s", invoiceID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// This endpoint can be used to fetch the upcoming
// [invoice](/core-concepts#invoice) for the current billing period given a
// subscription.
func (r *InvoiceService) FetchUpcoming(ctx context.Context, query InvoiceFetchUpcomingParams, opts ...option.RequestOption) (res *InvoiceFetchUpcomingResponse, err error) {
opts = append(r.Options[:], opts...)
path := "invoices/upcoming"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, query, &res, opts...)
return
}
// This endpoint allows an eligible invoice to be issued manually. This is only
// possible with invoices where status is `draft`, `will_auto_issue` is false, and
// an `eligible_to_issue_at` is a time in the past. Issuing an invoice could
// possibly trigger side effects, some of which could be customer-visible (e.g.
// sending emails, auto-collecting payment, syncing the invoice to external
// providers, etc).
func (r *InvoiceService) Issue(ctx context.Context, invoiceID string, body InvoiceIssueParams, opts ...option.RequestOption) (res *shared.Invoice, err error) {
opts = append(r.Options[:], opts...)
if invoiceID == "" {
err = errors.New("missing required invoice_id parameter")
return
}
path := fmt.Sprintf("invoices/%s/issue", invoiceID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// This endpoint allows an invoice's status to be set to the `paid` status. This
// can only be done to invoices that are in the `issued` or `synced` status.
func (r *InvoiceService) MarkPaid(ctx context.Context, invoiceID string, body InvoiceMarkPaidParams, opts ...option.RequestOption) (res *shared.Invoice, err error) {
opts = append(r.Options[:], opts...)
if invoiceID == "" {
err = errors.New("missing required invoice_id parameter")
return
}
path := fmt.Sprintf("invoices/%s/mark_paid", invoiceID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// This endpoint collects payment for an invoice using the customer's default
// payment method. This action can only be taken on invoices with status "issued".
func (r *InvoiceService) Pay(ctx context.Context, invoiceID string, opts ...option.RequestOption) (res *shared.Invoice, err error) {
opts = append(r.Options[:], opts...)
if invoiceID == "" {
err = errors.New("missing required invoice_id parameter")
return
}
path := fmt.Sprintf("invoices/%s/pay", invoiceID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return
}
// This endpoint allows an invoice's status to be set to the `void` status. This
// can only be done to invoices that are in the `issued` status.
//
// If the associated invoice has used the customer balance to change the amount
// due, the customer balance operation will be reverted. For example, if the
// invoice used \$10 of customer balance, that amount will be added back to the
// customer balance upon voiding.
//
// If the invoice was used to purchase a credit block, but the invoice is not yet
// paid, the credit block will be voided. If the invoice was created due to a
// top-up, the top-up will be disabled.
func (r *InvoiceService) Void(ctx context.Context, invoiceID string, opts ...option.RequestOption) (res *shared.Invoice, err error) {
opts = append(r.Options[:], opts...)
if invoiceID == "" {
err = errors.New("missing required invoice_id parameter")
return
}
path := fmt.Sprintf("invoices/%s/void", invoiceID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return
}
type InvoiceFetchUpcomingResponse struct {
ID string `json:"id,required"`
// This is the final amount required to be charged to the customer and reflects the
// application of the customer balance to the `total` of the invoice.
AmountDue string `json:"amount_due,required"`
AutoCollection InvoiceFetchUpcomingResponseAutoCollection `json:"auto_collection,required"`
BillingAddress shared.Address `json:"billing_address,required,nullable"`
// The creation time of the resource in Orb.
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// A list of credit notes associated with the invoice
CreditNotes []InvoiceFetchUpcomingResponseCreditNote `json:"credit_notes,required"`
// An ISO 4217 currency string or `credits`
Currency string `json:"currency,required"`
Customer shared.CustomerMinified `json:"customer,required"`
CustomerBalanceTransactions []InvoiceFetchUpcomingResponseCustomerBalanceTransaction `json:"customer_balance_transactions,required"`
// Tax IDs are commonly required to be displayed on customer invoices, which are
// added to the headers of invoices.
//
// ### Supported Tax ID Countries and Types
//
// | Country | Type | Description |
// | ---------------------- | ------------ | ------------------------------------------------------------------------------------------------------- |
// | Albania | `al_tin` | Albania Tax Identification Number |
// | Andorra | `ad_nrt` | Andorran NRT Number |
// | Angola | `ao_tin` | Angola Tax Identification Number |
// | Argentina | `ar_cuit` | Argentinian Tax ID Number |
// | Armenia | `am_tin` | Armenia Tax Identification Number |
// | Aruba | `aw_tin` | Aruba Tax Identification Number |
// | Australia | `au_abn` | Australian Business Number (AU ABN) |
// | Australia | `au_arn` | Australian Taxation Office Reference Number |
// | Austria | `eu_vat` | European VAT Number |
// | Azerbaijan | `az_tin` | Azerbaijan Tax Identification Number |
// | Bahamas | `bs_tin` | Bahamas Tax Identification Number |
// | Bahrain | `bh_vat` | Bahraini VAT Number |
// | Bangladesh | `bd_bin` | Bangladesh Business Identification Number |
// | Barbados | `bb_tin` | Barbados Tax Identification Number |
// | Belarus | `by_tin` | Belarus TIN Number |
// | Belgium | `eu_vat` | European VAT Number |
// | Benin | `bj_ifu` | Benin Tax Identification Number (Identifiant Fiscal Unique) |
// | Bolivia | `bo_tin` | Bolivian Tax ID |
// | Bosnia and Herzegovina | `ba_tin` | Bosnia and Herzegovina Tax Identification Number |
// | Brazil | `br_cnpj` | Brazilian CNPJ Number |
// | Brazil | `br_cpf` | Brazilian CPF Number |
// | Bulgaria | `bg_uic` | Bulgaria Unified Identification Code |
// | Bulgaria | `eu_vat` | European VAT Number |
// | Burkina Faso | `bf_ifu` | Burkina Faso Tax Identification Number (Numéro d'Identifiant Fiscal Unique) |
// | Cambodia | `kh_tin` | Cambodia Tax Identification Number |
// | Cameroon | `cm_niu` | Cameroon Tax Identification Number (Numéro d'Identifiant fiscal Unique) |
// | Canada | `ca_bn` | Canadian BN |
// | Canada | `ca_gst_hst` | Canadian GST/HST Number |
// | Canada | `ca_pst_bc` | Canadian PST Number (British Columbia) |
// | Canada | `ca_pst_mb` | Canadian PST Number (Manitoba) |
// | Canada | `ca_pst_sk` | Canadian PST Number (Saskatchewan) |
// | Canada | `ca_qst` | Canadian QST Number (Québec) |
// | Cape Verde | `cv_nif` | Cape Verde Tax Identification Number (Número de Identificação Fiscal) |
// | Chile | `cl_tin` | Chilean TIN |
// | China | `cn_tin` | Chinese Tax ID |
// | Colombia | `co_nit` | Colombian NIT Number |
// | Congo-Kinshasa | `cd_nif` | Congo (DR) Tax Identification Number (Número de Identificação Fiscal) |
// | Costa Rica | `cr_tin` | Costa Rican Tax ID |
// | Croatia | `eu_vat` | European VAT Number |
// | Croatia | `hr_oib` | Croatian Personal Identification Number (OIB) |
// | Cyprus | `eu_vat` | European VAT Number |
// | Czech Republic | `eu_vat` | European VAT Number |
// | Denmark | `eu_vat` | European VAT Number |
// | Dominican Republic | `do_rcn` | Dominican RCN Number |
// | Ecuador | `ec_ruc` | Ecuadorian RUC Number |
// | Egypt | `eg_tin` | Egyptian Tax Identification Number |
// | El Salvador | `sv_nit` | El Salvadorian NIT Number |
// | Estonia | `eu_vat` | European VAT Number |
// | Ethiopia | `et_tin` | Ethiopia Tax Identification Number |
// | European Union | `eu_oss_vat` | European One Stop Shop VAT Number for non-Union scheme |
// | Finland | `eu_vat` | European VAT Number |
// | France | `eu_vat` | European VAT Number |
// | Georgia | `ge_vat` | Georgian VAT |
// | Germany | `de_stn` | German Tax Number (Steuernummer) |
// | Germany | `eu_vat` | European VAT Number |
// | Greece | `eu_vat` | European VAT Number |
// | Guinea | `gn_nif` | Guinea Tax Identification Number (Número de Identificação Fiscal) |
// | Hong Kong | `hk_br` | Hong Kong BR Number |
// | Hungary | `eu_vat` | European VAT Number |
// | Hungary | `hu_tin` | Hungary Tax Number (adószám) |
// | Iceland | `is_vat` | Icelandic VAT |
// | India | `in_gst` | Indian GST Number |
// | Indonesia | `id_npwp` | Indonesian NPWP Number |
// | Ireland | `eu_vat` | European VAT Number |
// | Israel | `il_vat` | Israel VAT |
// | Italy | `eu_vat` | European VAT Number |
// | Japan | `jp_cn` | Japanese Corporate Number (_Hōjin Bangō_) |
// | Japan | `jp_rn` | Japanese Registered Foreign Businesses' Registration Number (_Tōroku Kokugai Jigyōsha no Tōroku Bangō_) |
// | Japan | `jp_trn` | Japanese Tax Registration Number (_Tōroku Bangō_) |
// | Kazakhstan | `kz_bin` | Kazakhstani Business Identification Number |
// | Kenya | `ke_pin` | Kenya Revenue Authority Personal Identification Number |
// | Kyrgyzstan | `kg_tin` | Kyrgyzstan Tax Identification Number |
// | Laos | `la_tin` | Laos Tax Identification Number |
// | Latvia | `eu_vat` | European VAT Number |
// | Liechtenstein | `li_uid` | Liechtensteinian UID Number |
// | Liechtenstein | `li_vat` | Liechtenstein VAT Number |
// | Lithuania | `eu_vat` | European VAT Number |
// | Luxembourg | `eu_vat` | European VAT Number |
// | Malaysia | `my_frp` | Malaysian FRP Number |
// | Malaysia | `my_itn` | Malaysian ITN |
// | Malaysia | `my_sst` | Malaysian SST Number |
// | Malta | `eu_vat` | European VAT Number |
// | Mauritania | `mr_nif` | Mauritania Tax Identification Number (Número de Identificação Fiscal) |
// | Mexico | `mx_rfc` | Mexican RFC Number |
// | Moldova | `md_vat` | Moldova VAT Number |
// | Montenegro | `me_pib` | Montenegro PIB Number |
// | Morocco | `ma_vat` | Morocco VAT Number |
// | Nepal | `np_pan` | Nepal PAN Number |
// | Netherlands | `eu_vat` | European VAT Number |
// | New Zealand | `nz_gst` | New Zealand GST Number |
// | Nigeria | `ng_tin` | Nigerian Tax Identification Number |
// | North Macedonia | `mk_vat` | North Macedonia VAT Number |
// | Northern Ireland | `eu_vat` | Northern Ireland VAT Number |
// | Norway | `no_vat` | Norwegian VAT Number |
// | Norway | `no_voec` | Norwegian VAT on e-commerce Number |
// | Oman | `om_vat` | Omani VAT Number |
// | Peru | `pe_ruc` | Peruvian RUC Number |
// | Philippines | `ph_tin` | Philippines Tax Identification Number |
// | Poland | `eu_vat` | European VAT Number |
// | Portugal | `eu_vat` | European VAT Number |
// | Romania | `eu_vat` | European VAT Number |
// | Romania | `ro_tin` | Romanian Tax ID Number |
// | Russia | `ru_inn` | Russian INN |
// | Russia | `ru_kpp` | Russian KPP |
// | Saudi Arabia | `sa_vat` | Saudi Arabia VAT |
// | Senegal | `sn_ninea` | Senegal NINEA Number |
// | Serbia | `rs_pib` | Serbian PIB Number |
// | Singapore | `sg_gst` | Singaporean GST |
// | Singapore | `sg_uen` | Singaporean UEN |
// | Slovakia | `eu_vat` | European VAT Number |
// | Slovenia | `eu_vat` | European VAT Number |
// | Slovenia | `si_tin` | Slovenia Tax Number (davčna številka) |
// | South Africa | `za_vat` | South African VAT Number |
// | South Korea | `kr_brn` | Korean BRN |
// | Spain | `es_cif` | Spanish NIF Number (previously Spanish CIF Number) |
// | Spain | `eu_vat` | European VAT Number |
// | Suriname | `sr_fin` | Suriname FIN Number |
// | Sweden | `eu_vat` | European VAT Number |
// | Switzerland | `ch_uid` | Switzerland UID Number |
// | Switzerland | `ch_vat` | Switzerland VAT Number |
// | Taiwan | `tw_vat` | Taiwanese VAT |
// | Tajikistan | `tj_tin` | Tajikistan Tax Identification Number |
// | Tanzania | `tz_vat` | Tanzania VAT Number |
// | Thailand | `th_vat` | Thai VAT |
// | Turkey | `tr_tin` | Turkish Tax Identification Number |
// | Uganda | `ug_tin` | Uganda Tax Identification Number |
// | Ukraine | `ua_vat` | Ukrainian VAT |
// | United Arab Emirates | `ae_trn` | United Arab Emirates TRN |
// | United Kingdom | `gb_vat` | United Kingdom VAT Number |
// | United States | `us_ein` | United States EIN |
// | Uruguay | `uy_ruc` | Uruguayan RUC Number |
// | Uzbekistan | `uz_tin` | Uzbekistan TIN Number |
// | Uzbekistan | `uz_vat` | Uzbekistan VAT Number |
// | Venezuela | `ve_rif` | Venezuelan RIF Number |
// | Vietnam | `vn_tin` | Vietnamese Tax ID Number |
// | Zambia | `zm_tin` | Zambia Tax Identification Number |
// | Zimbabwe | `zw_tin` | Zimbabwe Tax Identification Number |
CustomerTaxID shared.CustomerTaxID `json:"customer_tax_id,required,nullable"`
// This field is deprecated in favor of `discounts`. If a `discounts` list is
// provided, the first discount in the list will be returned. If the list is empty,
// `None` will be returned.
//
// Deprecated: deprecated
Discount interface{} `json:"discount,required"`
Discounts []shared.InvoiceLevelDiscount `json:"discounts,required"`
// When the invoice payment is due. The due date is null if the invoice is not yet
// finalized.
DueDate time.Time `json:"due_date,required,nullable" format:"date-time"`
// If the invoice has a status of `draft`, this will be the time that the invoice
// will be eligible to be issued, otherwise it will be `null`. If `auto-issue` is
// true, the invoice will automatically begin issuing at this time.
EligibleToIssueAt time.Time `json:"eligible_to_issue_at,required,nullable" format:"date-time"`
// A URL for the customer-facing invoice portal. This URL expires 30 days after the
// invoice's due date, or 60 days after being re-generated through the UI.
HostedInvoiceURL string `json:"hosted_invoice_url,required,nullable"`
// Automatically generated invoice number to help track and reconcile invoices.
// Invoice numbers have a prefix such as `RFOBWG`. These can be sequential per
// account or customer.
InvoiceNumber string `json:"invoice_number,required"`
// The link to download the PDF representation of the `Invoice`.
InvoicePdf string `json:"invoice_pdf,required,nullable"`
InvoiceSource InvoiceFetchUpcomingResponseInvoiceSource `json:"invoice_source,required"`
// If the invoice failed to issue, this will be the last time it failed to issue
// (even if it is now in a different state.)
IssueFailedAt time.Time `json:"issue_failed_at,required,nullable" format:"date-time"`
// If the invoice has been issued, this will be the time it transitioned to
// `issued` (even if it is now in a different state.)
IssuedAt time.Time `json:"issued_at,required,nullable" format:"date-time"`
// The breakdown of prices in this invoice.
LineItems []InvoiceFetchUpcomingResponseLineItem `json:"line_items,required"`
Maximum shared.Maximum `json:"maximum,required,nullable"`
MaximumAmount string `json:"maximum_amount,required,nullable"`
// Free-form text which is available on the invoice PDF and the Orb invoice portal.
Memo string `json:"memo,required,nullable"`
// User specified key-value pairs for the resource. If not present, this defaults
// to an empty dictionary. Individual keys can be removed by setting the value to
// `null`, and the entire metadata mapping can be cleared by setting `metadata` to
// `null`.
Metadata map[string]string `json:"metadata,required"`
Minimum shared.Minimum `json:"minimum,required,nullable"`
MinimumAmount string `json:"minimum_amount,required,nullable"`
// If the invoice has a status of `paid`, this gives a timestamp when the invoice
// was paid.
PaidAt time.Time `json:"paid_at,required,nullable" format:"date-time"`
// A list of payment attempts associated with the invoice
PaymentAttempts []InvoiceFetchUpcomingResponsePaymentAttempt `json:"payment_attempts,required"`
// If payment was attempted on this invoice but failed, this will be the time of
// the most recent attempt.
PaymentFailedAt time.Time `json:"payment_failed_at,required,nullable" format:"date-time"`
// If payment was attempted on this invoice, this will be the start time of the
// most recent attempt. This field is especially useful for delayed-notification
// payment mechanisms (like bank transfers), where payment can take 3 days or more.
PaymentStartedAt time.Time `json:"payment_started_at,required,nullable" format:"date-time"`
// If the invoice is in draft, this timestamp will reflect when the invoice is
// scheduled to be issued.
ScheduledIssueAt time.Time `json:"scheduled_issue_at,required,nullable" format:"date-time"`
ShippingAddress shared.Address `json:"shipping_address,required,nullable"`
Status InvoiceFetchUpcomingResponseStatus `json:"status,required"`
Subscription shared.SubscriptionMinified `json:"subscription,required,nullable"`
// The total before any discounts and minimums are applied.
Subtotal string `json:"subtotal,required"`
// If the invoice failed to sync, this will be the last time an external invoicing
// provider sync was attempted. This field will always be `null` for invoices using
// Orb Invoicing.
SyncFailedAt time.Time `json:"sync_failed_at,required,nullable" format:"date-time"`
// The scheduled date of the invoice
TargetDate time.Time `json:"target_date,required" format:"date-time"`
// The total after any minimums and discounts have been applied.
Total string `json:"total,required"`
// If the invoice has a status of `void`, this gives a timestamp when the invoice
// was voided.
VoidedAt time.Time `json:"voided_at,required,nullable" format:"date-time"`
// This is true if the invoice will be automatically issued in the future, and
// false otherwise.
WillAutoIssue bool `json:"will_auto_issue,required"`
JSON invoiceFetchUpcomingResponseJSON `json:"-"`
}
// invoiceFetchUpcomingResponseJSON contains the JSON metadata for the struct
// [InvoiceFetchUpcomingResponse]
type invoiceFetchUpcomingResponseJSON struct {
ID apijson.Field
AmountDue apijson.Field
AutoCollection apijson.Field
BillingAddress apijson.Field
CreatedAt apijson.Field
CreditNotes apijson.Field
Currency apijson.Field
Customer apijson.Field
CustomerBalanceTransactions apijson.Field
CustomerTaxID apijson.Field
Discount apijson.Field
Discounts apijson.Field
DueDate apijson.Field
EligibleToIssueAt apijson.Field
HostedInvoiceURL apijson.Field
InvoiceNumber apijson.Field
InvoicePdf apijson.Field
InvoiceSource apijson.Field
IssueFailedAt apijson.Field
IssuedAt apijson.Field
LineItems apijson.Field
Maximum apijson.Field
MaximumAmount apijson.Field
Memo apijson.Field
Metadata apijson.Field
Minimum apijson.Field
MinimumAmount apijson.Field
PaidAt apijson.Field
PaymentAttempts apijson.Field
PaymentFailedAt apijson.Field
PaymentStartedAt apijson.Field
ScheduledIssueAt apijson.Field
ShippingAddress apijson.Field
Status apijson.Field
Subscription apijson.Field
Subtotal apijson.Field
SyncFailedAt apijson.Field
TargetDate apijson.Field
Total apijson.Field
VoidedAt apijson.Field
WillAutoIssue apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *InvoiceFetchUpcomingResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r invoiceFetchUpcomingResponseJSON) RawJSON() string {
return r.raw
}
type InvoiceFetchUpcomingResponseAutoCollection struct {
// True only if auto-collection is enabled for this invoice.
Enabled bool `json:"enabled,required,nullable"`
// If the invoice is scheduled for auto-collection, this field will reflect when
// the next attempt will occur. If dunning has been exhausted, or auto-collection
// is not enabled for this invoice, this field will be `null`.
NextAttemptAt time.Time `json:"next_attempt_at,required,nullable" format:"date-time"`
// Number of auto-collection payment attempts.
NumAttempts int64 `json:"num_attempts,required,nullable"`
// If Orb has ever attempted payment auto-collection for this invoice, this field
// will reflect when that attempt occurred. In conjunction with `next_attempt_at`,
// this can be used to tell whether the invoice is currently in dunning (that is,
// `previously_attempted_at` is non-null, and `next_attempt_time` is non-null), or
// if dunning has been exhausted (`previously_attempted_at` is non-null, but
// `next_attempt_time` is null).
PreviouslyAttemptedAt time.Time `json:"previously_attempted_at,required,nullable" format:"date-time"`
JSON invoiceFetchUpcomingResponseAutoCollectionJSON `json:"-"`
}
// invoiceFetchUpcomingResponseAutoCollectionJSON contains the JSON metadata for
// the struct [InvoiceFetchUpcomingResponseAutoCollection]
type invoiceFetchUpcomingResponseAutoCollectionJSON struct {
Enabled apijson.Field
NextAttemptAt apijson.Field
NumAttempts apijson.Field
PreviouslyAttemptedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *InvoiceFetchUpcomingResponseAutoCollection) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r invoiceFetchUpcomingResponseAutoCollectionJSON) RawJSON() string {
return r.raw
}
type InvoiceFetchUpcomingResponseCreditNote struct {
ID string `json:"id,required"`
CreditNoteNumber string `json:"credit_note_number,required"`
// An optional memo supplied on the credit note.
Memo string `json:"memo,required,nullable"`
Reason string `json:"reason,required"`
Total string `json:"total,required"`
Type string `json:"type,required"`
// If the credit note has a status of `void`, this gives a timestamp when the
// credit note was voided.
VoidedAt time.Time `json:"voided_at,required,nullable" format:"date-time"`
JSON invoiceFetchUpcomingResponseCreditNoteJSON `json:"-"`
}
// invoiceFetchUpcomingResponseCreditNoteJSON contains the JSON metadata for the
// struct [InvoiceFetchUpcomingResponseCreditNote]
type invoiceFetchUpcomingResponseCreditNoteJSON struct {
ID apijson.Field
CreditNoteNumber apijson.Field
Memo apijson.Field
Reason apijson.Field
Total apijson.Field
Type apijson.Field
VoidedAt apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *InvoiceFetchUpcomingResponseCreditNote) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r invoiceFetchUpcomingResponseCreditNoteJSON) RawJSON() string {
return r.raw
}
type InvoiceFetchUpcomingResponseCustomerBalanceTransaction struct {
// A unique id for this transaction.
ID string `json:"id,required"`
Action InvoiceFetchUpcomingResponseCustomerBalanceTransactionsAction `json:"action,required"`
// The value of the amount changed in the transaction.
Amount string `json:"amount,required"`
// The creation time of this transaction.
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
CreditNote shared.CreditNoteTiny `json:"credit_note,required,nullable"`
// An optional description provided for manual customer balance adjustments.
Description string `json:"description,required,nullable"`
// The new value of the customer's balance prior to the transaction, in the
// customer's currency.
EndingBalance string `json:"ending_balance,required"`
Invoice shared.InvoiceTiny `json:"invoice,required,nullable"`
// The original value of the customer's balance prior to the transaction, in the
// customer's currency.
StartingBalance string `json:"starting_balance,required"`
Type InvoiceFetchUpcomingResponseCustomerBalanceTransactionsType `json:"type,required"`
JSON invoiceFetchUpcomingResponseCustomerBalanceTransactionJSON `json:"-"`
}
// invoiceFetchUpcomingResponseCustomerBalanceTransactionJSON contains the JSON
// metadata for the struct [InvoiceFetchUpcomingResponseCustomerBalanceTransaction]
type invoiceFetchUpcomingResponseCustomerBalanceTransactionJSON struct {
ID apijson.Field
Action apijson.Field
Amount apijson.Field
CreatedAt apijson.Field
CreditNote apijson.Field
Description apijson.Field
EndingBalance apijson.Field
Invoice apijson.Field
StartingBalance apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *InvoiceFetchUpcomingResponseCustomerBalanceTransaction) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r invoiceFetchUpcomingResponseCustomerBalanceTransactionJSON) RawJSON() string {
return r.raw
}
type InvoiceFetchUpcomingResponseCustomerBalanceTransactionsAction string
const (
InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionAppliedToInvoice InvoiceFetchUpcomingResponseCustomerBalanceTransactionsAction = "applied_to_invoice"
InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionManualAdjustment InvoiceFetchUpcomingResponseCustomerBalanceTransactionsAction = "manual_adjustment"
InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionProratedRefund InvoiceFetchUpcomingResponseCustomerBalanceTransactionsAction = "prorated_refund"
InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionRevertProratedRefund InvoiceFetchUpcomingResponseCustomerBalanceTransactionsAction = "revert_prorated_refund"
InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionReturnFromVoiding InvoiceFetchUpcomingResponseCustomerBalanceTransactionsAction = "return_from_voiding"
InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionCreditNoteApplied InvoiceFetchUpcomingResponseCustomerBalanceTransactionsAction = "credit_note_applied"
InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionCreditNoteVoided InvoiceFetchUpcomingResponseCustomerBalanceTransactionsAction = "credit_note_voided"
InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionOverpaymentRefund InvoiceFetchUpcomingResponseCustomerBalanceTransactionsAction = "overpayment_refund"
InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionExternalPayment InvoiceFetchUpcomingResponseCustomerBalanceTransactionsAction = "external_payment"
InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionSmallInvoiceCarryover InvoiceFetchUpcomingResponseCustomerBalanceTransactionsAction = "small_invoice_carryover"
)
func (r InvoiceFetchUpcomingResponseCustomerBalanceTransactionsAction) IsKnown() bool {
switch r {
case InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionAppliedToInvoice, InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionManualAdjustment, InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionProratedRefund, InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionRevertProratedRefund, InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionReturnFromVoiding, InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionCreditNoteApplied, InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionCreditNoteVoided, InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionOverpaymentRefund, InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionExternalPayment, InvoiceFetchUpcomingResponseCustomerBalanceTransactionsActionSmallInvoiceCarryover:
return true
}
return false
}
type InvoiceFetchUpcomingResponseCustomerBalanceTransactionsType string
const (
InvoiceFetchUpcomingResponseCustomerBalanceTransactionsTypeIncrement InvoiceFetchUpcomingResponseCustomerBalanceTransactionsType = "increment"
InvoiceFetchUpcomingResponseCustomerBalanceTransactionsTypeDecrement InvoiceFetchUpcomingResponseCustomerBalanceTransactionsType = "decrement"
)
func (r InvoiceFetchUpcomingResponseCustomerBalanceTransactionsType) IsKnown() bool {
switch r {
case InvoiceFetchUpcomingResponseCustomerBalanceTransactionsTypeIncrement, InvoiceFetchUpcomingResponseCustomerBalanceTransactionsTypeDecrement:
return true
}
return false
}
type InvoiceFetchUpcomingResponseInvoiceSource string
const (
InvoiceFetchUpcomingResponseInvoiceSourceSubscription InvoiceFetchUpcomingResponseInvoiceSource = "subscription"
InvoiceFetchUpcomingResponseInvoiceSourcePartial InvoiceFetchUpcomingResponseInvoiceSource = "partial"
InvoiceFetchUpcomingResponseInvoiceSourceOneOff InvoiceFetchUpcomingResponseInvoiceSource = "one_off"
)
func (r InvoiceFetchUpcomingResponseInvoiceSource) IsKnown() bool {
switch r {
case InvoiceFetchUpcomingResponseInvoiceSourceSubscription, InvoiceFetchUpcomingResponseInvoiceSourcePartial, InvoiceFetchUpcomingResponseInvoiceSourceOneOff:
return true
}
return false
}
type InvoiceFetchUpcomingResponseLineItem struct {
// A unique ID for this line item.
ID string `json:"id,required"`
// The line amount after any adjustments and before overage conversion, credits and
// partial invoicing.
AdjustedSubtotal string `json:"adjusted_subtotal,required"`
// All adjustments applied to the line item in the order they were applied based on
// invoice calculations (ie. usage discounts -> amount discounts -> percentage
// discounts -> minimums -> maximums).
Adjustments []InvoiceFetchUpcomingResponseLineItemsAdjustment `json:"adjustments,required"`
// The final amount for a line item after all adjustments and pre paid credits have
// been applied.
Amount string `json:"amount,required"`
// The number of prepaid credits applied.
CreditsApplied string `json:"credits_applied,required"`
// This field is deprecated in favor of `adjustments`
//
// Deprecated: deprecated
Discount shared.Discount `json:"discount,required,nullable"`
// The end date of the range of time applied for this line item's price.
EndDate time.Time `json:"end_date,required" format:"date-time"`
// An additional filter that was used to calculate the usage for this line item.
Filter string `json:"filter,required,nullable"`
// [DEPRECATED] For configured prices that are split by a grouping key, this will
// be populated with the key and a value. The `amount` and `subtotal` will be the
// values for this particular grouping.
Grouping string `json:"grouping,required,nullable"`
// This field is deprecated in favor of `adjustments`.
//
// Deprecated: deprecated
Maximum shared.Maximum `json:"maximum,required,nullable"`
// This field is deprecated in favor of `adjustments`.
//
// Deprecated: deprecated
MaximumAmount string `json:"maximum_amount,required,nullable"`
// This field is deprecated in favor of `adjustments`.
//
// Deprecated: deprecated
Minimum shared.Minimum `json:"minimum,required,nullable"`
// This field is deprecated in favor of `adjustments`.
//
// Deprecated: deprecated
MinimumAmount string `json:"minimum_amount,required,nullable"`
// The name of the price associated with this line item.
Name string `json:"name,required"`
// Any amount applied from a partial invoice
PartiallyInvoicedAmount string `json:"partially_invoiced_amount,required"`
// The Price resource represents a price that can be billed on a subscription,
// resulting in a charge on an invoice in the form of an invoice line item. Prices
// take a quantity and determine an amount to bill.
//
// Orb supports a few different pricing models out of the box. Each of these models
// is serialized differently in a given Price object. The model_type field
// determines the key for the configuration object that is present.
//
// For more on the types of prices, see
// [the core concepts documentation](/core-concepts#plan-and-price)
Price shared.Price `json:"price,required"`
// Either the fixed fee quantity or the usage during the service period.
Quantity float64 `json:"quantity,required"`
// The start date of the range of time applied for this line item's price.
StartDate time.Time `json:"start_date,required" format:"date-time"`
// For complex pricing structures, the line item can be broken down further in
// `sub_line_items`.
SubLineItems []InvoiceFetchUpcomingResponseLineItemsSubLineItem `json:"sub_line_items,required"`
// The line amount before any adjustments.
Subtotal string `json:"subtotal,required"`
// An array of tax rates and their incurred tax amounts. Empty if no tax
// integration is configured.
TaxAmounts []shared.TaxAmount `json:"tax_amounts,required"`
// A list of customer ids that were used to calculate the usage for this line item.
UsageCustomerIDs []string `json:"usage_customer_ids,required,nullable"`
JSON invoiceFetchUpcomingResponseLineItemJSON `json:"-"`
}
// invoiceFetchUpcomingResponseLineItemJSON contains the JSON metadata for the
// struct [InvoiceFetchUpcomingResponseLineItem]
type invoiceFetchUpcomingResponseLineItemJSON struct {
ID apijson.Field
AdjustedSubtotal apijson.Field
Adjustments apijson.Field
Amount apijson.Field
CreditsApplied apijson.Field
Discount apijson.Field
EndDate apijson.Field
Filter apijson.Field
Grouping apijson.Field
Maximum apijson.Field
MaximumAmount apijson.Field
Minimum apijson.Field
MinimumAmount apijson.Field
Name apijson.Field
PartiallyInvoicedAmount apijson.Field
Price apijson.Field
Quantity apijson.Field
StartDate apijson.Field
SubLineItems apijson.Field
Subtotal apijson.Field
TaxAmounts apijson.Field
UsageCustomerIDs apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *InvoiceFetchUpcomingResponseLineItem) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r invoiceFetchUpcomingResponseLineItemJSON) RawJSON() string {
return r.raw
}
type InvoiceFetchUpcomingResponseLineItemsAdjustment struct {
ID string `json:"id,required"`
AdjustmentType InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentType `json:"adjustment_type,required"`
// The value applied by an adjustment.
Amount string `json:"amount,required"`
// This field can have the runtime type of [[]string].
AppliesToPriceIDs interface{} `json:"applies_to_price_ids,required"`
// This field can have the runtime type of [[]shared.TransformPriceFilter].
Filters interface{} `json:"filters,required"`
// True for adjustments that apply to an entire invoice, false for adjustments that
// apply to only one price.
IsInvoiceLevel bool `json:"is_invoice_level,required"`
// The reason for the adjustment.
Reason string `json:"reason,required,nullable"`
// The adjustment id this adjustment replaces. This adjustment will take the place
// of the replaced adjustment in plan version migrations.
ReplacesAdjustmentID string `json:"replaces_adjustment_id,required,nullable"`
// The amount by which to discount the prices this adjustment applies to in a given
// billing period.
AmountDiscount string `json:"amount_discount"`
// The item ID that revenue from this minimum will be attributed to.
ItemID string `json:"item_id"`
// The maximum amount to charge in a given billing period for the prices this
// adjustment applies to.
MaximumAmount string `json:"maximum_amount"`
// The minimum amount to charge in a given billing period for the prices this
// adjustment applies to.
MinimumAmount string `json:"minimum_amount"`
// The percentage (as a value between 0 and 1) by which to discount the price
// intervals this adjustment applies to in a given billing period.
PercentageDiscount float64 `json:"percentage_discount"`
// The number of usage units by which to discount the price this adjustment applies
// to in a given billing period.
UsageDiscount float64 `json:"usage_discount"`
JSON invoiceFetchUpcomingResponseLineItemsAdjustmentJSON `json:"-"`
union InvoiceFetchUpcomingResponseLineItemsAdjustmentsUnion
}
// invoiceFetchUpcomingResponseLineItemsAdjustmentJSON contains the JSON metadata
// for the struct [InvoiceFetchUpcomingResponseLineItemsAdjustment]
type invoiceFetchUpcomingResponseLineItemsAdjustmentJSON struct {
ID apijson.Field
AdjustmentType apijson.Field
Amount apijson.Field
AppliesToPriceIDs apijson.Field
Filters apijson.Field
IsInvoiceLevel apijson.Field
Reason apijson.Field
ReplacesAdjustmentID apijson.Field
AmountDiscount apijson.Field
ItemID apijson.Field
MaximumAmount apijson.Field
MinimumAmount apijson.Field
PercentageDiscount apijson.Field
UsageDiscount apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r invoiceFetchUpcomingResponseLineItemsAdjustmentJSON) RawJSON() string {
return r.raw
}
func (r *InvoiceFetchUpcomingResponseLineItemsAdjustment) UnmarshalJSON(data []byte) (err error) {
*r = InvoiceFetchUpcomingResponseLineItemsAdjustment{}
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
// AsUnion returns a [InvoiceFetchUpcomingResponseLineItemsAdjustmentsUnion]
// interface which you can cast to the specific types for more type safety.
//
// Possible runtime types of the union are
// [shared.MonetaryUsageDiscountAdjustment],
// [shared.MonetaryAmountDiscountAdjustment],
// [shared.MonetaryPercentageDiscountAdjustment],
// [shared.MonetaryMinimumAdjustment], [shared.MonetaryMaximumAdjustment].
func (r InvoiceFetchUpcomingResponseLineItemsAdjustment) AsUnion() InvoiceFetchUpcomingResponseLineItemsAdjustmentsUnion {
return r.union
}
// Union satisfied by [shared.MonetaryUsageDiscountAdjustment],
// [shared.MonetaryAmountDiscountAdjustment],
// [shared.MonetaryPercentageDiscountAdjustment],
// [shared.MonetaryMinimumAdjustment] or [shared.MonetaryMaximumAdjustment].
type InvoiceFetchUpcomingResponseLineItemsAdjustmentsUnion interface {
ImplementsInvoiceFetchUpcomingResponseLineItemsAdjustment()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*InvoiceFetchUpcomingResponseLineItemsAdjustmentsUnion)(nil)).Elem(),
"adjustment_type",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(shared.MonetaryUsageDiscountAdjustment{}),
DiscriminatorValue: "usage_discount",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(shared.MonetaryAmountDiscountAdjustment{}),
DiscriminatorValue: "amount_discount",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(shared.MonetaryPercentageDiscountAdjustment{}),
DiscriminatorValue: "percentage_discount",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(shared.MonetaryMinimumAdjustment{}),
DiscriminatorValue: "minimum",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(shared.MonetaryMaximumAdjustment{}),
DiscriminatorValue: "maximum",
},
)
}
type InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentType string
const (
InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentTypeUsageDiscount InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentType = "usage_discount"
InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentTypeAmountDiscount InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentType = "amount_discount"
InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentTypePercentageDiscount InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentType = "percentage_discount"
InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentTypeMinimum InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentType = "minimum"
InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentTypeMaximum InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentType = "maximum"
)
func (r InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentType) IsKnown() bool {
switch r {
case InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentTypeUsageDiscount, InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentTypeAmountDiscount, InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentTypePercentageDiscount, InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentTypeMinimum, InvoiceFetchUpcomingResponseLineItemsAdjustmentsAdjustmentTypeMaximum:
return true
}
return false
}
type InvoiceFetchUpcomingResponseLineItemsSubLineItem struct {
// The total amount for this sub line item.
Amount string `json:"amount,required"`
Grouping shared.SubLineItemGrouping `json:"grouping,required,nullable"`
Name string `json:"name,required"`
Quantity float64 `json:"quantity,required"`
Type InvoiceFetchUpcomingResponseLineItemsSubLineItemsType `json:"type,required"`
MatrixConfig shared.SubLineItemMatrixConfig `json:"matrix_config"`
// This field can have the runtime type of [shared.TierSubLineItemTierConfig].
TierConfig interface{} `json:"tier_config"`
JSON invoiceFetchUpcomingResponseLineItemsSubLineItemJSON `json:"-"`
union InvoiceFetchUpcomingResponseLineItemsSubLineItemsUnion
}
// invoiceFetchUpcomingResponseLineItemsSubLineItemJSON contains the JSON metadata
// for the struct [InvoiceFetchUpcomingResponseLineItemsSubLineItem]
type invoiceFetchUpcomingResponseLineItemsSubLineItemJSON struct {
Amount apijson.Field
Grouping apijson.Field
Name apijson.Field
Quantity apijson.Field
Type apijson.Field
MatrixConfig apijson.Field
TierConfig apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r invoiceFetchUpcomingResponseLineItemsSubLineItemJSON) RawJSON() string {
return r.raw
}
func (r *InvoiceFetchUpcomingResponseLineItemsSubLineItem) UnmarshalJSON(data []byte) (err error) {
*r = InvoiceFetchUpcomingResponseLineItemsSubLineItem{}
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
// AsUnion returns a [InvoiceFetchUpcomingResponseLineItemsSubLineItemsUnion]
// interface which you can cast to the specific types for more type safety.
//
// Possible runtime types of the union are [shared.MatrixSubLineItem],
// [shared.TierSubLineItem], [shared.OtherSubLineItem].
func (r InvoiceFetchUpcomingResponseLineItemsSubLineItem) AsUnion() InvoiceFetchUpcomingResponseLineItemsSubLineItemsUnion {
return r.union
}
// Union satisfied by [shared.MatrixSubLineItem], [shared.TierSubLineItem] or
// [shared.OtherSubLineItem].
type InvoiceFetchUpcomingResponseLineItemsSubLineItemsUnion interface {
ImplementsInvoiceFetchUpcomingResponseLineItemsSubLineItem()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*InvoiceFetchUpcomingResponseLineItemsSubLineItemsUnion)(nil)).Elem(),
"type",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(shared.MatrixSubLineItem{}),
DiscriminatorValue: "matrix",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(shared.TierSubLineItem{}),
DiscriminatorValue: "tier",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(shared.OtherSubLineItem{}),