billing

package
v0.50.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SupportEmail    = "support@rilldata.com"
	DefaultTimeZone = "UTC"
)

Variables

View Source
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
	GetDefaultPlan(ctx context.Context) (*Plan, error)
	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)

	// 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

	// 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

	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
}

func NewNoop

func NewNoop() Biller

func NewOrb

func NewOrb(logger *zap.Logger, orbKey, webhookSecret string) Biller

type Customer added in v0.48.0

type Customer struct {
	ID                string
	Email             string
	Name              string
	PaymentProviderID string
	PortalURL         string
}

type Invoice added in v0.50.0

type Invoice struct {
	ID             string
	Status         string
	CustomerID     string
	Amount         string
	Currency       string
	DueDate        time.Time
	CreatedAt      time.Time
	SubscriptionID string
	Metadata       map[string]interface{}
}

type Orb

type Orb struct {
	// contains filtered or unexported fields
}

func (*Orb) CancelSubscriptionsForCustomer

func (o *Orb) CancelSubscriptionsForCustomer(ctx context.Context, customerID string, cancelOption SubscriptionCancellationOption) (time.Time, error)

func (*Orb) ChangeSubscriptionPlan

func (o *Orb) ChangeSubscriptionPlan(ctx context.Context, subscriptionID string, plan *Plan) (*Subscription, error)

func (*Orb) CreateCustomer

func (o *Orb) CreateCustomer(ctx context.Context, organization *database.Organization, provider PaymentProvider) (*Customer, error)

func (*Orb) CreateSubscription

func (o *Orb) CreateSubscription(ctx context.Context, customerID string, plan *Plan) (*Subscription, error)

func (*Orb) FindCustomer added in v0.48.0

func (o *Orb) FindCustomer(ctx context.Context, customerID string) (*Customer, error)

func (*Orb) GetActiveSubscription added in v0.50.0

func (o *Orb) GetActiveSubscription(ctx context.Context, customerID string) (*Subscription, error)

func (*Orb) GetDefaultPlan

func (o *Orb) GetDefaultPlan(ctx context.Context) (*Plan, error)

func (*Orb) GetInvoice added in v0.50.0

func (o *Orb) GetInvoice(ctx context.Context, invoiceID string) (*Invoice, error)

func (*Orb) GetPlan

func (o *Orb) GetPlan(ctx context.Context, id string) (*Plan, error)

func (*Orb) GetPlanByName

func (o *Orb) GetPlanByName(ctx context.Context, name string) (*Plan, error)

func (*Orb) GetPlans

func (o *Orb) GetPlans(ctx context.Context) ([]*Plan, error)

func (*Orb) GetPublicPlans

func (o *Orb) GetPublicPlans(ctx context.Context) ([]*Plan, error)

func (*Orb) GetReportingGranularity

func (o *Orb) GetReportingGranularity() UsageReportingGranularity

func (*Orb) GetReportingWorkerCron

func (o *Orb) GetReportingWorkerCron() string

func (*Orb) IsInvoicePaid added in v0.50.0

func (o *Orb) IsInvoicePaid(ctx context.Context, invoice *Invoice) bool

func (*Orb) IsInvoiceValid added in v0.50.0

func (o *Orb) IsInvoiceValid(ctx context.Context, invoice *Invoice) bool

func (*Orb) Name

func (o *Orb) Name() string

func (*Orb) ReportUsage

func (o *Orb) ReportUsage(ctx context.Context, usage []*Usage) error

func (*Orb) UnscheduleCancellation added in v0.50.0

func (o *Orb) UnscheduleCancellation(ctx context.Context, subscriptionID string) (*Subscription, error)

func (*Orb) UpdateCustomerEmail added in v0.49.0

func (o *Orb) UpdateCustomerEmail(ctx context.Context, customerID, email string) error

func (*Orb) UpdateCustomerPaymentID added in v0.48.0

func (o *Orb) UpdateCustomerPaymentID(ctx context.Context, customerID string, provider PaymentProvider, paymentProviderID string) error

func (*Orb) WebhookHandlerFunc added in v0.50.0

func (o *Orb) WebhookHandlerFunc(ctx context.Context, jc jobs.Client) httputil.Handler

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
	DisplayName     string
	Description     string
	TrialPeriodDays int
	Default         bool
	Public          bool
	Quotas          Quotas
	Metadata        map[string]string
}

type Quotas

type Quotas struct {
	StorageLimitBytesPerDeployment *int64

	// Existing quotas
	NumProjects           *int
	NumDeployments        *int
	NumSlotsTotal         *int
	NumSlotsPerDeployment *int
	NumOutstandingInvites *int
}

type Subscription

type Subscription struct {
	ID                           string
	Customer                     *Customer
	Plan                         *Plan
	StartDate                    time.Time
	EndDate                      time.Time
	CurrentBillingCycleStartDate time.Time
	CurrentBillingCycleEndDate   time.Time
	TrialEndDate                 time.Time
	Metadata                     map[string]string
}

type SubscriptionCancellationOption

type SubscriptionCancellationOption int
const (
	SubscriptionCancellationOptionEndOfSubscriptionTerm SubscriptionCancellationOption = iota
	SubscriptionCancellationOptionImmediate
)

type Usage

type Usage struct {
	CustomerID     string
	MetricName     string
	Value          float64
	ReportingGrain UsageReportingGranularity
	StartTime      time.Time // Start time of the usage period
	EndTime        time.Time // End time of the usage period
	Metadata       map[string]interface{}
}

type UsageReportingGranularity

type UsageReportingGranularity string
const (
	UsageReportingGranularityNone UsageReportingGranularity = ""
	UsageReportingGranularityHour UsageReportingGranularity = "hour"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL