activation

package
v1.15.3 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

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

View Source
const (
	OrderTypeSubscribe = 1
	OrderTypeRenewal   = 2
	OrderTypeRecharge  = 4

	OrderStatusPaid     = 2
	OrderStatusFinished = 5
)

Order lifecycle constants mirrored from the order rows.

Variables

View Source
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

type ProfileReader interface {
	FindOne(ctx context.Context, id int64) (*user.User, error)
}

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 NewService(deps Deps) *Service

func (*Service) ActivateRecharge

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

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

func (s *Service) FinalizeOrder(ctx context.Context, orderNo string) error

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

func (s *Service) SettleOrderCommission(ctx context.Context, orderNo string, buyerID int64) error

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.

Jump to

Keyboard shortcuts

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