billing.go 5.4 KB

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