-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplan.go
4164 lines (3612 loc) · 208 KB
/
plan.go
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"
)
// PlanService 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 [NewPlanService] method instead.
type PlanService struct {
Options []option.RequestOption
ExternalPlanID *PlanExternalPlanIDService
}
// NewPlanService 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 NewPlanService(opts ...option.RequestOption) (r *PlanService) {
r = &PlanService{}
r.Options = opts
r.ExternalPlanID = NewPlanExternalPlanIDService(opts...)
return
}
// This endpoint allows creation of plans including their prices.
func (r *PlanService) New(ctx context.Context, body PlanNewParams, opts ...option.RequestOption) (res *Plan, err error) {
opts = append(r.Options[:], opts...)
path := "plans"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// This endpoint can be used to update the `external_plan_id`, and `metadata` of an
// existing plan.
//
// Other fields on a customer are currently immutable.
func (r *PlanService) Update(ctx context.Context, planID string, body PlanUpdateParams, opts ...option.RequestOption) (res *Plan, err error) {
opts = append(r.Options[:], opts...)
if planID == "" {
err = errors.New("missing required plan_id parameter")
return
}
path := fmt.Sprintf("plans/%s", planID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPut, path, body, &res, opts...)
return
}
// This endpoint returns a list of all [plans](../guides/concepts##plan-and-price)
// for an account in a list format. The list of plans is ordered starting from the
// most recently created plan. The response also includes
// [`pagination_metadata`](../reference/pagination), which lets the caller retrieve
// the next page of results if they exist.
func (r *PlanService) List(ctx context.Context, query PlanListParams, opts ...option.RequestOption) (res *pagination.Page[Plan], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "plans"
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 [plans](../guides/concepts##plan-and-price)
// for an account in a list format. The list of plans is ordered starting from the
// most recently created plan. The response also includes
// [`pagination_metadata`](../reference/pagination), which lets the caller retrieve
// the next page of results if they exist.
func (r *PlanService) ListAutoPaging(ctx context.Context, query PlanListParams, opts ...option.RequestOption) *pagination.PageAutoPager[Plan] {
return pagination.NewPageAutoPager(r.List(ctx, query, opts...))
}
// This endpoint is used to fetch [plan](../guides/concepts##plan-and-price)
// details given a plan identifier. It returns information about the prices
// included in the plan and their configuration, as well as the product that the
// plan is attached to.
//
// ## Serialized prices
//
// Orb supports a few different pricing models out of the box. Each of these models
// is serialized differently in a given [Price](../guides/concepts#plan-and-price)
// object. The `model_type` field determines the key for the configuration object
// that is present. A detailed explanation of price types can be found in the
// [Price schema](../guides/concepts#plan-and-price).
//
// ## Phases
//
// Orb supports plan phases, also known as contract ramps. For plans with phases,
// the serialized prices refer to all prices across all phases.
func (r *PlanService) Fetch(ctx context.Context, planID string, opts ...option.RequestOption) (res *Plan, err error) {
opts = append(r.Options[:], opts...)
if planID == "" {
err = errors.New("missing required plan_id parameter")
return
}
path := fmt.Sprintf("plans/%s", planID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// The [Plan](../guides/core-concepts.mdx#plan-and-price) resource represents a
// plan that can be subscribed to by a customer. Plans define the billing behavior
// of the subscription. You can see more about how to configure prices in the
// [Price resource](/reference/price).
type Plan struct {
ID string `json:"id,required"`
// Adjustments for this plan. If the plan has phases, this includes adjustments
// across all phases of the plan.
Adjustments []PlanAdjustment `json:"adjustments,required"`
BasePlan PlanBasePlan `json:"base_plan,required,nullable"`
// The parent plan id if the given plan was created by overriding one or more of
// the parent's prices
BasePlanID string `json:"base_plan_id,required,nullable"`
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
// An ISO 4217 currency string or custom pricing unit (`credits`) for this plan's
// prices.
Currency string `json:"currency,required"`
// The default memo text on the invoices corresponding to subscriptions on this
// plan. Note that each subscription may configure its own memo.
DefaultInvoiceMemo string `json:"default_invoice_memo,required,nullable"`
Description string `json:"description,required"`
Discount shared.Discount `json:"discount,required,nullable"`
// An optional user-defined ID for this plan resource, used throughout the system
// as an alias for this Plan. Use this field to identify a plan by an existing
// identifier in your system.
ExternalPlanID string `json:"external_plan_id,required,nullable"`
// An ISO 4217 currency string for which this plan is billed in. Matches `currency`
// unless `currency` is a custom pricing unit.
InvoicingCurrency string `json:"invoicing_currency,required"`
Maximum PlanMaximum `json:"maximum,required,nullable"`
MaximumAmount string `json:"maximum_amount,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 PlanMinimum `json:"minimum,required,nullable"`
MinimumAmount string `json:"minimum_amount,required,nullable"`
Name string `json:"name,required"`
// Determines the difference between the invoice issue date and the due date. A
// value of "0" here signifies that invoices are due on issue, whereas a value of
// "30" means that the customer has a month to pay the invoice before its overdue.
// Note that individual subscriptions or invoices may set a different net terms
// configuration.
NetTerms int64 `json:"net_terms,required,nullable"`
PlanPhases []PlanPlanPhase `json:"plan_phases,required,nullable"`
// Prices for this plan. If the plan has phases, this includes prices across all
// phases of the plan.
Prices []Price `json:"prices,required"`
Product PlanProduct `json:"product,required"`
Status PlanStatus `json:"status,required"`
TrialConfig PlanTrialConfig `json:"trial_config,required"`
Version int64 `json:"version,required"`
JSON planJSON `json:"-"`
}
// planJSON contains the JSON metadata for the struct [Plan]
type planJSON struct {
ID apijson.Field
Adjustments apijson.Field
BasePlan apijson.Field
BasePlanID apijson.Field
CreatedAt apijson.Field
Currency apijson.Field
DefaultInvoiceMemo apijson.Field
Description apijson.Field
Discount apijson.Field
ExternalPlanID apijson.Field
InvoicingCurrency apijson.Field
Maximum apijson.Field
MaximumAmount apijson.Field
Metadata apijson.Field
Minimum apijson.Field
MinimumAmount apijson.Field
Name apijson.Field
NetTerms apijson.Field
PlanPhases apijson.Field
Prices apijson.Field
Product apijson.Field
Status apijson.Field
TrialConfig apijson.Field
Version apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Plan) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planJSON) RawJSON() string {
return r.raw
}
type PlanAdjustment struct {
ID string `json:"id,required"`
AdjustmentType PlanAdjustmentsAdjustmentType `json:"adjustment_type,required"`
// This field can have the runtime type of [[]string].
AppliesToPriceIDs interface{} `json:"applies_to_price_ids,required"`
// True for adjustments that apply to an entire invocice, false for adjustments
// that apply to only one price.
IsInvoiceLevel bool `json:"is_invoice_level,required"`
// The plan phase in which this adjustment is active.
PlanPhaseOrder int64 `json:"plan_phase_order,required,nullable"`
// The reason for the adjustment.
Reason string `json:"reason,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 planAdjustmentJSON `json:"-"`
union PlanAdjustmentsUnion
}
// planAdjustmentJSON contains the JSON metadata for the struct [PlanAdjustment]
type planAdjustmentJSON struct {
ID apijson.Field
AdjustmentType apijson.Field
AppliesToPriceIDs apijson.Field
IsInvoiceLevel apijson.Field
PlanPhaseOrder apijson.Field
Reason 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 planAdjustmentJSON) RawJSON() string {
return r.raw
}
func (r *PlanAdjustment) UnmarshalJSON(data []byte) (err error) {
*r = PlanAdjustment{}
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
// AsUnion returns a [PlanAdjustmentsUnion] interface which you can cast to the
// specific types for more type safety.
//
// Possible runtime types of the union are
// [PlanAdjustmentsAmountDiscountAdjustment],
// [PlanAdjustmentsPercentageDiscountAdjustment],
// [PlanAdjustmentsUsageDiscountAdjustment], [PlanAdjustmentsMinimumAdjustment],
// [PlanAdjustmentsMaximumAdjustment].
func (r PlanAdjustment) AsUnion() PlanAdjustmentsUnion {
return r.union
}
// Union satisfied by [PlanAdjustmentsAmountDiscountAdjustment],
// [PlanAdjustmentsPercentageDiscountAdjustment],
// [PlanAdjustmentsUsageDiscountAdjustment], [PlanAdjustmentsMinimumAdjustment] or
// [PlanAdjustmentsMaximumAdjustment].
type PlanAdjustmentsUnion interface {
implementsPlanAdjustment()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*PlanAdjustmentsUnion)(nil)).Elem(),
"adjustment_type",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(PlanAdjustmentsAmountDiscountAdjustment{}),
DiscriminatorValue: "amount_discount",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(PlanAdjustmentsPercentageDiscountAdjustment{}),
DiscriminatorValue: "percentage_discount",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(PlanAdjustmentsUsageDiscountAdjustment{}),
DiscriminatorValue: "usage_discount",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(PlanAdjustmentsMinimumAdjustment{}),
DiscriminatorValue: "minimum",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(PlanAdjustmentsMaximumAdjustment{}),
DiscriminatorValue: "maximum",
},
)
}
type PlanAdjustmentsAmountDiscountAdjustment struct {
ID string `json:"id,required"`
AdjustmentType PlanAdjustmentsAmountDiscountAdjustmentAdjustmentType `json:"adjustment_type,required"`
// The amount by which to discount the prices this adjustment applies to in a given
// billing period.
AmountDiscount string `json:"amount_discount,required"`
// The price IDs that this adjustment applies to.
AppliesToPriceIDs []string `json:"applies_to_price_ids,required"`
// True for adjustments that apply to an entire invocice, false for adjustments
// that apply to only one price.
IsInvoiceLevel bool `json:"is_invoice_level,required"`
// The plan phase in which this adjustment is active.
PlanPhaseOrder int64 `json:"plan_phase_order,required,nullable"`
// The reason for the adjustment.
Reason string `json:"reason,required,nullable"`
JSON planAdjustmentsAmountDiscountAdjustmentJSON `json:"-"`
}
// planAdjustmentsAmountDiscountAdjustmentJSON contains the JSON metadata for the
// struct [PlanAdjustmentsAmountDiscountAdjustment]
type planAdjustmentsAmountDiscountAdjustmentJSON struct {
ID apijson.Field
AdjustmentType apijson.Field
AmountDiscount apijson.Field
AppliesToPriceIDs apijson.Field
IsInvoiceLevel apijson.Field
PlanPhaseOrder apijson.Field
Reason apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PlanAdjustmentsAmountDiscountAdjustment) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planAdjustmentsAmountDiscountAdjustmentJSON) RawJSON() string {
return r.raw
}
func (r PlanAdjustmentsAmountDiscountAdjustment) implementsPlanAdjustment() {}
type PlanAdjustmentsAmountDiscountAdjustmentAdjustmentType string
const (
PlanAdjustmentsAmountDiscountAdjustmentAdjustmentTypeAmountDiscount PlanAdjustmentsAmountDiscountAdjustmentAdjustmentType = "amount_discount"
)
func (r PlanAdjustmentsAmountDiscountAdjustmentAdjustmentType) IsKnown() bool {
switch r {
case PlanAdjustmentsAmountDiscountAdjustmentAdjustmentTypeAmountDiscount:
return true
}
return false
}
type PlanAdjustmentsPercentageDiscountAdjustment struct {
ID string `json:"id,required"`
AdjustmentType PlanAdjustmentsPercentageDiscountAdjustmentAdjustmentType `json:"adjustment_type,required"`
// The price IDs that this adjustment applies to.
AppliesToPriceIDs []string `json:"applies_to_price_ids,required"`
// True for adjustments that apply to an entire invocice, false for adjustments
// that apply to only one price.
IsInvoiceLevel bool `json:"is_invoice_level,required"`
// 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,required"`
// The plan phase in which this adjustment is active.
PlanPhaseOrder int64 `json:"plan_phase_order,required,nullable"`
// The reason for the adjustment.
Reason string `json:"reason,required,nullable"`
JSON planAdjustmentsPercentageDiscountAdjustmentJSON `json:"-"`
}
// planAdjustmentsPercentageDiscountAdjustmentJSON contains the JSON metadata for
// the struct [PlanAdjustmentsPercentageDiscountAdjustment]
type planAdjustmentsPercentageDiscountAdjustmentJSON struct {
ID apijson.Field
AdjustmentType apijson.Field
AppliesToPriceIDs apijson.Field
IsInvoiceLevel apijson.Field
PercentageDiscount apijson.Field
PlanPhaseOrder apijson.Field
Reason apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PlanAdjustmentsPercentageDiscountAdjustment) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planAdjustmentsPercentageDiscountAdjustmentJSON) RawJSON() string {
return r.raw
}
func (r PlanAdjustmentsPercentageDiscountAdjustment) implementsPlanAdjustment() {}
type PlanAdjustmentsPercentageDiscountAdjustmentAdjustmentType string
const (
PlanAdjustmentsPercentageDiscountAdjustmentAdjustmentTypePercentageDiscount PlanAdjustmentsPercentageDiscountAdjustmentAdjustmentType = "percentage_discount"
)
func (r PlanAdjustmentsPercentageDiscountAdjustmentAdjustmentType) IsKnown() bool {
switch r {
case PlanAdjustmentsPercentageDiscountAdjustmentAdjustmentTypePercentageDiscount:
return true
}
return false
}
type PlanAdjustmentsUsageDiscountAdjustment struct {
ID string `json:"id,required"`
AdjustmentType PlanAdjustmentsUsageDiscountAdjustmentAdjustmentType `json:"adjustment_type,required"`
// The price IDs that this adjustment applies to.
AppliesToPriceIDs []string `json:"applies_to_price_ids,required"`
// True for adjustments that apply to an entire invocice, false for adjustments
// that apply to only one price.
IsInvoiceLevel bool `json:"is_invoice_level,required"`
// The plan phase in which this adjustment is active.
PlanPhaseOrder int64 `json:"plan_phase_order,required,nullable"`
// The reason for the adjustment.
Reason string `json:"reason,required,nullable"`
// 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,required"`
JSON planAdjustmentsUsageDiscountAdjustmentJSON `json:"-"`
}
// planAdjustmentsUsageDiscountAdjustmentJSON contains the JSON metadata for the
// struct [PlanAdjustmentsUsageDiscountAdjustment]
type planAdjustmentsUsageDiscountAdjustmentJSON struct {
ID apijson.Field
AdjustmentType apijson.Field
AppliesToPriceIDs apijson.Field
IsInvoiceLevel apijson.Field
PlanPhaseOrder apijson.Field
Reason apijson.Field
UsageDiscount apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PlanAdjustmentsUsageDiscountAdjustment) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planAdjustmentsUsageDiscountAdjustmentJSON) RawJSON() string {
return r.raw
}
func (r PlanAdjustmentsUsageDiscountAdjustment) implementsPlanAdjustment() {}
type PlanAdjustmentsUsageDiscountAdjustmentAdjustmentType string
const (
PlanAdjustmentsUsageDiscountAdjustmentAdjustmentTypeUsageDiscount PlanAdjustmentsUsageDiscountAdjustmentAdjustmentType = "usage_discount"
)
func (r PlanAdjustmentsUsageDiscountAdjustmentAdjustmentType) IsKnown() bool {
switch r {
case PlanAdjustmentsUsageDiscountAdjustmentAdjustmentTypeUsageDiscount:
return true
}
return false
}
type PlanAdjustmentsMinimumAdjustment struct {
ID string `json:"id,required"`
AdjustmentType PlanAdjustmentsMinimumAdjustmentAdjustmentType `json:"adjustment_type,required"`
// The price IDs that this adjustment applies to.
AppliesToPriceIDs []string `json:"applies_to_price_ids,required"`
// True for adjustments that apply to an entire invocice, false for adjustments
// that apply to only one price.
IsInvoiceLevel bool `json:"is_invoice_level,required"`
// The item ID that revenue from this minimum will be attributed to.
ItemID string `json:"item_id,required"`
// The minimum amount to charge in a given billing period for the prices this
// adjustment applies to.
MinimumAmount string `json:"minimum_amount,required"`
// The plan phase in which this adjustment is active.
PlanPhaseOrder int64 `json:"plan_phase_order,required,nullable"`
// The reason for the adjustment.
Reason string `json:"reason,required,nullable"`
JSON planAdjustmentsMinimumAdjustmentJSON `json:"-"`
}
// planAdjustmentsMinimumAdjustmentJSON contains the JSON metadata for the struct
// [PlanAdjustmentsMinimumAdjustment]
type planAdjustmentsMinimumAdjustmentJSON struct {
ID apijson.Field
AdjustmentType apijson.Field
AppliesToPriceIDs apijson.Field
IsInvoiceLevel apijson.Field
ItemID apijson.Field
MinimumAmount apijson.Field
PlanPhaseOrder apijson.Field
Reason apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PlanAdjustmentsMinimumAdjustment) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planAdjustmentsMinimumAdjustmentJSON) RawJSON() string {
return r.raw
}
func (r PlanAdjustmentsMinimumAdjustment) implementsPlanAdjustment() {}
type PlanAdjustmentsMinimumAdjustmentAdjustmentType string
const (
PlanAdjustmentsMinimumAdjustmentAdjustmentTypeMinimum PlanAdjustmentsMinimumAdjustmentAdjustmentType = "minimum"
)
func (r PlanAdjustmentsMinimumAdjustmentAdjustmentType) IsKnown() bool {
switch r {
case PlanAdjustmentsMinimumAdjustmentAdjustmentTypeMinimum:
return true
}
return false
}
type PlanAdjustmentsMaximumAdjustment struct {
ID string `json:"id,required"`
AdjustmentType PlanAdjustmentsMaximumAdjustmentAdjustmentType `json:"adjustment_type,required"`
// The price IDs that this adjustment applies to.
AppliesToPriceIDs []string `json:"applies_to_price_ids,required"`
// True for adjustments that apply to an entire invocice, false for adjustments
// that apply to only one price.
IsInvoiceLevel bool `json:"is_invoice_level,required"`
// The maximum amount to charge in a given billing period for the prices this
// adjustment applies to.
MaximumAmount string `json:"maximum_amount,required"`
// The plan phase in which this adjustment is active.
PlanPhaseOrder int64 `json:"plan_phase_order,required,nullable"`
// The reason for the adjustment.
Reason string `json:"reason,required,nullable"`
JSON planAdjustmentsMaximumAdjustmentJSON `json:"-"`
}
// planAdjustmentsMaximumAdjustmentJSON contains the JSON metadata for the struct
// [PlanAdjustmentsMaximumAdjustment]
type planAdjustmentsMaximumAdjustmentJSON struct {
ID apijson.Field
AdjustmentType apijson.Field
AppliesToPriceIDs apijson.Field
IsInvoiceLevel apijson.Field
MaximumAmount apijson.Field
PlanPhaseOrder apijson.Field
Reason apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PlanAdjustmentsMaximumAdjustment) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planAdjustmentsMaximumAdjustmentJSON) RawJSON() string {
return r.raw
}
func (r PlanAdjustmentsMaximumAdjustment) implementsPlanAdjustment() {}
type PlanAdjustmentsMaximumAdjustmentAdjustmentType string
const (
PlanAdjustmentsMaximumAdjustmentAdjustmentTypeMaximum PlanAdjustmentsMaximumAdjustmentAdjustmentType = "maximum"
)
func (r PlanAdjustmentsMaximumAdjustmentAdjustmentType) IsKnown() bool {
switch r {
case PlanAdjustmentsMaximumAdjustmentAdjustmentTypeMaximum:
return true
}
return false
}
type PlanAdjustmentsAdjustmentType string
const (
PlanAdjustmentsAdjustmentTypeAmountDiscount PlanAdjustmentsAdjustmentType = "amount_discount"
PlanAdjustmentsAdjustmentTypePercentageDiscount PlanAdjustmentsAdjustmentType = "percentage_discount"
PlanAdjustmentsAdjustmentTypeUsageDiscount PlanAdjustmentsAdjustmentType = "usage_discount"
PlanAdjustmentsAdjustmentTypeMinimum PlanAdjustmentsAdjustmentType = "minimum"
PlanAdjustmentsAdjustmentTypeMaximum PlanAdjustmentsAdjustmentType = "maximum"
)
func (r PlanAdjustmentsAdjustmentType) IsKnown() bool {
switch r {
case PlanAdjustmentsAdjustmentTypeAmountDiscount, PlanAdjustmentsAdjustmentTypePercentageDiscount, PlanAdjustmentsAdjustmentTypeUsageDiscount, PlanAdjustmentsAdjustmentTypeMinimum, PlanAdjustmentsAdjustmentTypeMaximum:
return true
}
return false
}
type PlanBasePlan struct {
ID string `json:"id,required,nullable"`
// An optional user-defined ID for this plan resource, used throughout the system
// as an alias for this Plan. Use this field to identify a plan by an existing
// identifier in your system.
ExternalPlanID string `json:"external_plan_id,required,nullable"`
Name string `json:"name,required,nullable"`
JSON planBasePlanJSON `json:"-"`
}
// planBasePlanJSON contains the JSON metadata for the struct [PlanBasePlan]
type planBasePlanJSON struct {
ID apijson.Field
ExternalPlanID apijson.Field
Name apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PlanBasePlan) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planBasePlanJSON) RawJSON() string {
return r.raw
}
type PlanMaximum struct {
// List of price_ids that this maximum amount applies to. For plan/plan phase
// maximums, this can be a subset of prices.
AppliesToPriceIDs []string `json:"applies_to_price_ids,required"`
// Maximum amount applied
MaximumAmount string `json:"maximum_amount,required"`
JSON planMaximumJSON `json:"-"`
}
// planMaximumJSON contains the JSON metadata for the struct [PlanMaximum]
type planMaximumJSON struct {
AppliesToPriceIDs apijson.Field
MaximumAmount apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PlanMaximum) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planMaximumJSON) RawJSON() string {
return r.raw
}
type PlanMinimum struct {
// List of price_ids that this minimum amount applies to. For plan/plan phase
// minimums, this can be a subset of prices.
AppliesToPriceIDs []string `json:"applies_to_price_ids,required"`
// Minimum amount applied
MinimumAmount string `json:"minimum_amount,required"`
JSON planMinimumJSON `json:"-"`
}
// planMinimumJSON contains the JSON metadata for the struct [PlanMinimum]
type planMinimumJSON struct {
AppliesToPriceIDs apijson.Field
MinimumAmount apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PlanMinimum) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planMinimumJSON) RawJSON() string {
return r.raw
}
type PlanPlanPhase struct {
ID string `json:"id,required"`
Description string `json:"description,required,nullable"`
Discount shared.Discount `json:"discount,required,nullable"`
// How many terms of length `duration_unit` this phase is active for. If null, this
// phase is evergreen and active indefinitely
Duration int64 `json:"duration,required,nullable"`
DurationUnit PlanPlanPhasesDurationUnit `json:"duration_unit,required,nullable"`
Maximum PlanPlanPhasesMaximum `json:"maximum,required,nullable"`
MaximumAmount string `json:"maximum_amount,required,nullable"`
Minimum PlanPlanPhasesMinimum `json:"minimum,required,nullable"`
MinimumAmount string `json:"minimum_amount,required,nullable"`
Name string `json:"name,required"`
// Determines the ordering of the phase in a plan's lifecycle. 1 = first phase.
Order int64 `json:"order,required"`
JSON planPlanPhaseJSON `json:"-"`
}
// planPlanPhaseJSON contains the JSON metadata for the struct [PlanPlanPhase]
type planPlanPhaseJSON struct {
ID apijson.Field
Description apijson.Field
Discount apijson.Field
Duration apijson.Field
DurationUnit apijson.Field
Maximum apijson.Field
MaximumAmount apijson.Field
Minimum apijson.Field
MinimumAmount apijson.Field
Name apijson.Field
Order apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PlanPlanPhase) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planPlanPhaseJSON) RawJSON() string {
return r.raw
}
type PlanPlanPhasesDurationUnit string
const (
PlanPlanPhasesDurationUnitDaily PlanPlanPhasesDurationUnit = "daily"
PlanPlanPhasesDurationUnitMonthly PlanPlanPhasesDurationUnit = "monthly"
PlanPlanPhasesDurationUnitQuarterly PlanPlanPhasesDurationUnit = "quarterly"
PlanPlanPhasesDurationUnitSemiAnnual PlanPlanPhasesDurationUnit = "semi_annual"
PlanPlanPhasesDurationUnitAnnual PlanPlanPhasesDurationUnit = "annual"
)
func (r PlanPlanPhasesDurationUnit) IsKnown() bool {
switch r {
case PlanPlanPhasesDurationUnitDaily, PlanPlanPhasesDurationUnitMonthly, PlanPlanPhasesDurationUnitQuarterly, PlanPlanPhasesDurationUnitSemiAnnual, PlanPlanPhasesDurationUnitAnnual:
return true
}
return false
}
type PlanPlanPhasesMaximum struct {
// List of price_ids that this maximum amount applies to. For plan/plan phase
// maximums, this can be a subset of prices.
AppliesToPriceIDs []string `json:"applies_to_price_ids,required"`
// Maximum amount applied
MaximumAmount string `json:"maximum_amount,required"`
JSON planPlanPhasesMaximumJSON `json:"-"`
}
// planPlanPhasesMaximumJSON contains the JSON metadata for the struct
// [PlanPlanPhasesMaximum]
type planPlanPhasesMaximumJSON struct {
AppliesToPriceIDs apijson.Field
MaximumAmount apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PlanPlanPhasesMaximum) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planPlanPhasesMaximumJSON) RawJSON() string {
return r.raw
}
type PlanPlanPhasesMinimum struct {
// List of price_ids that this minimum amount applies to. For plan/plan phase
// minimums, this can be a subset of prices.
AppliesToPriceIDs []string `json:"applies_to_price_ids,required"`
// Minimum amount applied
MinimumAmount string `json:"minimum_amount,required"`
JSON planPlanPhasesMinimumJSON `json:"-"`
}
// planPlanPhasesMinimumJSON contains the JSON metadata for the struct
// [PlanPlanPhasesMinimum]
type planPlanPhasesMinimumJSON struct {
AppliesToPriceIDs apijson.Field
MinimumAmount apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PlanPlanPhasesMinimum) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planPlanPhasesMinimumJSON) RawJSON() string {
return r.raw
}
type PlanProduct struct {
ID string `json:"id,required"`
CreatedAt time.Time `json:"created_at,required" format:"date-time"`
Name string `json:"name,required"`
JSON planProductJSON `json:"-"`
}
// planProductJSON contains the JSON metadata for the struct [PlanProduct]
type planProductJSON struct {
ID apijson.Field
CreatedAt apijson.Field
Name apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PlanProduct) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planProductJSON) RawJSON() string {
return r.raw
}
type PlanStatus string
const (
PlanStatusActive PlanStatus = "active"
PlanStatusArchived PlanStatus = "archived"
PlanStatusDraft PlanStatus = "draft"
)
func (r PlanStatus) IsKnown() bool {
switch r {
case PlanStatusActive, PlanStatusArchived, PlanStatusDraft:
return true
}
return false
}
type PlanTrialConfig struct {
TrialPeriod int64 `json:"trial_period,required,nullable"`
TrialPeriodUnit PlanTrialConfigTrialPeriodUnit `json:"trial_period_unit,required"`
JSON planTrialConfigJSON `json:"-"`
}
// planTrialConfigJSON contains the JSON metadata for the struct [PlanTrialConfig]
type planTrialConfigJSON struct {
TrialPeriod apijson.Field
TrialPeriodUnit apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *PlanTrialConfig) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r planTrialConfigJSON) RawJSON() string {
return r.raw
}
type PlanTrialConfigTrialPeriodUnit string
const (
PlanTrialConfigTrialPeriodUnitDays PlanTrialConfigTrialPeriodUnit = "days"
)
func (r PlanTrialConfigTrialPeriodUnit) IsKnown() bool {
switch r {
case PlanTrialConfigTrialPeriodUnitDays:
return true
}
return false
}
type PlanNewParams struct {
// An ISO 4217 currency string for invoices generated by subscriptions on this
// plan.
Currency param.Field[string] `json:"currency,required"`
Name param.Field[string] `json:"name,required"`
// Prices for this plan. If the plan has phases, this includes prices across all
// phases of the plan.
Prices param.Field[[]PlanNewParamsPriceUnion] `json:"prices,required"`
// Free-form text which is available on the invoice PDF and the Orb invoice portal.
DefaultInvoiceMemo param.Field[string] `json:"default_invoice_memo"`
ExternalPlanID param.Field[string] `json:"external_plan_id"`
// User-specified key/value pairs for the resource. 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 param.Field[map[string]string] `json:"metadata"`
// The net terms determines the difference between the invoice date and the issue
// date for the invoice. If you intend the invoice to be due on issue, set this
// to 0.
NetTerms param.Field[int64] `json:"net_terms"`
// The status of the plan to create (either active or draft). If not specified,
// this defaults to active.
Status param.Field[PlanNewParamsStatus] `json:"status"`
}
func (r PlanNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type PlanNewParamsPrice struct {
// The cadence to bill for this price on.
Cadence param.Field[PlanNewParamsPricesCadence] `json:"cadence,required"`
// The id of the item the plan will be associated with.
ItemID param.Field[string] `json:"item_id,required"`
ModelType param.Field[PlanNewParamsPricesModelType] `json:"model_type,required"`
// The name of the price.
Name param.Field[string] `json:"name,required"`
// The id of the billable metric for the price. Only needed if the price is
// usage-based.
BillableMetricID param.Field[string] `json:"billable_metric_id"`
// If the Price represents a fixed cost, the price will be billed in-advance if
// this is true, and in-arrears if this is false.
BilledInAdvance param.Field[bool] `json:"billed_in_advance"`
BillingCycleConfiguration param.Field[interface{}] `json:"billing_cycle_configuration"`
BpsConfig param.Field[interface{}] `json:"bps_config"`
BulkBpsConfig param.Field[interface{}] `json:"bulk_bps_config"`
BulkConfig param.Field[interface{}] `json:"bulk_config"`
BulkWithProrationConfig param.Field[interface{}] `json:"bulk_with_proration_config"`
// The per unit conversion rate of the price currency to the invoicing currency.
ConversionRate param.Field[float64] `json:"conversion_rate"`
// An ISO 4217 currency string, or custom pricing unit identifier, in which this
// price is billed.
Currency param.Field[string] `json:"currency"`
// An alias for the price.
ExternalPriceID param.Field[string] `json:"external_price_id"`
// If the Price represents a fixed cost, this represents the quantity of units
// applied.
FixedPriceQuantity param.Field[float64] `json:"fixed_price_quantity"`
GroupedAllocationConfig param.Field[interface{}] `json:"grouped_allocation_config"`
GroupedTieredPackageConfig param.Field[interface{}] `json:"grouped_tiered_package_config"`
GroupedWithMeteredMinimumConfig param.Field[interface{}] `json:"grouped_with_metered_minimum_config"`
GroupedWithProratedMinimumConfig param.Field[interface{}] `json:"grouped_with_prorated_minimum_config"`
// The property used to group this price on an invoice
InvoiceGroupingKey param.Field[string] `json:"invoice_grouping_key"`
InvoicingCycleConfiguration param.Field[interface{}] `json:"invoicing_cycle_configuration"`
MatrixConfig param.Field[interface{}] `json:"matrix_config"`
MatrixWithDisplayNameConfig param.Field[interface{}] `json:"matrix_with_display_name_config"`
Metadata param.Field[interface{}] `json:"metadata"`
PackageConfig param.Field[interface{}] `json:"package_config"`
PackageWithAllocationConfig param.Field[interface{}] `json:"package_with_allocation_config"`
ThresholdTotalAmountConfig param.Field[interface{}] `json:"threshold_total_amount_config"`
TieredBpsConfig param.Field[interface{}] `json:"tiered_bps_config"`
TieredConfig param.Field[interface{}] `json:"tiered_config"`
TieredPackageConfig param.Field[interface{}] `json:"tiered_package_config"`
TieredWithMinimumConfig param.Field[interface{}] `json:"tiered_with_minimum_config"`
TieredWithProrationConfig param.Field[interface{}] `json:"tiered_with_proration_config"`
UnitConfig param.Field[interface{}] `json:"unit_config"`
UnitWithPercentConfig param.Field[interface{}] `json:"unit_with_percent_config"`
UnitWithProrationConfig param.Field[interface{}] `json:"unit_with_proration_config"`
}
func (r PlanNewParamsPrice) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r PlanNewParamsPrice) implementsPlanNewParamsPriceUnion() {}
// Satisfied by [PlanNewParamsPricesNewPlanUnitPrice],
// [PlanNewParamsPricesNewPlanPackagePrice],
// [PlanNewParamsPricesNewPlanMatrixPrice],
// [PlanNewParamsPricesNewPlanTieredPrice],
// [PlanNewParamsPricesNewPlanTieredBpsPrice],
// [PlanNewParamsPricesNewPlanBpsPrice], [PlanNewParamsPricesNewPlanBulkBpsPrice],
// [PlanNewParamsPricesNewPlanBulkPrice],
// [PlanNewParamsPricesNewPlanThresholdTotalAmountPrice],
// [PlanNewParamsPricesNewPlanTieredPackagePrice],
// [PlanNewParamsPricesNewPlanTieredWithMinimumPrice],
// [PlanNewParamsPricesNewPlanUnitWithPercentPrice],