File size: 11,806 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 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | // Code generated by @openmeter/typespec-go. DO NOT EDIT.
package openmeter
import (
"encoding/json"
"fmt"
"time"
)
// Subscription.
type BillingSubscription struct {
ID string `json:"id"`
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 customer ID of the subscription.
CustomerID string `json:"customer_id"`
// The plan ID of the subscription. Set if subscription is created from a plan.
PlanID *string `json:"plan_id,omitempty"`
// A billing anchor is the fixed point in time that determines the subscription's
// recurring billing cycle. It affects when charges occur and how prorations are
// calculated. Common anchors:
//
// - Calendar month (1st of each month): `2025-01-01T00:00:00Z`
// - Subscription anniversary (day customer signed up)
// - Custom date (customer-specified day)
BillingAnchor time.Time `json:"billing_anchor"`
// The status of the subscription.
Status SubscriptionStatus `json:"status"`
// Settlement mode for billing.
//
// Values:
//
// - `credit_then_invoice`: Credits are applied first, then any remainder is
// invoiced.
// - `credit_only`: Usage is settled exclusively against credits.
SettlementMode *SettlementMode `json:"settlement_mode,omitempty"`
}
// SubscriptionAddon create request.
type CreateSubscriptionAddonRequest struct {
Labels *map[string]string `json:"labels,omitempty"`
// The add-on associated with the subscription.
Addon AddonReference `json:"addon"`
// The quantity of the add-on. Always 1 for single instance add-ons.
Quantity int64 `json:"quantity"`
// The timing of the operation. After the create or update, a new entry will be
// created in the timeline.
Timing SubscriptionEditTiming `json:"timing"`
}
// Addon purchased with a subscription.
type SubscriptionAddon struct {
ID string `json:"id"`
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"`
// 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"`
// The add-on associated with the subscription.
Addon AddonReference `json:"addon"`
// The quantity of the add-on. Always 1 for single instance add-ons.
Quantity int64 `json:"quantity"`
// An ISO-8601 timestamp representation of which point in time the quantity was
// resolved to.
QuantityAt time.Time `json:"quantity_at"`
// An ISO-8601 timestamp representation of the cadence start of the resource.
ActiveFrom time.Time `json:"active_from"`
// An ISO-8601 timestamp representation of the cadence end of the resource.
ActiveTo *time.Time `json:"active_to,omitempty"`
// The timeline of the add-on. The returned periods are sorted and continuous.
Timeline []SubscriptionAddonTimelineSegment `json:"timeline"`
// The rate cards of the add-on.
RateCards []SubscriptionAddonRateCard `json:"rate_cards"`
}
// Page paginated response.
type SubscriptionAddonPagePaginatedResponse struct {
Data []SubscriptionAddon `json:"data"`
Meta PaginatedMeta `json:"meta"`
}
// A rate card for a subscription add-on.
type SubscriptionAddonRateCard struct {
// The rate card.
RateCard RateCard `json:"rate_card"`
// The IDs of the subscription items that this rate card belongs to.
AffectedSubscriptionItemIds []string `json:"affected_subscription_item_ids"`
}
// A subscription add-on event.
type SubscriptionAddonTimelineSegment struct {
// An ISO-8601 timestamp representation of the cadence start of the resource.
ActiveFrom time.Time `json:"active_from"`
// An ISO-8601 timestamp representation of the cadence end of the resource.
ActiveTo *time.Time `json:"active_to,omitempty"`
// The quantity of the add-on for the given period.
Quantity int64 `json:"quantity"`
}
// Request for canceling a subscription.
type SubscriptionCancel struct {
// If not provided the subscription is canceled immediately.
Timing *SubscriptionEditTiming `json:"timing,omitempty"`
}
// Request for changing a subscription.
type SubscriptionChange struct {
Labels *map[string]string `json:"labels,omitempty"`
// Settlement mode for billing.
//
// Values:
//
// - `credit_then_invoice`: Credits are applied first, then any remainder is
// invoiced.
// - `credit_only`: Usage is settled exclusively against credits.
SettlementMode *SettlementMode `json:"settlement_mode,omitempty"`
// The customer to create the subscription for.
Customer SubscriptionChangeCustomer `json:"customer"`
// The plan reference of the subscription.
Plan SubscriptionChangePlan `json:"plan"`
// A billing anchor is the fixed point in time that determines the subscription's
// recurring billing cycle. It affects when charges occur and how prorations are
// calculated. Common anchors:
//
// - Calendar month (1st of each month): `2025-01-01T00:00:00Z`
// - Subscription anniversary (day customer signed up)
// - Custom date (customer-specified day)
//
// If not provided, the subscription will be created with the subscription's
// creation time as the billing anchor.
BillingAnchor *time.Time `json:"billing_anchor,omitempty"`
// Timing configuration for the change, when the change should take effect. For
// changing a subscription, the accepted values depend on the subscription
// configuration.
Timing SubscriptionEditTiming `json:"timing"`
}
type SubscriptionChangeCustomer struct {
// The ID of the customer to create the subscription for.
//
// Either customer ID or customer key must be provided. If both are provided, the
// ID will be used.
ID *string `json:"id,omitempty"`
// The key of the customer to create the subscription for.
//
// Either customer ID or customer key must be provided. If both are provided, the
// ID will be used.
Key *string `json:"key,omitempty"`
}
type SubscriptionChangePlan struct {
// The plan ID of the subscription. Set if subscription is created from a plan.
//
// ID or Key of the plan is required if creating a subscription from a plan. If
// both are provided, the ID will be used.
ID *string `json:"id,omitempty"`
// The plan Key of the subscription, if any. Set if subscription is created from a
// plan.
//
// ID or Key of the plan is required if creating a subscription from a plan. If
// both are provided, the ID will be used.
Key *string `json:"key,omitempty"`
// The plan version of the subscription, if any. If not provided, the latest
// version of the plan will be used.
Version *int64 `json:"version,omitempty"`
}
// Response for changing a subscription.
type SubscriptionChangeResponse struct {
// The current subscription before the change.
Current BillingSubscription `json:"current"`
// The new state of the subscription after the change.
Next BillingSubscription `json:"next"`
}
// Subscription create request.
type SubscriptionCreate struct {
Labels *map[string]string `json:"labels,omitempty"`
// Settlement mode for billing.
//
// Values:
//
// - `credit_then_invoice`: Credits are applied first, then any remainder is
// invoiced.
// - `credit_only`: Usage is settled exclusively against credits.
SettlementMode *SettlementMode `json:"settlement_mode,omitempty"`
// The customer to create the subscription for.
Customer SubscriptionChangeCustomer `json:"customer"`
// The plan reference of the subscription.
Plan SubscriptionChangePlan `json:"plan"`
// A billing anchor is the fixed point in time that determines the subscription's
// recurring billing cycle. It affects when charges occur and how prorations are
// calculated. Common anchors:
//
// - Calendar month (1st of each month): `2025-01-01T00:00:00Z`
// - Subscription anniversary (day customer signed up)
// - Custom date (customer-specified day)
//
// If not provided, the subscription will be created with the subscription's
// creation time as the billing anchor.
BillingAnchor *time.Time `json:"billing_anchor,omitempty"`
}
// Subscription edit timing defined when the changes should take effect. If the
// provided configuration is not supported by the subscription, an error will be
// returned.
//
// SubscriptionEditTiming is a JSON-preserving tagged union: its zero value marshals as JSON null, and values must be built with the SubscriptionEditTimingFrom* constructors.
type SubscriptionEditTiming struct {
raw json.RawMessage
}
func (u *SubscriptionEditTiming) UnmarshalJSON(data []byte) error {
u.raw = append([]byte(nil), data...)
return nil
}
func (u SubscriptionEditTiming) MarshalJSON() ([]byte, error) {
if len(u.raw) == 0 {
return []byte("null"), nil
}
return append([]byte(nil), u.raw...), nil
}
func (u SubscriptionEditTiming) AsEnum() (*SubscriptionEditTimingEnum, error) {
var value SubscriptionEditTimingEnum
if err := json.Unmarshal(u.raw, &value); err != nil {
return nil, err
}
if !value.Valid() {
return nil, fmt.Errorf("SubscriptionEditTiming: value %q is not Enum", value)
}
return &value, nil
}
func SubscriptionEditTimingFromEnum(value SubscriptionEditTimingEnum) (SubscriptionEditTiming, error) {
raw, err := json.Marshal(value)
if err != nil {
return SubscriptionEditTiming{}, err
}
var result SubscriptionEditTiming
if err := result.UnmarshalJSON(raw); err != nil {
return SubscriptionEditTiming{}, err
}
return result, nil
}
func (u SubscriptionEditTiming) AsCustom() (*time.Time, error) {
var value time.Time
if err := json.Unmarshal(u.raw, &value); err != nil {
return nil, err
}
return &value, nil
}
func SubscriptionEditTimingFromCustom(value time.Time) (SubscriptionEditTiming, error) {
raw, err := json.Marshal(value)
if err != nil {
return SubscriptionEditTiming{}, err
}
var result SubscriptionEditTiming
if err := result.UnmarshalJSON(raw); err != nil {
return SubscriptionEditTiming{}, err
}
return result, nil
}
// Subscription edit timing. When immediate, the requested changes take effect
// immediately. When next_billing_cycle, the requested changes take effect at the
// next billing cycle.
type SubscriptionEditTimingEnum string
const (
SubscriptionEditTimingEnumImmediate SubscriptionEditTimingEnum = "immediate"
SubscriptionEditTimingEnumNextBillingCycle SubscriptionEditTimingEnum = "next_billing_cycle"
)
func (value SubscriptionEditTimingEnum) Valid() bool {
switch value {
case SubscriptionEditTimingEnumImmediate, SubscriptionEditTimingEnumNextBillingCycle:
return true
default:
return false
}
}
// Page paginated response.
type SubscriptionPagePaginatedResponse struct {
Data []BillingSubscription `json:"data"`
Meta PaginatedMeta `json:"meta"`
}
// Subscription status.
type SubscriptionStatus string
const (
SubscriptionStatusActive SubscriptionStatus = "active"
SubscriptionStatusInactive SubscriptionStatus = "inactive"
SubscriptionStatusCanceled SubscriptionStatus = "canceled"
SubscriptionStatusScheduled SubscriptionStatus = "scheduled"
)
func (value SubscriptionStatus) Valid() bool {
switch value {
case SubscriptionStatusActive, SubscriptionStatusInactive, SubscriptionStatusCanceled, SubscriptionStatusScheduled:
return true
default:
return false
}
}
|