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
- type Module
- func (m *Module) Capabilities() []string
- func (m *Module) Init(_ kernel.Kernel) error
- func (m *Module) InvoiceSettings() ordersdomain.InvoiceSettings
- func (m *Module) Migrations() fs.FS
- func (m *Module) Name() string
- func (m *Module) Optional() []string
- func (m *Module) RegisterDualRoutes(r kernel.DualAuthRegistrar)
- func (m *Module) RegisterPublicRoutes(router chi.Router)
- func (m *Module) Requires() []string
- func (m *Module) SetInvoiceSettings(settings ordersdomain.InvoiceSettings) error
- func (m *Module) Shutdown() error
- func (m *Module) Version() string
- type Option
- func WithCapabilityResolver(resolve kernel.CapabilityResolver) Option
- func WithInvoiceRenderer(renderer ordersdomain.InvoiceRenderer) Option
- func WithInvoiceSettings(settings ordersdomain.InvoiceSettings) Option
- func WithInvoiceSettingsSaver(saver func(ordersdomain.InvoiceSettings) error) Option
- func WithLogger(logger kernel.Logger) Option
- func WithManualPayee(payee ordersapi.ManualPayee) Option
- func WithService(service *ordersdomain.Service) Option
- func WithSweeper(interval time.Duration, ttl time.Duration) Option
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
Migrations returns the embedded migration filesystem, laid out per driver subdirectory (the core migration runner selects via Driver.MigrationDir).
func (*Module) Optional ¶
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 ¶
RegisterPublicRoutes mounts the public surface (rate-limited, no auth chain): checkout, and guest order tracking.
func (*Module) Requires ¶
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.
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 ¶
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 ¶
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 |
|---|---|
|
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. |