Documentation
¶
Overview ¶
Package activation implements the billing-domain stages of the paid-order activation saga: the recharge wallet credit, the referral commission and the final settlement. Each stage is idempotent (inbox marker or status CAS); the queue shell sequences the stages. Only the module facade may reach it.
Index ¶
Constants ¶
const ( OrderTypeSubscribe = 1 OrderTypeRenewal = 2 OrderTypeRecharge = 4 OrderStatusPaid = 2 OrderStatusFinished = 5 )
Order lifecycle constants mirrored from the order rows.
Variables ¶
var ErrInvalidOrderStatus = errors.New("invalid order status")
ErrInvalidOrderStatus reports a lost Paid->Finished CAS: the order left the Paid state underneath the settlement.
Functions ¶
This section is empty.
Types ¶
type Deps ¶
type Deps struct {
Orders repository.OrderRepo
// Store carries the billing-scoped transactions, the wallet view and
// the inbox markers.
Store Store
// Profiles resolves the buyer's referrer and the referrer's commission
// settings from the identity domain.
Profiles ProfileReader
// InvitePolicy snapshots the runtime-mutable site-wide referral
// fallback (percentage, first-purchase-only).
InvitePolicy func() (percentage uint8, onlyFirstPurchase bool)
}
Deps declares the subdomain's dependencies; the module facade forwards them from the composition root.
type ProfileReader ¶
ProfileReader is the read-only identity port resolving referral settings; the legacy user repository satisfies it structurally.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the activation entry point used by the billing facade.
func NewService ¶
func (*Service) ActivateRecharge ¶
ActivateRecharge credits the order's amount to the buyer's wallet exactly once and returns the post-credit balance (re-read on replays) for the caller's notification.
func (*Service) FinalizeOrder ¶
FinalizeOrder is the billing-domain settlement: coupon accounting and the Paid -> Finished transition (which appends the order.fulfilled outbox event) commit atomically. Losing the status CAS rolls the coupon count back, so it stays exactly-once.
Known transitional window: an admin closing a Paid order between the fulfillment stage and this CAS leaves the fulfillment committed while the order ends Closed. The pre-split code had the same conflict resolved by row locks; compensation for admin closes of paid orders is a billing concern tracked in ADR-001 step 2.
func (*Service) SettleOrderCommission ¶
SettleOrderCommission credits the referral commission for a purchase or renewal exactly once. The inbox marker also covers the "no commission applies" outcome so replays skip the referrer lock entirely.
type Store ¶
type Store interface {
InBillingTx(ctx context.Context, fn func(repository.BillingStore) error) error
Inbox() repository.InboxRepo
Wallet() repository.WalletRepo
}
Store is the narrow persistence surface the activation stages need; the repository store satisfies it structurally.