Documentation
¶
Index ¶
- Constants
- Variables
- type AdminOrderFilter
- type AdminOrderView
- type AdminRepo
- type AdminUsageFunc
- type Auditor
- type BillingAdminService
- func (s *BillingAdminService) AdminCancelPendingOrder(ctx context.Context, actor *webx.Principal, orderID string) error
- func (s *BillingAdminService) AdminCancelSubscription(ctx context.Context, actor *webx.Principal, workspaceID string) error
- func (s *BillingAdminService) BillingConfig(ctx context.Context) (BillingConfigView, error)
- func (s *BillingAdminService) ListAllOrders(ctx context.Context, f AdminOrderFilter, limit, offset int) ([]AdminOrderView, int, error)
- func (s *BillingAdminService) ListPaymentEvents(ctx context.Context, f PaymentEventFilter, limit, offset int) ([]PaymentEventView, int, error)
- func (s *BillingAdminService) ListPlanCodes(ctx context.Context) ([]string, error)
- func (s *BillingAdminService) ListPlanViews(ctx context.Context) ([]PlanView, error)
- func (s *BillingAdminService) MarkOrderPaid(ctx context.Context, actor *webx.Principal, orderID string) error
- func (s *BillingAdminService) RunExpiryNow(ctx context.Context) (int, error)
- func (s *BillingAdminService) RunOverageNow(ctx context.Context) (int, error)
- func (s *BillingAdminService) TestChannelConnection(ctx context.Context, name string) error
- func (s *BillingAdminService) WithUsage(u AdminUsageFunc) *BillingAdminService
- type BillingConfigView
- type BillingHooks
- type BillingService
- func (s *BillingService) AdminCancelSubscription(ctx context.Context, actor *webx.Principal, workspaceID string) error
- func (s *BillingService) BillingConfig(_ context.Context) BillingConfigView
- func (s *BillingService) CancelPendingOrder(ctx context.Context, p *webx.Principal, orderID string) error
- func (s *BillingService) CreateCheckout(ctx context.Context, p *webx.Principal, workspaceID, planCode string, ...) (*domain.CheckoutSession, error)
- func (s *BillingService) CreateOverageOrder(ctx context.Context, workspaceID, period string, items []OverageItem, ...) (domain.Order, bool, error)
- func (s *BillingService) ExpireDueWorkspaces(ctx context.Context, now time.Time, limit int) ([]ExpiredWorkspace, error)
- func (s *BillingService) GetMeter(ctx context.Context, slug string) (Meter, bool, error)
- func (s *BillingService) GetSubscription(ctx context.Context, workspaceID string) (currentPlan string, orders []domain.Order, err error)
- func (s *BillingService) HandleWebhook(ctx context.Context, channelName string, req WebhookRequest) error
- func (s *BillingService) ListMeters(ctx context.Context) ([]Meter, error)
- func (s *BillingService) ListPlanViews(ctx context.Context) ([]PlanView, error)
- func (s *BillingService) ListPlans(ctx context.Context) ([]domain.Plan, error)
- func (s *BillingService) MarkOrderPaid(ctx context.Context, actor *webx.Principal, orderID string) error
- func (s *BillingService) MeterDueOverages(ctx context.Context, now time.Time, ...) ([]domain.Order, error)
- func (s *BillingService) RegisterMeter(ctx context.Context, m Meter) error
- func (s *BillingService) TestChannelConnection(ctx context.Context, name string) error
- func (s *BillingService) UsagePreview(ctx context.Context, workspaceID string, ...) (UsagePreview, error)
- func (s *BillingService) WithEventEmitter(emit EventEmit) *BillingService
- func (s *BillingService) WithMeterRegistry(r MeterRegistry) *BillingService
- type ChannelConfigInfo
- type ChannelConfigView
- type ChannelConfigViewer
- type ChannelRegistry
- type CheckoutCanceller
- type Clock
- type Config
- type ConnectionTester
- type EventEmit
- type ExpiredWorkspace
- type ManualChannel
- type Meter
- type MeterRegistry
- type MeteredWorkspace
- type OverageItem
- type PaymentChannel
- type PaymentEventFilter
- type PaymentEventView
- type PlanView
- type Repo
- type SubscriptionCanceller
- type UsagePreview
- type UsagePreviewItem
- type WebhookRequest
Constants ¶
View Source
const ( CodeChannelNotConfigured = "E_CHANNEL_NOT_CONFIGURED" CodeChannelTestUnsupported = "E_CHANNEL_TEST_UNSUPPORTED" CodeChannelCancelUnsupported = "E_CHANNEL_CANCEL_UNSUPPORTED" )
View Source
const ( KindPaymentFailed = "billing.payment_failed" KindOrderMarkedPaid = "billing.order_marked_paid" )
View Source
const ChannelManual = "manual"
Variables ¶
View Source
var ErrDuplicate = errors.New("duplicate")
View Source
var ErrMeterImmutable = errors.New("meter definition immutable")
Functions ¶
This section is empty.
Types ¶
type AdminOrderFilter ¶
type AdminOrderView ¶
type AdminRepo ¶
type AdminRepo interface {
ListAllOrders(ctx context.Context, f AdminOrderFilter, limit, offset int) ([]AdminOrderView, int, error)
ListPaymentEvents(ctx context.Context, f PaymentEventFilter, limit, offset int) ([]PaymentEventView, int, error)
ListPlanCodes(ctx context.Context) ([]string, error)
}
type AdminUsageFunc ¶
type BillingAdminService ¶
type BillingAdminService struct {
// contains filtered or unexported fields
}
func NewBillingAdminService ¶
func NewBillingAdminService(core *BillingService, adminRepo AdminRepo, now Clock, log *slog.Logger) *BillingAdminService
func (*BillingAdminService) AdminCancelPendingOrder ¶
func (*BillingAdminService) AdminCancelSubscription ¶
func (*BillingAdminService) BillingConfig ¶
func (s *BillingAdminService) BillingConfig(ctx context.Context) (BillingConfigView, error)
func (*BillingAdminService) ListAllOrders ¶
func (s *BillingAdminService) ListAllOrders(ctx context.Context, f AdminOrderFilter, limit, offset int) ([]AdminOrderView, int, error)
func (*BillingAdminService) ListPaymentEvents ¶
func (s *BillingAdminService) ListPaymentEvents(ctx context.Context, f PaymentEventFilter, limit, offset int) ([]PaymentEventView, int, error)
func (*BillingAdminService) ListPlanCodes ¶
func (s *BillingAdminService) ListPlanCodes(ctx context.Context) ([]string, error)
func (*BillingAdminService) ListPlanViews ¶
func (s *BillingAdminService) ListPlanViews(ctx context.Context) ([]PlanView, error)
func (*BillingAdminService) MarkOrderPaid ¶
func (*BillingAdminService) RunExpiryNow ¶
func (s *BillingAdminService) RunExpiryNow(ctx context.Context) (int, error)
func (*BillingAdminService) RunOverageNow ¶
func (s *BillingAdminService) RunOverageNow(ctx context.Context) (int, error)
func (*BillingAdminService) TestChannelConnection ¶
func (s *BillingAdminService) TestChannelConnection(ctx context.Context, name string) error
func (*BillingAdminService) WithUsage ¶
func (s *BillingAdminService) WithUsage(u AdminUsageFunc) *BillingAdminService
type BillingConfigView ¶
type BillingConfigView struct {
Channels []ChannelConfigView `json:"channels"`
}
type BillingHooks ¶
type BillingHooks struct {
BeforeCheckout func(ctx context.Context, workspaceID, userID, planCode string) error
OnPlanChanged func(ctx context.Context, workspaceID, from, to string) error
OnPlanChangedTx func(ctx context.Context, tx pgx.Tx, workspaceID, from, to string) error
OnPaymentFailed func(ctx context.Context, workspaceID, orderID, reason string) error
OnSubscriptionRenewed func(ctx context.Context, workspaceID string, expiresAt time.Time) error
OnMeteredOverage func(ctx context.Context, workspaceID, orderID, period string, items int, amountCents int64) error
}
type BillingService ¶
type BillingService struct {
// contains filtered or unexported fields
}
func NewBillingService ¶
func NewBillingService(repo Repo, channels *ChannelRegistry, cfg Config, hooks BillingHooks, auditor Auditor, now Clock, log *slog.Logger) *BillingService
func (*BillingService) AdminCancelSubscription ¶
func (*BillingService) BillingConfig ¶
func (s *BillingService) BillingConfig(_ context.Context) BillingConfigView
func (*BillingService) CancelPendingOrder ¶
func (*BillingService) CreateCheckout ¶
func (s *BillingService) CreateCheckout(ctx context.Context, p *webx.Principal, workspaceID, planCode string, interval domain.BillingInterval, channelName string) (*domain.CheckoutSession, error)
func (*BillingService) CreateOverageOrder ¶
func (*BillingService) ExpireDueWorkspaces ¶
func (s *BillingService) ExpireDueWorkspaces(ctx context.Context, now time.Time, limit int) ([]ExpiredWorkspace, error)
func (*BillingService) GetSubscription ¶
func (*BillingService) HandleWebhook ¶
func (s *BillingService) HandleWebhook(ctx context.Context, channelName string, req WebhookRequest) error
func (*BillingService) ListMeters ¶
func (s *BillingService) ListMeters(ctx context.Context) ([]Meter, error)
func (*BillingService) ListPlanViews ¶
func (s *BillingService) ListPlanViews(ctx context.Context) ([]PlanView, error)
func (*BillingService) MarkOrderPaid ¶
func (*BillingService) MeterDueOverages ¶
func (*BillingService) RegisterMeter ¶
func (s *BillingService) RegisterMeter(ctx context.Context, m Meter) error
func (*BillingService) TestChannelConnection ¶
func (s *BillingService) TestChannelConnection(ctx context.Context, name string) error
func (*BillingService) UsagePreview ¶
func (*BillingService) WithEventEmitter ¶
func (s *BillingService) WithEventEmitter(emit EventEmit) *BillingService
func (*BillingService) WithMeterRegistry ¶
func (s *BillingService) WithMeterRegistry(r MeterRegistry) *BillingService
type ChannelConfigInfo ¶
type ChannelConfigView ¶
type ChannelConfigViewer ¶
type ChannelConfigViewer interface {
ChannelConfig() ChannelConfigInfo
}
type ChannelRegistry ¶
type ChannelRegistry struct {
// contains filtered or unexported fields
}
func NewChannelRegistry ¶
func NewChannelRegistry() *ChannelRegistry
func (*ChannelRegistry) Get ¶
func (r *ChannelRegistry) Get(name string) (PaymentChannel, bool)
func (*ChannelRegistry) Names ¶
func (r *ChannelRegistry) Names() []string
func (*ChannelRegistry) Register ¶
func (r *ChannelRegistry) Register(ch PaymentChannel)
type CheckoutCanceller ¶
type ConnectionTester ¶
type ExpiredWorkspace ¶
type ManualChannel ¶
type ManualChannel struct {
InfoURL string
}
func (*ManualChannel) CreateCheckout ¶
func (m *ManualChannel) CreateCheckout(_ context.Context, order domain.Order, _, _ string) (domain.CheckoutSession, error)
func (*ManualChannel) Name ¶
func (m *ManualChannel) Name() string
func (*ManualChannel) ParseWebhook ¶
func (m *ManualChannel) ParseWebhook(_ context.Context, _ WebhookRequest) (domain.PaymentEvent, error)
type MeterRegistry ¶
type MeteredWorkspace ¶
type OverageItem ¶
type PaymentChannel ¶
type PaymentChannel interface {
Name() string
CreateCheckout(ctx context.Context, order domain.Order, successURL, cancelURL string) (domain.CheckoutSession, error)
ParseWebhook(ctx context.Context, req WebhookRequest) (domain.PaymentEvent, error)
}
type PaymentEventFilter ¶
type PaymentEventFilter struct {
WorkspaceID string
}
type PaymentEventView ¶
type PaymentEventView struct {
ID string `json:"id"`
Channel string `json:"channel"`
ChannelEventID string `json:"channel_event_id"`
Type string `json:"event_type"`
OrderID string `json:"order_id,omitempty"`
ProcessStatus string `json:"process_status"`
ProcessError string `json:"process_error,omitempty"`
ProcessedAt *time.Time `json:"processed_at,omitempty"`
Processed bool `json:"processed"`
CreatedAt time.Time `json:"created_at"`
}
type Repo ¶
type Repo interface {
CreateOrder(ctx context.Context, o domain.Order) (domain.Order, error)
GetOrder(ctx context.Context, id string) (domain.Order, bool, error)
ListOrdersByWorkspace(ctx context.Context, workspaceID string, limit int) ([]domain.Order, error)
UpdateOrderStatus(ctx context.Context, id string, from, to domain.OrderStatus, now time.Time) error
FailOrder(ctx context.Context, o domain.Order, e domain.PaymentEvent, emit func(tx pgx.Tx) error, now time.Time) error
PayOrder(ctx context.Context, id string, emit func(tx pgx.Tx) error, now time.Time) error
SetOrderChannelRef(ctx context.Context, id, channelRef string) error
FindOrderByChannelRef(ctx context.Context, channel, channelRef string) (domain.Order, bool, error)
SetOrderPaymentIntentRef(ctx context.Context, orderID, paymentIntentRef string) error
FindOrderByPaymentIntent(ctx context.Context, paymentIntentRef string) (domain.Order, bool, error)
InsertPaymentEvent(ctx context.Context, e domain.PaymentEvent) (isNew bool, err error)
MarkEventProcessed(ctx context.Context, channel, channelEventID string) error
MarkEventError(ctx context.Context, channel, channelEventID, processErr string) error
ListPlans(ctx context.Context) ([]domain.Plan, error)
GetPlan(ctx context.Context, code string) (domain.Plan, bool, error)
ChangeWorkspacePlan(ctx context.Context, workspaceID, toPlan, actor, reason string, now time.Time, inTx func(tx pgx.Tx, from string) error) error
GetWorkspacePlan(ctx context.Context, workspaceID string) (string, error)
SetWorkspaceSubscription(ctx context.Context, workspaceID, subscriptionRef string, expiresAt, now time.Time) error
GetWorkspaceSubscription(ctx context.Context, workspaceID string) (ref string, ok bool, err error)
FindWorkspaceBySubscription(ctx context.Context, subscriptionRef string) (workspaceID, planCode string, ok bool, err error)
LatestPaidOrderInterval(ctx context.Context, workspaceID string) (interval string, ok bool, err error)
ExpireDueWorkspaces(ctx context.Context, now time.Time, limit int) ([]ExpiredWorkspace, error)
InsertOverageOrder(ctx context.Context, o domain.Order) (order domain.Order, created bool, err error)
ListMeteredWorkspaces(ctx context.Context, limit int) ([]MeteredWorkspace, error)
}
type SubscriptionCanceller ¶
type UsagePreview ¶
type UsagePreview struct {
Period string `json:"period"`
Items []UsagePreviewItem `json:"items"`
ProjectedTotalCents int64 `json:"projected_total_cents"`
}
type UsagePreviewItem ¶
type WebhookRequest ¶
Click to show internal directories.
Click to hide internal directories.