Help us shape the future of Go! Take the 2026 Go Developer Survey

billing

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

README

Billing module

modules/billing is what a tenant pays for: plans are a collection an administrator maintains (a rest.Spec at /api/v1/billing/plans, guarded by billing:read and billing:manage), the subscription is a tenant's singleton at /api/v1/billing/subscription, and billing:catalog reads the plan list. Renewal takes money from somebody else's machine, so the job never runs inside a database transaction; module.go makes that argument and ADR 0008 says who sets prices.

Compose it with billing.Deps{Tenants, Payments, RenewEvery}, where Payments is your contracts.PaymentProvider. Consumers import contracts/ and its fake, never internal/. make test TEST_PACKAGES=./modules/billing/... needs the development database.

Documentation

Overview

Package billing is the module manifest: what a tenant is paying for.

It is the shape every module follows — contracts/, internal/, and one exported function taking a struct of typed dependencies and returning a module.Module — with one asymmetry worth naming at the top. Plans are a collection an administrator maintains, so they are a rest.Spec. The subscription is not a collection: a tenant is the customer, so it has one, and a singleton has no list, no create and no id in its path. Its three routes are internal/handler.go, the only hand-written ones here.

Renewal is the other thing to read first. Taking money is a call to somebody else's machine, so it never happens inside a database transaction: the job asks the service what is owed, closes that transaction, charges, and opens another to record the answer. internal/renew.go is the shape.

Index

Constants

This section is empty.

Variables

Manual is the PaymentProvider that records what is owed and moves no money. main wires it, or whatever a deployment has instead, so the choice is visible in the file that composes the application — as the mailer is.

View Source
var Migrations = db.MigrationSource{
	Owner:  "billing",
	Files:  db.Sub(schema, "migrations"),
	Adopts: []db.Adoption{{Owner: "platformkit", Versions: []int64{16, 22}}},
}

Migrations is this module's SQL as one source — plans, subscriptions and their billing anchor — owned as "billing". The manifest hands the kernel the same files and adoption, and a test composes the schema it needs beside the foundation: dbtest.Schema(t, billing.Migrations).

The files keep the version numbers they had when the foundation applied them under its own name, so an installation migrated before this module owned its SQL is adopted by checksum rather than migrated again (see db.Adoption and docs/adr/0011). New files continue from the highest number.

Functions

func Module

func Module(deps Deps) (httpx.Entitler, module.Module)

Module is the manifest, and the plan answer beside it, as user's and notification's modules return their services: the kernel asks this module what a tenant's plan includes, for the operations whose declaration names a feature, and this is where an application is handed something to answer with.

Types

type Deps

type Deps struct {
	// Tenants is how the nightly renewal reaches every tenant.
	Tenants jobs.TenantLister

	// Payments takes the money. There is one implementation here, Manual; the
	// ones that speak to a payment processor live outside this repository.
	Payments contracts.PaymentProvider

	// RenewEvery replaces the nightly schedule with an interval, for a test
	// that cannot wait until two in the morning. Zero means the schedule.
	RenewEvery time.Duration
}

Deps is what this module cannot make for itself.

Directories

Path Synopsis
Package contracts is everything another module, an app or a test may know about billing: the two entities, the events, the permissions, the payment provider this module needs somebody else to satisfy, and the Service interface.
Package contracts is everything another module, an app or a test may know about billing: the two entities, the events, the permissions, the payment provider this module needs somebody else to satisfy, and the Service interface.
billingtest
Package billingtest is the conformance suite for contracts.Service, and a fake that passes it.
Package billingtest is the conformance suite for contracts.Service, and a fake that passes it.
Package internal is every implementation of the billing module.
Package internal is every implementation of the billing module.

Jump to

Keyboard shortcuts

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