2
0

billing.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package types
  2. import (
  3. "github.com/google/uuid"
  4. )
  5. // Stripe types
  6. // PaymentMethod is a subset of the Stripe PaymentMethod type,
  7. // with only the fields used in the dashboard
  8. type PaymentMethod = struct {
  9. ID string `json:"id"`
  10. DisplayBrand string `json:"display_brand"`
  11. Last4 string `json:"last4"`
  12. ExpMonth int64 `json:"exp_month"`
  13. ExpYear int64 `json:"exp_year"`
  14. Default bool `json:"is_default"`
  15. }
  16. // Metronome Types
  17. // Customer represents a customer in Metronome
  18. type Customer struct {
  19. ID uuid.UUID `json:"id"`
  20. Name string `json:"name"` // Required. Name of the customer
  21. Aliases []string `json:"ingest_aliases"` // Aliases that can be used to refer to this customer in usage events
  22. BillingConfig BillingConfig `json:"billing_config,omitempty"`
  23. CustomFields map[string]string `json:"custom_fields,omitempty"`
  24. }
  25. // CustomerArchiveRequest will archive the customer in Metronome.
  26. type CustomerArchiveRequest struct {
  27. CustomerID uuid.UUID `json:"id"`
  28. }
  29. // BillingConfig is the configuration for the billing provider (Stripe, etc.)
  30. type BillingConfig struct {
  31. BillingProviderType string `json:"billing_provider_type"` // Required. Can be any of "aws_marketplace", "stripe", "netsuite", "custom", "azure_marketplace", "quickbooks_online", or "workday"
  32. BillingProviderCustomerID string `json:"billing_provider_customer_id"`
  33. StripeCollectionMethod string `json:"stripe_collection_method"` // Can be any of "charge_automatically" or "send_invoice"
  34. }
  35. // AddCustomerPlanRequest represents a request to add a customer plan with specific details.
  36. type AddCustomerPlanRequest struct {
  37. PlanID uuid.UUID `json:"plan_id"` // Required. The customer ID, plan ID, and date range for the plan to be applied.
  38. StartingOn string `json:"starting_on"` // Required. RFC 3339 timestamp for when the plan becomes active for this customer. Must be at 0:00 UTC (midnight).
  39. EndingBefore string `json:"ending_before,omitempty"` // Optional. RFC 3339 timestamp for when the plan ends (exclusive) for this customer. Must be at 0:00 UTC (midnight).
  40. NetPaymentTermsDays int `json:"net_payment_terms_days,omitempty"` // Number of days after issuance of invoice after which the invoice is due (e.g., Net 30).
  41. }
  42. // AddCustomerPlanResponse is a response to the add customer plan request. Returns customer-plan relationship id.
  43. type AddCustomerPlanResponse struct {
  44. Data struct {
  45. CustomerPlanID uuid.UUID `json:"id"`
  46. } `json:"data"`
  47. }
  48. // EndCustomerPlanRequest represents a request to end the plan for a specific customer.
  49. type EndCustomerPlanRequest struct {
  50. EndingBefore string `json:"ending_before,omitempty"` // RFC 3339 timestamp for when the plan ends (exclusive) for this customer. Must be at 0:00 UTC (midnight).
  51. VoidInvoices bool `json:"void_invoices"` // If true, plan end date can be before the last finalized invoice date. Any invoices generated after the plan end date will be voided.
  52. VoidStripeInvoices bool `json:"void_stripe_invoices"` // Will void Stripe invoices if VoidInvoices is set to true. Drafts will be deleted.
  53. }
  54. // ListCreditGrantsRequest is the request to list a user's credit grants
  55. type ListCreditGrantsRequest struct {
  56. // An array of credit type IDs. This must not be specified if
  57. // credit_grant_ids is specified.
  58. CreditTypeIDs []uuid.UUID `json:"credit_type_ids,omitempty"`
  59. // An array of Metronome customer IDs. This must not be specified if
  60. // credit_grant_ids is specified.
  61. CustomerIDs []uuid.UUID `json:"customer_ids,omitempty"`
  62. // An array of credit grant IDs. If this is specified, neither
  63. // credit_type_ids nor customer_ids may be specified.
  64. CreditGrantIDs []uuid.UUID `json:"credit_grant_ids,omitempty"`
  65. // Only return credit grants that expire at or after this RFC 3339 timestamp.
  66. NotExpiringBefore string `json:"not_expiring_before,omitempty"`
  67. // Only return credit grants that are effective before this RFC 3339 timestamp
  68. // (exclusive).
  69. EffectiveBefore string `json:"effective_before,omitempty"`
  70. }
  71. // ListCreditGrantsResponse is the response returned by the list credit grants request
  72. type ListCreditGrantsResponse struct {
  73. Data []CreditGrant `json:"data"`
  74. }
  75. // CreditType is the type of the credit used in the credit grant
  76. type CreditType struct {
  77. Name string `json:"name"` // The name of the credit type
  78. ID string `json:"id"` // The UUID of the credit type
  79. }
  80. // GrantAmount represents the amount of credits granted
  81. type GrantAmount struct {
  82. Amount int64 `json:"amount"` // The amount of credits granted
  83. CreditType CreditType `json:"credit_type"` // The credit type for the amount granted
  84. }
  85. // Balance represents the effective balance of the grant as of the end of the customer's
  86. // current billing period.
  87. type Balance struct {
  88. ExcludingPending int64 `json:"excluding_pending"` // The grant's current balance excluding all pending deductions.
  89. IncludingPending int64 `json:"including_pending"` // The grant's current balance including all posted and pending deductions.
  90. EffectiveAt string `json:"effective_at"` // The end date of the customer's current billing period in RFC 3339 format.
  91. }
  92. // CreditGrant is a grant given to a specific user on a specific plan
  93. type CreditGrant struct {
  94. ID uuid.UUID `json:"id"`
  95. Name string
  96. CustomerID uuid.UUID
  97. GrantAmount GrantAmount
  98. Balance Balance
  99. }