orders

package module
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 10 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package orders is the official commerce order module: first-class orders snapshotted at checkout, a domain-enforced status lifecycle, guest order tracking, an admin order surface, and a pending-expiry sweeper that ages unpaid orders off the books. Checkout consumes the cart through the CartSource seam the composition root adapts; the module's only knob is the sweeper cadence the composition root adopts.

Index

Constants

View Source
const (
	// Name is the registry key for this module.
	Name = "orders"

	// Version is the module version reported via Module.Version.
	Version = "0.1.0"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Module

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

Module is the orders kernel module.

func New

func New(options ...Option) *Module

New builds the module and constructs the handler once, so every endpoint shares the adopted service. A module built without a logger degrades to a discard sink: the background sweeper logs unconditionally and must never panic for lack of one.

func (*Module) Capabilities

func (m *Module) Capabilities() []string

Capabilities contributes the module's permission to the registry so the resolver can grant it (Admin implicitly, custom roles via config when declared).

func (*Module) Init

func (m *Module) Init(_ kernel.Kernel) error

Init wires the module. The handler is already built by New; Init only validates that the adopted service and resolver are present — an orders module without every seam fails startup loudly instead of serving an empty surface. A configured sweeper starts its background loop here. Migration execution is core-driven (it needs the live *sql.DB, which modules never touch directly).

func (*Module) InvoiceSettings

func (m *Module) InvoiceSettings() ordersdomain.InvoiceSettings

InvoiceSettings returns the live invoice settings the next rendered invoice will use.

func (*Module) Migrations

func (m *Module) Migrations() fs.FS

Migrations returns the embedded migration filesystem, laid out per driver subdirectory (the core migration runner selects via Driver.MigrationDir).

func (*Module) Name

func (m *Module) Name() string

Name returns the registry key.

func (*Module) Optional

func (m *Module) Optional() []string

Optional lists soft dependencies. The mailer is structural best-effort: email failures never fail checkout or transitions.

func (*Module) RegisterDualRoutes

func (m *Module) RegisterDualRoutes(r kernel.DualAuthRegistrar)

RegisterDualRoutes declares the admin surface for dual-realm mounting: core serves every path on both the agent stack (Bearer API key) and the browser stack (CSRF plus JWT), dispatched by credential — so AI agents operate orders with the same API key they use for content while the admin SPA keeps working unchanged. Same handlers, same in-handler Admin checks on both realms.

func (*Module) RegisterPublicRoutes

func (m *Module) RegisterPublicRoutes(router chi.Router)

RegisterPublicRoutes mounts the public surface (rate-limited, no auth chain): checkout, and guest order tracking.

func (*Module) Requires

func (m *Module) Requires() []string

Requires lists hard dependencies. Checkout consumes the cart through the CartSource seam, and carts price from the catalog: without either there is nothing to check out, so disabling catalog cascades orders off the registry (catalog → cart → orders). The module covers both the checkout surface and the admin lifecycle views, so it is coherent to disable it as one unit.

func (*Module) SetInvoiceSettings

func (m *Module) SetInvoiceSettings(settings ordersdomain.InvoiceSettings) error

SetInvoiceSettings validates nothing itself (the API surface does) but persists the block through the adopted saver first: a failed write leaves the running settings untouched, so the admin sees the error instead of a value that would vanish on restart. The write lock spans the saver and the assignment so parallel admin saves cannot diverge the file from the live settings; invoice renders take the read lock and block briefly.

func (*Module) Shutdown

func (m *Module) Shutdown() error

Shutdown stops the sweeper and waits for its loop to return, so a graceful shutdown never leaks a tick mid-write.

func (*Module) Version

func (m *Module) Version() string

Version returns the module version.

type Option

type Option func(*Module)

Option configures a Module. The composition root supplies every option; direct construction without options yields a standalone module that serves nothing (handlers built over nil dependencies must not be invoked).

func WithCapabilityResolver

func WithCapabilityResolver(resolve kernel.CapabilityResolver) Option

WithCapabilityResolver attaches the capability resolver gating the admin surface. Without one every admin request is refused (fail closed).

func WithInvoiceRenderer

func WithInvoiceRenderer(renderer ordersdomain.InvoiceRenderer) Option

WithInvoiceRenderer adopts the PDF renderer backing the invoice endpoint. Without one the endpoint answers unavailable.

func WithInvoiceSettings

func WithInvoiceSettings(settings ordersdomain.InvoiceSettings) Option

WithInvoiceSettings adopts the seller identity and PPN rate stamped on every invoice.

func WithInvoiceSettingsSaver

func WithInvoiceSettingsSaver(saver func(ordersdomain.InvoiceSettings) error) Option

WithInvoiceSettingsSaver adopts the persistence seam behind the admin invoice-settings surface: the composition root supplies the config.toml write-back, so an admin edit survives a restart. Without one, edits stay in memory for the running process.

func WithLogger

func WithLogger(logger kernel.Logger) Option

WithLogger attaches the module logger. Without one handler failures are dropped (discard sink).

func WithManualPayee

func WithManualPayee(payee ordersapi.ManualPayee) Option

WithManualPayee adopts the manual payee block for guest tracking payloads. Without one tracking payloads carry no payee section.

func WithService

func WithService(service *ordersdomain.Service) Option

WithService adopts the order domain service (composition root). The same instance backs every endpoint so checkout, tracking, and the admin surface speak one snapshot vocabulary.

func WithSweeper

func WithSweeper(interval time.Duration, ttl time.Duration) Option

WithSweeper runs the pending-expiry sweep in the module background: every interval the module expires pendings older than the TTL. A non-positive interval leaves the sweeper off (tests, standalone modules). The TTL mirrors into gateway session lifetimes so a hosted checkout cannot outlive the order it pays.

Directories

Path Synopsis
api
Package api hosts the order module's surfaces: the public checkout and guest tracking (rate-limited, no auth chain) and the admin order list, detail, and lifecycle transitions (JWT-protected, admin-gated).
Package api hosts the order module's surfaces: the public checkout and guest tracking (rate-limited, no auth chain) and the admin order list, detail, and lifecycle transitions (JWT-protected, admin-gated).
Package orders is the official commerce order module: first-class orders snapshotted at checkout, a domain-enforced status lifecycle, and guest order tracking.
Package orders is the official commerce order module: first-class orders snapshotted at checkout, a domain-enforced status lifecycle, and guest order tracking.
Package pdf renders order invoices to PDF bytes over maroto.
Package pdf renders order invoices to PDF bytes over maroto.
Package store is the single-source order repository: one implementation against *sql.DB plus a kernel Dialect, following the cart/media store pattern.
Package store is the single-source order repository: one implementation against *sql.DB plus a kernel Dialect, following the cart/media store pattern.
Package testutil provides the kernel fixture module tests run against.
Package testutil provides the kernel fixture module tests run against.

Jump to

Keyboard shortcuts

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