Documentation
¶
Overview ¶
Package subscriptions is togo's subscription-management plugin: plans, subscribe / cancel / change, trials, and status — built on the `payment` plugin (charges are delegated to whatever PaymentProvider is registered in the kernel). If no payment provider is installed, it still manages subscription state locally.
Install: `togo install togo-framework/subscriptions` (blank-import registers it).
Index ¶
- type Charger
- type Plan
- type Service
- func (s *Service) Cancel(ctx context.Context, id string) error
- func (s *Service) Change(ctx context.Context, id, planID string) error
- func (s *Service) CreatePlan(ctx context.Context, p Plan) (*Plan, error)
- func (s *Service) ListPlans(ctx context.Context) ([]Plan, error)
- func (s *Service) ListSubscriptions(ctx context.Context, userID string) ([]Subscription, error)
- func (s *Service) Subscribe(ctx context.Context, userID, planID string, trialDays int) (*Subscription, error)
- type Subscription
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Charger ¶
type Charger interface {
CreateSubscription(ctx context.Context, customer, plan string, meta map[string]string) (string, error)
}
Charger is the minimal slice of the payment plugin this needs. The payment plugin's service is looked up from the kernel container (no import dependency), so subscriptions builds + runs whether or not payment is installed.
type Plan ¶
type Plan struct {
ID string `db:"id" json:"id"`
Name string `db:"name" json:"name"`
Price float64 `db:"price" json:"price"`
Currency string `db:"currency" json:"currency"`
Interval string `db:"interval" json:"interval"` // "month" | "year" | "week" | "day"
Features string `db:"features" json:"features"` // free-form / JSON
CreatedAt string `db:"created_at" json:"created_at"`
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func (*Service) CreatePlan ¶
func (*Service) ListSubscriptions ¶
type Subscription ¶
type Subscription struct {
ID string `db:"id" json:"id"`
UserID string `db:"user_id" json:"user_id"`
PlanID string `db:"plan_id" json:"plan_id"`
Status string `db:"status" json:"status"` // trialing|active|canceled|past_due
ProviderRef string `db:"provider_ref" json:"provider_ref"`
TrialEndsAt string `db:"trial_ends_at" json:"trial_ends_at"`
CurrentPeriodEnd string `db:"current_period_end" json:"current_period_end"`
CreatedAt string `db:"created_at" json:"created_at"`
CanceledAt string `db:"canceled_at" json:"canceled_at"`
}
Click to show internal directories.
Click to hide internal directories.