Documentation
¶
Index ¶
- Constants
- Variables
- func Email(organization *database.Organization) string
- type Biller
- type Customer
- type Invoice
- type Orb
- func (o *Orb) CancelSubscriptionsForCustomer(ctx context.Context, customerID string, ...) (time.Time, error)
- func (o *Orb) ChangeSubscriptionPlan(ctx context.Context, subscriptionID string, plan *Plan) (*Subscription, error)
- func (o *Orb) CreateCustomer(ctx context.Context, organization *database.Organization, ...) (*Customer, error)
- func (o *Orb) CreateCustomerCreditAlerts(ctx context.Context, customerID, currency string, lowThreshold float64) error
- func (o *Orb) CreateSubscription(ctx context.Context, customerID string, plan *Plan) (*Subscription, error)
- func (o *Orb) DebitCustomerCredits(ctx context.Context, customerID string, amount float64, ...) error
- func (o *Orb) DefaultQuotas() Quotas
- func (o *Orb) DefaultUserQuotas() UserQuotas
- func (o *Orb) DeleteCustomer(ctx context.Context, customerID string) error
- func (o *Orb) FindCustomer(ctx context.Context, customerID string) (*Customer, error)
- func (o *Orb) GetActiveSubscription(ctx context.Context, customerID string) (*Subscription, error)
- func (o *Orb) GetCustomerCreditBalance(ctx context.Context, customerID, currency string) (float64, error)
- func (o *Orb) GetDefaultPlan(ctx context.Context) (*Plan, error)
- func (o *Orb) GetInvoice(ctx context.Context, invoiceID string) (*Invoice, error)
- func (o *Orb) GetPlan(ctx context.Context, id string) (*Plan, error)
- func (o *Orb) GetPlanByName(ctx context.Context, name string) (*Plan, error)
- func (o *Orb) GetPlanByType(ctx context.Context, planType PlanType) (*Plan, error)
- func (o *Orb) GetPlans(ctx context.Context) ([]*Plan, error)
- func (o *Orb) GetPublicPlans(ctx context.Context) ([]*Plan, error)
- func (o *Orb) GetReportingGranularity() UsageReportingGranularity
- func (o *Orb) GetReportingWorkerCron() string
- func (o *Orb) GrantCustomerCredits(ctx context.Context, customerID string, amount float64, ...) error
- func (o *Orb) IsInvoicePaid(ctx context.Context, invoice *Invoice) bool
- func (o *Orb) IsInvoiceValid(ctx context.Context, invoice *Invoice) bool
- func (o *Orb) MarkCustomerTaxExempt(ctx context.Context, customerID string) error
- func (o *Orb) Name() string
- func (o *Orb) ReportUsage(ctx context.Context, usage []*Usage) error
- func (o *Orb) UnmarkCustomerTaxExempt(ctx context.Context, customerID string) error
- func (o *Orb) UnscheduleCancellation(ctx context.Context, subscriptionID string) (*Subscription, error)
- func (o *Orb) UpdateCustomerEmail(ctx context.Context, customerID, email string) error
- func (o *Orb) UpdateCustomerPaymentID(ctx context.Context, customerID string, provider PaymentProvider, ...) error
- func (o *Orb) WebhookHandlerFunc(ctx context.Context, jc jobs.Client) httputil.Handler
- type PaymentProvider
- type Plan
- type PlanType
- type Quotas
- type Subscription
- type SubscriptionCancellationOption
- type Usage
- type UsageReportingGranularity
- type UserQuotas
Constants ¶
const ( SupportEmail = "support@rilldata.com" DefaultTimeZone = "UTC" )
const CreditTrialLowBalanceThreshold = 50
CreditTrialLowBalanceThreshold is the credit balance at which we trigger a warning email.
const CreditsCurrency = "credits"
CreditsCurrency is the pricing-unit used for trial credit balance/alerts/grants. Its a non-monetary custom pricing unit, so trial usage never produces USD invoice line items. 1 credit is equivalent to 1 USD
const USDCurrency = "USD"
USDCurrency is the standard real-world currency used for paid-plan billing and the USD ledger (e.g., where trial `credits` get rolled over on upgrade).
Variables ¶
var ErrCustomerIDRequired = errors.New("customer id is required")
var ErrNotFound = errors.New("not found")
Functions ¶
func Email ¶ added in v0.49.0
func Email(organization *database.Organization) string
Types ¶
type Biller ¶
type Biller interface {
Name() string
// DefaultQuotas returns the default quotas to assign to orgs before billing has been initialized.
DefaultQuotas() Quotas
// DefaultUserQuotas returns the default quotas to assign to users.
DefaultUserQuotas() UserQuotas
// GetDefaultPlan returns the default plan for new organizations.
GetDefaultPlan(ctx context.Context) (*Plan, error)
// GetPlans returns all the plans available in the billing system.
GetPlans(ctx context.Context) ([]*Plan, error)
// GetPublicPlans for listing purposes
GetPublicPlans(ctx context.Context) ([]*Plan, error)
// GetPlan returns the plan with the given biller plan ID.
GetPlan(ctx context.Context, id string) (*Plan, error)
// GetPlanByName returns the plan with the given Rill plan name.
GetPlanByName(ctx context.Context, name string) (*Plan, error)
// GetPlanByType returns the plan with the given PlanType. Returns ErrNotFound if no plan matches.
GetPlanByType(ctx context.Context, planType PlanType) (*Plan, error)
// CreateCustomer creates a customer for the given organization in the billing system and returns the external customer ID.
CreateCustomer(ctx context.Context, organization *database.Organization, provider PaymentProvider) (*Customer, error)
FindCustomer(ctx context.Context, customerID string) (*Customer, error)
UpdateCustomerPaymentID(ctx context.Context, customerID string, provider PaymentProvider, paymentProviderID string) error
UpdateCustomerEmail(ctx context.Context, customerID, email string) error
DeleteCustomer(ctx context.Context, customerID string) error
// CreateCustomerCreditAlerts registers credit-balance alerts for the customer in the given currency.
CreateCustomerCreditAlerts(ctx context.Context, customerID, currency string, lowThreshold float64) error
// GrantCustomerCredits increments credit ledger entry to the customer's balance in the given currency. Description is recorded on the ledger entry; expiryDate may be nil for credits that never expire.
GrantCustomerCredits(ctx context.Context, customerID string, amount float64, currency, description string, expiryDate *time.Time) error
// DebitCustomerCredits posts a `decrement` ledger entry against the customer's balance in the given currency.
DebitCustomerCredits(ctx context.Context, customerID string, amount float64, currency, description string) error
// GetCustomerCreditBalance returns the customer's current credit balance in the given currency.
GetCustomerCreditBalance(ctx context.Context, customerID, currency string) (float64, error)
// CreateSubscription creates a subscription for the given organization. Subscription starts immediately.
CreateSubscription(ctx context.Context, customerID string, plan *Plan) (*Subscription, error)
// GetActiveSubscription returns the active subscription for the given organization
GetActiveSubscription(ctx context.Context, customerID string) (*Subscription, error)
// CancelSubscriptionsForCustomer cancels all the subscriptions for the given organization and returns the end date of the subscription
CancelSubscriptionsForCustomer(ctx context.Context, customerID string, cancelOption SubscriptionCancellationOption) (time.Time, error)
// ChangeSubscriptionPlan changes the plan of the given subscription immediately and returns the updated subscription
ChangeSubscriptionPlan(ctx context.Context, subscriptionID string, plan *Plan) (*Subscription, error)
// UnscheduleCancellation cancels the scheduled cancellation for the given subscription and returns the updated subscription
UnscheduleCancellation(ctx context.Context, subscriptionID string) (*Subscription, error)
GetInvoice(ctx context.Context, invoiceID string) (*Invoice, error)
IsInvoiceValid(ctx context.Context, invoice *Invoice) bool
IsInvoicePaid(ctx context.Context, invoice *Invoice) bool
MarkCustomerTaxExempt(ctx context.Context, customerID string) error
UnmarkCustomerTaxExempt(ctx context.Context, customerID string) error
ReportUsage(ctx context.Context, usage []*Usage) error
GetReportingGranularity() UsageReportingGranularity
GetReportingWorkerCron() string
// WebhookHandlerFunc returns a http.HandlerFunc that can be used to handle incoming webhooks from the payment provider. Return nil if you don't want to register any webhook handlers. jobs is used to enqueue jobs for processing the webhook events.
WebhookHandlerFunc(ctx context.Context, jobs jobs.Client) httputil.Handler
}
type Orb ¶
type Orb struct {
// contains filtered or unexported fields
}
func (*Orb) CancelSubscriptionsForCustomer ¶
func (*Orb) ChangeSubscriptionPlan ¶
func (*Orb) CreateCustomer ¶
func (o *Orb) CreateCustomer(ctx context.Context, organization *database.Organization, provider PaymentProvider) (*Customer, error)
func (*Orb) CreateCustomerCreditAlerts ¶ added in v0.87.0
func (o *Orb) CreateCustomerCreditAlerts(ctx context.Context, customerID, currency string, lowThreshold float64) error
CreateCustomerCreditAlerts registers a credit_balance_dropped alert at the given threshold and a credit_balance_depleted alert for the customer in Orb. Required for Orb to deliver the corresponding webhook events. Idempotent: if the alerts already exist for the customer/currency they are not re-created (Orb throws an error if the alert already exits).
func (*Orb) CreateSubscription ¶
func (*Orb) DebitCustomerCredits ¶ added in v0.87.0
func (o *Orb) DebitCustomerCredits(ctx context.Context, customerID string, amount float64, currency, description string) error
DebitCustomerCredits posts a `decrement` ledger entry against the customer's credit balance in Orb in the given currency. Used to expire/zero out a credit pool, e.g., to roll trial credits over to a different currency on upgrade.
func (*Orb) DefaultQuotas ¶ added in v0.58.0
func (*Orb) DefaultUserQuotas ¶ added in v0.58.0
func (o *Orb) DefaultUserQuotas() UserQuotas
func (*Orb) DeleteCustomer ¶ added in v0.51.0
func (*Orb) FindCustomer ¶ added in v0.48.0
func (*Orb) GetActiveSubscription ¶ added in v0.50.0
func (*Orb) GetCustomerCreditBalance ¶ added in v0.87.0
func (o *Orb) GetCustomerCreditBalance(ctx context.Context, customerID, currency string) (float64, error)
GetCustomerCreditBalance returns the customer's current credit balance in the given currency. Sums active (unexpired) blocks only.
func (*Orb) GetInvoice ¶ added in v0.50.0
func (*Orb) GetPlanByName ¶
func (*Orb) GetPlanByType ¶ added in v0.87.0
func (*Orb) GetReportingGranularity ¶
func (o *Orb) GetReportingGranularity() UsageReportingGranularity
func (*Orb) GetReportingWorkerCron ¶
func (*Orb) GrantCustomerCredits ¶ added in v0.87.0
func (o *Orb) GrantCustomerCredits(ctx context.Context, customerID string, amount float64, currency, description string, expiryDate *time.Time) error
GrantCustomerCredits adds an `increment` ledger entry to the customer's credit balance in Orb in the given currency. per_unit_cost_basis is set to "0.00" so the grant itself does not produce an invoice line item.
func (*Orb) IsInvoicePaid ¶ added in v0.50.0
func (*Orb) IsInvoiceValid ¶ added in v0.50.0
func (*Orb) MarkCustomerTaxExempt ¶ added in v0.51.0
func (*Orb) UnmarkCustomerTaxExempt ¶ added in v0.51.0
func (*Orb) UnscheduleCancellation ¶ added in v0.50.0
func (*Orb) UpdateCustomerEmail ¶ added in v0.49.0
func (*Orb) UpdateCustomerPaymentID ¶ added in v0.48.0
type PaymentProvider ¶ added in v0.48.0
type PaymentProvider string
const (
PaymentProviderStripe PaymentProvider = "stripe"
)
type Plan ¶
type Plan struct {
ID string // ID of the plan in the external billing system
Name string // Unique name of the plan in Rill, can be empty if biller does not support it
PlanType PlanType
DisplayName string
Description string
TrialPeriodDays int
Default bool
Public bool
Quotas Quotas
Metadata map[string]string
}
type Subscription ¶
type SubscriptionCancellationOption ¶
type SubscriptionCancellationOption int
const ( SubscriptionCancellationOptionEndOfSubscriptionTerm SubscriptionCancellationOption = iota SubscriptionCancellationOptionImmediate )
type UsageReportingGranularity ¶
type UsageReportingGranularity string
const ( UsageReportingGranularityNone UsageReportingGranularity = "" UsageReportingGranularityHour UsageReportingGranularity = "hour" )