inventory

package
v1.20.3 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InventoryReserveConsumer = "subscription.inventory_reserve"
	InventoryRestoreConsumer = "subscription.inventory_restore"
)

Inbox consumers for the plan-inventory lifecycle (ADR-001 step 2). Reservation and restoration are subscription-domain writes that used to sit inside billing transactions; the idempotent inbox keys them by order number so the purchase flow, the activation safety net and the close-order compensation can each run at-least-once without double-moving stock.

Variables

View Source
var ErrOutOfStock = errors.New("subscribe out of stock")

ErrOutOfStock reports that the plan has no inventory left to reserve.

Functions

This section is empty.

Types

type Service

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

func New

func New(store Store) *Service

func (*Service) Reserve

func (s *Service) Reserve(ctx context.Context, orderNo string, subscribeID int64) error

Reserve commits one unit and its inbox marker in the same subscription transaction. A duplicate marker rolls back a concurrent losing reservation.

func (*Service) Restore

func (s *Service) Restore(ctx context.Context, orderNo string, subscribeID int64) error

Restore returns the order's reserved unit exactly once. Orders that never reserved (stock-out compensation, historical orders) are a no-op, and a second restoration attempt is absorbed by the restore marker.

type Store

type Store interface {
	Inbox() repository.InboxRepo
	InSubscriptionTx(ctx context.Context, fn func(repository.SubscriptionStore) error) error
}

Store is the narrow persistence surface the inventory lifecycle needs; the repository store satisfies it structurally.

Jump to

Keyboard shortcuts

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