File size: 11,389 Bytes
04f1444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
// Code generated by @openmeter/typespec-go. DO NOT EDIT.

package openmeter

import (
	"encoding/json"
	"fmt"
	"time"
)

// BillingCollectionAlignment specifies when the pending line items should be
// collected into an invoice.
type CollectionAlignment string

const (
	CollectionAlignmentSubscription CollectionAlignment = "subscription"
	CollectionAlignmentAnchored     CollectionAlignment = "anchored"
)

func (value CollectionAlignment) Valid() bool {
	switch value {
	case CollectionAlignmentSubscription, CollectionAlignmentAnchored:
		return true
	default:
		return false
	}
}

// BillingProfile create request.
type CreateBillingProfileRequest struct {
	// Display name of the resource.
	//
	// Between 1 and 256 characters.
	Name string `json:"name"`
	// Optional description of the resource.
	//
	// Maximum 1024 characters.
	Description *string            `json:"description,omitempty"`
	Labels      *map[string]string `json:"labels,omitempty"`
	// The name and contact information for the supplier this billing profile
	// represents
	Supplier Party `json:"supplier"`
	// The billing workflow settings for this profile
	Workflow Workflow `json:"workflow"`
	// The applications used by this billing profile.
	Apps ProfileAppReferences `json:"apps"`
	// Whether this is the default profile.
	Default bool `json:"default"`
}

// Party represents a person or business entity.
type Party struct {
	// Unique identifier for the party.
	ID *string `json:"id,omitempty"`
	// An optional unique key of the party.
	Key *string `json:"key,omitempty"`
	// Legal name or representation of the party.
	Name *string `json:"name,omitempty"`
	// The entity's legal identification used for tax purposes. They may have other
	// numbers, but we're only interested in those valid for tax purposes.
	TaxID *PartyTaxIdentity `json:"tax_id,omitempty"`
	// Address for where information should be sent if needed.
	Addresses *PartyAddresses `json:"addresses,omitempty"`
}

// Billing profiles contain the settings for billing and controls invoice
// generation.
type Profile struct {
	ID string `json:"id"`
	// Display name of the resource.
	//
	// Between 1 and 256 characters.
	Name string `json:"name"`
	// Optional description of the resource.
	//
	// Maximum 1024 characters.
	Description *string           `json:"description,omitempty"`
	Labels      map[string]string `json:"labels,omitempty"`
	// An ISO-8601 timestamp representation of entity creation date.
	CreatedAt time.Time `json:"created_at"`
	// An ISO-8601 timestamp representation of entity last update date.
	UpdatedAt time.Time `json:"updated_at"`
	// An ISO-8601 timestamp representation of entity deletion date.
	DeletedAt *time.Time `json:"deleted_at,omitempty"`
	// The name and contact information for the supplier this billing profile
	// represents
	Supplier Party `json:"supplier"`
	// The billing workflow settings for this profile
	Workflow Workflow `json:"workflow"`
	// The applications used by this billing profile.
	Apps ProfileAppReferences `json:"apps"`
	// Whether this is the default profile.
	Default bool `json:"default"`
}

// References to the applications used by a billing profile.
type ProfileAppReferences struct {
	// The tax app used for this workflow.
	Tax AppReference `json:"tax"`
	// The invoicing app used for this workflow.
	Invoicing AppReference `json:"invoicing"`
	// The payment app used for this workflow.
	Payment AppReference `json:"payment"`
}

// Page paginated response.
type ProfilePagePaginatedResponse struct {
	Data []Profile     `json:"data"`
	Meta PaginatedMeta `json:"meta"`
}

// Recurring period with an anchor and an interval.
type RecurringPeriod struct {
	// A date-time anchor to base the recurring period on.
	Anchor time.Time `json:"anchor"`
	// The interval duration in ISO 8601 format.
	Interval string `json:"interval"`
}

// BillingProfile upsert request.
type UpsertBillingProfileRequest struct {
	// Display name of the resource.
	//
	// Between 1 and 256 characters.
	Name string `json:"name"`
	// Optional description of the resource.
	//
	// Maximum 1024 characters.
	Description *string            `json:"description,omitempty"`
	Labels      *map[string]string `json:"labels,omitempty"`
	// The name and contact information for the supplier this billing profile
	// represents
	Supplier Party `json:"supplier"`
	// The billing workflow settings for this profile
	Workflow Workflow `json:"workflow"`
	// Whether this is the default profile.
	Default bool `json:"default"`
}

// Billing workflow settings.
type Workflow struct {
	// The collection settings for this workflow
	Collection *WorkflowCollectionSettings `json:"collection,omitempty"`
	// The invoicing settings for this workflow
	Invoicing *WorkflowInvoicingSettings `json:"invoicing,omitempty"`
	// The payment settings for this workflow
	Payment *WorkflowPaymentSettings `json:"payment,omitempty"`
	// The tax settings for this workflow
	Tax *WorkflowTaxSettings `json:"tax,omitempty"`
}

// The alignment for collecting the pending line items into an invoice.
//
// Defaults to subscription, which means that we are to create a new invoice every
// time the a subscription period starts (for in advance items) or ends (for in
// arrears items).
//
// WorkflowCollectionAlignment is a JSON-preserving tagged union: its zero value marshals as JSON null, and values must be built with the WorkflowCollectionAlignmentFrom* constructors.
// The exported Type field is decode-side metadata; MarshalJSON round-trips the original payload and ignores writes to it.
type WorkflowCollectionAlignment struct {
	Type string `json:"type"`
	raw  json.RawMessage
}

func (u *WorkflowCollectionAlignment) UnmarshalJSON(data []byte) error {
	u.raw = append([]byte(nil), data...)
	if string(data) == "null" {
		u.Type = ""
		return nil
	}

	var envelope struct {
		Value string `json:"type"`
	}
	if err := json.Unmarshal(data, &envelope); err != nil {
		return err
	}
	u.Type = envelope.Value
	return nil
}

func (u WorkflowCollectionAlignment) MarshalJSON() ([]byte, error) {
	if len(u.raw) == 0 {
		return []byte("null"), nil
	}
	return append([]byte(nil), u.raw...), nil
}

func (u WorkflowCollectionAlignment) AsWorkflowCollectionAlignmentSubscription() (*WorkflowCollectionAlignmentSubscription, error) {
	if u.Type != "subscription" {
		return nil, fmt.Errorf("WorkflowCollectionAlignment: expected type %q, got %q", "subscription", u.Type)
	}
	var value WorkflowCollectionAlignmentSubscription
	if err := json.Unmarshal(u.raw, &value); err != nil {
		return nil, err
	}
	return &value, nil
}

func WorkflowCollectionAlignmentFromWorkflowCollectionAlignmentSubscription(value WorkflowCollectionAlignmentSubscription) (WorkflowCollectionAlignment, error) {
	value.Type = "subscription"
	raw, err := json.Marshal(value)
	if err != nil {
		return WorkflowCollectionAlignment{}, err
	}
	var result WorkflowCollectionAlignment
	if err := result.UnmarshalJSON(raw); err != nil {
		return WorkflowCollectionAlignment{}, err
	}
	return result, nil
}

func (u WorkflowCollectionAlignment) AsWorkflowCollectionAlignmentAnchored() (*WorkflowCollectionAlignmentAnchored, error) {
	if u.Type != "anchored" {
		return nil, fmt.Errorf("WorkflowCollectionAlignment: expected type %q, got %q", "anchored", u.Type)
	}
	var value WorkflowCollectionAlignmentAnchored
	if err := json.Unmarshal(u.raw, &value); err != nil {
		return nil, err
	}
	return &value, nil
}

func WorkflowCollectionAlignmentFromWorkflowCollectionAlignmentAnchored(value WorkflowCollectionAlignmentAnchored) (WorkflowCollectionAlignment, error) {
	value.Type = "anchored"
	raw, err := json.Marshal(value)
	if err != nil {
		return WorkflowCollectionAlignment{}, err
	}
	var result WorkflowCollectionAlignment
	if err := result.UnmarshalJSON(raw); err != nil {
		return WorkflowCollectionAlignment{}, err
	}
	return result, nil
}

// BillingWorkflowCollectionAlignmentAnchored specifies the alignment for
// collecting the pending line items into an invoice.
type WorkflowCollectionAlignmentAnchored struct {
	// The type of alignment.
	Type CollectionAlignment `json:"type"`
	// The recurring period for the alignment.
	RecurringPeriod RecurringPeriod `json:"recurring_period"`
}

// BillingWorkflowCollectionAlignmentSubscription specifies the alignment for
// collecting the pending line items into an invoice.
type WorkflowCollectionAlignmentSubscription struct {
	// The type of alignment.
	Type CollectionAlignment `json:"type"`
}

// Workflow collection specifies how to collect the pending line items for an
// invoice.
type WorkflowCollectionSettings struct {
	// The alignment for collecting the pending line items into an invoice.
	Alignment *WorkflowCollectionAlignment `json:"alignment,omitempty"`
	// This grace period can be used to delay the collection of the pending line items
	// specified in alignment.
	//
	// This is useful, in case of multiple subscriptions having slightly different
	// billing periods.
	Interval *string `json:"interval,omitempty"`
}

// Invoice settings for a billing workflow.
type WorkflowInvoicingSettings struct {
	// Whether to automatically issue the invoice after the draftPeriod has passed.
	AutoAdvance *bool `json:"auto_advance,omitempty"`
	// The period for the invoice to be kept in draft status for manual reviews.
	DraftPeriod *string `json:"draft_period,omitempty"`
	// Should progressive billing be allowed for this workflow?
	ProgressiveBilling *bool `json:"progressive_billing,omitempty"`
	// Controls how subscription-ending shortened service periods are billed.
	SubscriptionEndProrationMode *WorkflowInvoicingSubscriptionEndProrationMode `json:"subscription_end_proration_mode,omitempty"`
}

// Billing workflow subscription end proration mode.
type WorkflowInvoicingSubscriptionEndProrationMode string

const (
	WorkflowInvoicingSubscriptionEndProrationModeBillFullPeriod   WorkflowInvoicingSubscriptionEndProrationMode = "bill_full_period"
	WorkflowInvoicingSubscriptionEndProrationModeBillActualPeriod WorkflowInvoicingSubscriptionEndProrationMode = "bill_actual_period"
)

func (value WorkflowInvoicingSubscriptionEndProrationMode) Valid() bool {
	switch value {
	case WorkflowInvoicingSubscriptionEndProrationModeBillFullPeriod, WorkflowInvoicingSubscriptionEndProrationModeBillActualPeriod:
		return true
	default:
		return false
	}
}

// Tax settings for a billing workflow.
type WorkflowTaxSettings struct {
	// Enable automatic tax calculation when tax is supported by the app. For example,
	// with Stripe Invoicing when enabled, tax is calculated via Stripe Tax.
	Enabled *bool `json:"enabled,omitempty"`
	// Enforce tax calculation when tax is supported by the app. When enabled, the
	// billing system will not allow to create an invoice without tax calculation.
	// Enforcement is different per apps, for example, Stripe app requires customer to
	// have a tax location when starting a paid subscription.
	Enforced *bool `json:"enforced,omitempty"`
	// Default tax configuration to apply to the invoices for line items.
	//
	// Setting a tax code (`stripe.code` / `taxCodeId`) on a profile's default tax
	// config is deprecated and can no longer be added or changed: the organization
	// default tax code is used instead. Existing tax-code values may still be removed,
	// and `behavior` remains fully supported.
	DefaultTaxConfig *TaxConfig `json:"default_tax_config,omitempty"`
}