subscriptions

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 11 Imported by: 0

README

togo

togo-framework/subscriptions

marketplace pkg.go.dev MIT

Part of the togo framework.

Install

togo install togo-framework/subscriptions

togo

togo · subscriptions

Subscription management for togoplans, subscribe / cancel / change, trials, and status — built on the payment plugin. Charges are delegated to whatever PaymentProvider is registered in the kernel; with no payment provider installed it still manages subscription state.

Install

togo install togo-framework/subscriptions
# usually alongside a payment provider:
togo install togo-framework/payment-stripe

Tables (plans, subscriptions) are created on boot.

API

Method Path Description
GET /api/plans List plans
POST /api/plans Create a plan ({name, price, currency, interval, features})
GET /api/subscriptions?user_id= A user's subscriptions
POST /api/subscriptions Subscribe ({user_id, plan_id, trial_days})
POST /api/subscriptions/{id}/cancel Cancel
POST /api/subscriptions/{id}/change Upgrade/downgrade ({plan_id})

Payment integration

The plugin looks up the payment service from the kernel container and, if it satisfies the local Charger interface (CreateSubscription), creates a provider-side subscription and stores the provider_ref. No hard import on payment, so subscriptions builds and runs standalone.

MIT


Premium sponsors

ID8 Media  ·  One Studio

Support togo — become a sponsor.

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

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) Cancel

func (s *Service) Cancel(ctx context.Context, id string) error

func (*Service) Change

func (s *Service) Change(ctx context.Context, id, planID string) error

Change upgrades/downgrades a subscription to another plan.

func (*Service) CreatePlan

func (s *Service) CreatePlan(ctx context.Context, p Plan) (*Plan, error)

func (*Service) ListPlans

func (s *Service) ListPlans(ctx context.Context) ([]Plan, error)

func (*Service) ListSubscriptions

func (s *Service) ListSubscriptions(ctx context.Context, userID string) ([]Subscription, error)

func (*Service) Subscribe

func (s *Service) Subscribe(ctx context.Context, userID, planID string, trialDays int) (*Subscription, error)

Subscribe creates a subscription for a user on a plan, with an optional trial. If a payment provider is installed it creates a provider-side subscription.

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"`
}

Jump to

Keyboard shortcuts

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