orderflow

package
v1.19.1 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: GPL-3.0 Imports: 5 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

func ApplyIdempotency

func ApplyIdempotency(ctx context.Context, data *order.Order)

func GuestCheckoutToken

func GuestCheckoutToken(ctx context.Context) string

func ReserveInventoryOnce added in v1.15.0

func ReserveInventoryOnce(ctx context.Context, store Store, orderNo string, subscribeID int64) error

func RestoreInventoryOnce added in v1.15.0

func RestoreInventoryOnce(ctx context.Context, store Store, orderNo string, subscribeID int64) error

RestoreInventoryOnce 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.

func WithIdempotency

func WithIdempotency(ctx context.Context, value Idempotency) context.Context

Types

type Idempotency

type Idempotency struct {
	Key                string
	Hash               string
	GuestCheckoutToken string
}

Idempotency carries V2-only creation metadata through the existing domain creators. V1 callers never attach it, so their persisted representation and behaviour remain unchanged.

type Store added in v1.15.0

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

ReserveInventoryOnce reserves one unit of plan inventory for the order in a subscription-domain transaction. Replays and concurrent deliveries are resolved by the inbox marker: a lost race rolls the reservation back and the retry sees the winner's marker. Returns ErrOutOfStock when no unit is left. 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