billing.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. type ListCreditGrantsRequest struct {
  55. // An array of credit type IDs. This must not be specified if
  56. // credit_grant_ids is specified.
  57. CreditTypeIDs []uuid.UUID `json:"credit_type_ids,omitempty"`
  58. // An array of Metronome customer IDs. This must not be specified if
  59. // credit_grant_ids is specified.
  60. CustomerIDs []uuid.UUID `json:"customer_ids,omitempty"`
  61. // An array of credit grant IDs. If this is specified, neither
  62. // credit_type_ids nor customer_ids may be specified.
  63. CreditGrantIDs []uuid.UUID `json:"credit_grant_ids,omitempty"`
  64. // Only return credit grants that expire at or after this RFC 3339 timestamp.
  65. NotExpiringBefore string `json:"not_expiring_before,omitempty"`
  66. // Only return credit grants that are effective before this RFC 3339 timestamp
  67. // (exclusive).
  68. EffectiveBefore string `json:"effective_before,omitempty"`
  69. }
  70. type ListCreditGrantsResponse struct {
  71. Data []CreditGrant `json:"data"`
  72. }
  73. type CreditType struct {
  74. Name string `json:"name"` // The name of the credit type
  75. ID string `json:"id"` // The UUID of the credit type
  76. }
  77. type GrantAmount struct {
  78. Amount int64 `json:"amount"` // The amount of credits granted
  79. CreditType CreditType `json:"credit_type"` // The credit type for the amount granted
  80. }
  81. // Balance represents the effective balance of the grant as of the end of the customer's
  82. // current billing period.
  83. type Balance struct {
  84. ExcludingPending int64 `json:"excluding_pending"` // The grant's current balance excluding all pending deductions.
  85. IncludingPending int64 `json:"including_pending"` // The grant's current balance including all posted and pending deductions.
  86. EffectiveAt string `json:"effective_at"` // The end date of the customer's current billing period in RFC 3339 format.
  87. }
  88. type CreditGrant struct {
  89. ID uuid.UUID `json:"id"`
  90. Name string
  91. CustomerID uuid.UUID
  92. GrantAmount GrantAmount
  93. Balance Balance
  94. }