Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyIdempotency(ctx context.Context, data *order.Order)
- func GuestCheckoutToken(ctx context.Context) string
- func ReserveInventoryOnce(ctx context.Context, store Store, orderNo string, subscribeID int64) error
- func RestoreInventoryOnce(ctx context.Context, store Store, orderNo string, subscribeID int64) error
- func WithIdempotency(ctx context.Context, value Idempotency) context.Context
- type Idempotency
- type Store
Constants ¶
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 ¶
var ErrOutOfStock = errors.New("subscribe out of stock")
ErrOutOfStock reports that the plan has no inventory left to reserve.
Functions ¶
func GuestCheckoutToken ¶
func ReserveInventoryOnce ¶ added in v1.15.0
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 ¶
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.