| |
|
|
| package openmeter |
|
|
| import ( |
| "encoding/json" |
| "fmt" |
| "time" |
| ) |
|
|
| |
| |
| |
| |
| type App struct { |
| Type string `json:"type"` |
| raw json.RawMessage |
| } |
|
|
| func (u *App) 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 App) MarshalJSON() ([]byte, error) { |
| if len(u.raw) == 0 { |
| return []byte("null"), nil |
| } |
| return append([]byte(nil), u.raw...), nil |
| } |
|
|
| func (u App) AsAppStripe() (*AppStripe, error) { |
| if u.Type != "stripe" { |
| return nil, fmt.Errorf("App: expected type %q, got %q", "stripe", u.Type) |
| } |
| var value AppStripe |
| if err := json.Unmarshal(u.raw, &value); err != nil { |
| return nil, err |
| } |
| return &value, nil |
| } |
|
|
| func AppFromAppStripe(value AppStripe) (App, error) { |
| value.Type = "stripe" |
| raw, err := json.Marshal(value) |
| if err != nil { |
| return App{}, err |
| } |
| var result App |
| if err := result.UnmarshalJSON(raw); err != nil { |
| return App{}, err |
| } |
| return result, nil |
| } |
|
|
| func (u App) AsAppSandbox() (*AppSandbox, error) { |
| if u.Type != "sandbox" { |
| return nil, fmt.Errorf("App: expected type %q, got %q", "sandbox", u.Type) |
| } |
| var value AppSandbox |
| if err := json.Unmarshal(u.raw, &value); err != nil { |
| return nil, err |
| } |
| return &value, nil |
| } |
|
|
| func AppFromAppSandbox(value AppSandbox) (App, error) { |
| value.Type = "sandbox" |
| raw, err := json.Marshal(value) |
| if err != nil { |
| return App{}, err |
| } |
| var result App |
| if err := result.UnmarshalJSON(raw); err != nil { |
| return App{}, err |
| } |
| return result, nil |
| } |
|
|
| func (u App) AsAppExternalInvoicing() (*AppExternalInvoicing, error) { |
| if u.Type != "external_invoicing" { |
| return nil, fmt.Errorf("App: expected type %q, got %q", "external_invoicing", u.Type) |
| } |
| var value AppExternalInvoicing |
| if err := json.Unmarshal(u.raw, &value); err != nil { |
| return nil, err |
| } |
| return &value, nil |
| } |
|
|
| func AppFromAppExternalInvoicing(value AppExternalInvoicing) (App, error) { |
| value.Type = "external_invoicing" |
| raw, err := json.Marshal(value) |
| if err != nil { |
| return App{}, err |
| } |
| var result App |
| if err := result.UnmarshalJSON(raw); err != nil { |
| return App{}, err |
| } |
| return result, nil |
| } |
|
|
| |
| type AppCapability struct { |
| |
| Type AppCapabilityType `json:"type"` |
| |
| Key string `json:"key"` |
| |
| Name string `json:"name"` |
| |
| Description string `json:"description"` |
| } |
|
|
| |
| |
| |
| type AppCapabilityType string |
|
|
| const ( |
| AppCapabilityTypeReportUsage AppCapabilityType = "report_usage" |
| AppCapabilityTypeReportEvents AppCapabilityType = "report_events" |
| AppCapabilityTypeCalculateTax AppCapabilityType = "calculate_tax" |
| AppCapabilityTypeInvoiceCustomers AppCapabilityType = "invoice_customers" |
| AppCapabilityTypeCollectPayments AppCapabilityType = "collect_payments" |
| ) |
|
|
| func (value AppCapabilityType) Valid() bool { |
| switch value { |
| case AppCapabilityTypeReportUsage, AppCapabilityTypeReportEvents, AppCapabilityTypeCalculateTax, AppCapabilityTypeInvoiceCustomers, AppCapabilityTypeCollectPayments: |
| return true |
| default: |
| return false |
| } |
| } |
|
|
| |
| |
| |
| |
| type AppCatalogItem struct { |
| |
| Type AppType `json:"type"` |
| |
| Name string `json:"name"` |
| |
| Description string `json:"description"` |
| |
| Capabilities []AppCapability `json:"capabilities"` |
| |
| InstallMethods []AppInstallMethods `json:"install_methods"` |
| } |
|
|
| |
| type AppCatalogItemPagePaginatedResponse struct { |
| Data []AppCatalogItem `json:"data"` |
| Meta PaginatedMeta `json:"meta"` |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| type AppExternalInvoicing struct { |
| ID string `json:"id"` |
| |
| |
| |
| Name string `json:"name"` |
| |
| |
| |
| Description *string `json:"description,omitempty"` |
| Labels map[string]string `json:"labels,omitempty"` |
| |
| CreatedAt time.Time `json:"created_at"` |
| |
| UpdatedAt time.Time `json:"updated_at"` |
| |
| DeletedAt *time.Time `json:"deleted_at,omitempty"` |
| |
| Type AppType `json:"type"` |
| |
| Definition AppCatalogItem `json:"definition"` |
| |
| Status AppStatus `json:"status"` |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| EnableDraftSyncHook bool `json:"enable_draft_sync_hook"` |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| EnableIssuingSyncHook bool `json:"enable_issuing_sync_hook"` |
| } |
|
|
| |
| type AppInstallMethods string |
|
|
| const ( |
| AppInstallMethodsWithOAuth2 AppInstallMethods = "with_oauth2" |
| AppInstallMethodsWithAPIKey AppInstallMethods = "with_api_key" |
| AppInstallMethodsNoCredentialsRequired AppInstallMethods = "no_credentials_required" |
| ) |
|
|
| func (value AppInstallMethods) Valid() bool { |
| switch value { |
| case AppInstallMethodsWithOAuth2, AppInstallMethodsWithAPIKey, AppInstallMethodsNoCredentialsRequired: |
| return true |
| default: |
| return false |
| } |
| } |
|
|
| |
| type AppPagePaginatedResponse struct { |
| Data []App `json:"data"` |
| Meta PaginatedMeta `json:"meta"` |
| } |
|
|
| |
| type AppSandbox struct { |
| ID string `json:"id"` |
| |
| |
| |
| Name string `json:"name"` |
| |
| |
| |
| Description *string `json:"description,omitempty"` |
| Labels map[string]string `json:"labels,omitempty"` |
| |
| CreatedAt time.Time `json:"created_at"` |
| |
| UpdatedAt time.Time `json:"updated_at"` |
| |
| DeletedAt *time.Time `json:"deleted_at,omitempty"` |
| |
| Type AppType `json:"type"` |
| |
| Definition AppCatalogItem `json:"definition"` |
| |
| Status AppStatus `json:"status"` |
| } |
|
|
| |
| type AppStatus string |
|
|
| const ( |
| AppStatusReady AppStatus = "ready" |
| AppStatusUnauthorized AppStatus = "unauthorized" |
| ) |
|
|
| func (value AppStatus) Valid() bool { |
| switch value { |
| case AppStatusReady, AppStatusUnauthorized: |
| return true |
| default: |
| return false |
| } |
| } |
|
|
| |
| type AppStripe struct { |
| ID string `json:"id"` |
| |
| |
| |
| Name string `json:"name"` |
| |
| |
| |
| Description *string `json:"description,omitempty"` |
| Labels map[string]string `json:"labels,omitempty"` |
| |
| CreatedAt time.Time `json:"created_at"` |
| |
| UpdatedAt time.Time `json:"updated_at"` |
| |
| DeletedAt *time.Time `json:"deleted_at,omitempty"` |
| |
| Type AppType `json:"type"` |
| |
| Definition AppCatalogItem `json:"definition"` |
| |
| Status AppStatus `json:"status"` |
| |
| AccountID string `json:"account_id"` |
| |
| Livemode bool `json:"livemode"` |
| |
| MaskedAPIKey string `json:"masked_api_key"` |
| } |
|
|
| |
| type InstallAppExternalInvoicing struct { |
| |
| Type AppType `json:"type"` |
| |
| Name string `json:"name"` |
| |
| |
| CreateBillingProfile bool `json:"create_billing_profile"` |
| } |
|
|
| |
| |
| |
| |
| type InstallAppRequest struct { |
| Type string `json:"type"` |
| raw json.RawMessage |
| } |
|
|
| func (u *InstallAppRequest) 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 InstallAppRequest) MarshalJSON() ([]byte, error) { |
| if len(u.raw) == 0 { |
| return []byte("null"), nil |
| } |
| return append([]byte(nil), u.raw...), nil |
| } |
|
|
| func (u InstallAppRequest) AsInstallAppStripeWithAPIKey() (*InstallAppStripeWithAPIKey, error) { |
| if u.Type != "stripe" { |
| return nil, fmt.Errorf("InstallAppRequest: expected type %q, got %q", "stripe", u.Type) |
| } |
| var value InstallAppStripeWithAPIKey |
| if err := json.Unmarshal(u.raw, &value); err != nil { |
| return nil, err |
| } |
| return &value, nil |
| } |
|
|
| func InstallAppRequestFromInstallAppStripeWithAPIKey(value InstallAppStripeWithAPIKey) (InstallAppRequest, error) { |
| value.Type = "stripe" |
| raw, err := json.Marshal(value) |
| if err != nil { |
| return InstallAppRequest{}, err |
| } |
| var result InstallAppRequest |
| if err := result.UnmarshalJSON(raw); err != nil { |
| return InstallAppRequest{}, err |
| } |
| return result, nil |
| } |
|
|
| func (u InstallAppRequest) AsInstallAppSandbox() (*InstallAppSandbox, error) { |
| if u.Type != "sandbox" { |
| return nil, fmt.Errorf("InstallAppRequest: expected type %q, got %q", "sandbox", u.Type) |
| } |
| var value InstallAppSandbox |
| if err := json.Unmarshal(u.raw, &value); err != nil { |
| return nil, err |
| } |
| return &value, nil |
| } |
|
|
| func InstallAppRequestFromInstallAppSandbox(value InstallAppSandbox) (InstallAppRequest, error) { |
| value.Type = "sandbox" |
| raw, err := json.Marshal(value) |
| if err != nil { |
| return InstallAppRequest{}, err |
| } |
| var result InstallAppRequest |
| if err := result.UnmarshalJSON(raw); err != nil { |
| return InstallAppRequest{}, err |
| } |
| return result, nil |
| } |
|
|
| func (u InstallAppRequest) AsInstallAppExternalInvoicing() (*InstallAppExternalInvoicing, error) { |
| if u.Type != "external_invoicing" { |
| return nil, fmt.Errorf("InstallAppRequest: expected type %q, got %q", "external_invoicing", u.Type) |
| } |
| var value InstallAppExternalInvoicing |
| if err := json.Unmarshal(u.raw, &value); err != nil { |
| return nil, err |
| } |
| return &value, nil |
| } |
|
|
| func InstallAppRequestFromInstallAppExternalInvoicing(value InstallAppExternalInvoicing) (InstallAppRequest, error) { |
| value.Type = "external_invoicing" |
| raw, err := json.Marshal(value) |
| if err != nil { |
| return InstallAppRequest{}, err |
| } |
| var result InstallAppRequest |
| if err := result.UnmarshalJSON(raw); err != nil { |
| return InstallAppRequest{}, err |
| } |
| return result, nil |
| } |
|
|
| |
| type InstallAppResponse struct { |
| App App `json:"app"` |
| DefaultForCapabilityTypes []AppCapabilityType `json:"default_for_capability_types"` |
| } |
|
|
| |
| type InstallAppSandbox struct { |
| |
| Type AppType `json:"type"` |
| |
| Name string `json:"name"` |
| |
| |
| CreateBillingProfile bool `json:"create_billing_profile"` |
| } |
|
|
| |
| type InstallAppStripeWithAPIKey struct { |
| |
| Type AppType `json:"type"` |
| |
| Name string `json:"name"` |
| |
| |
| CreateBillingProfile bool `json:"create_billing_profile"` |
| |
| APIKey string `json:"api_key"` |
| } |
|
|