Documentation
¶
Overview ¶
Package orderLogic provides order processing logic for handling various types of orders including subscription purchases, renewals, traffic resets, and balance recharges.
Index ¶
Constants ¶
const ( OrderTypeSubscribe = 1 // New subscription purchase OrderTypeRenewal = 2 // Subscription renewal OrderTypeResetTraffic = 3 // Traffic quota reset OrderTypeRecharge = 4 // Balance recharge )
Order type constants define the different types of orders that can be processed
const ( OrderStatusPending = 1 // Order created but not paid OrderStatusPaid = 2 // Order paid and ready for processing OrderStatusClose = 3 // Order closed/cancelled OrderStatusFailed = 4 // Order processing failed OrderStatusFinished = 5 // Order successfully completed )
Order status constants define the lifecycle states of an order
Variables ¶
var ( ErrInvalidOrderStatus = fmt.Errorf("invalid order status") ErrInvalidOrderType = fmt.Errorf("invalid order type") )
Predefined error variables for common error conditions
Functions ¶
This section is empty.
Types ¶
type ActivateOrderLogic ¶
type ActivateOrderLogic struct {
// contains filtered or unexported fields
}
ActivateOrderLogic handles the activation and processing of paid orders
func NewActivateOrderLogic ¶
func NewActivateOrderLogic(svc *svc.ServiceContext) *ActivateOrderLogic
NewActivateOrderLogic creates a new instance of ActivateOrderLogic
func (*ActivateOrderLogic) ProcessTask ¶
ProcessTask activates a paid order as a sequence of single-domain transactions instead of one cross-domain transaction (ADR-001 step 2):
- identity: create the guest account (subscribe orders without a user)
- subscription/identity: fulfill (open/extend/reset subscription, or credit the recharge balance)
- identity: settle referral commission
- billing: coupon accounting + the Paid -> Finished transition, which also appends the order.fulfilled outbox event
Idempotency: every stage marks itself in the domain event inbox inside its own transaction, so Asynq's at-least-once delivery and the paid-order reconciler can replay the task safely — completed stages are skipped, the remaining ones run. The order stays Paid until stage 4 commits, so a crash between stages leaves a durable signal that the reconciler re-drives.
type CleanupOrderEventsLogic ¶ added in v1.14.19
type CleanupOrderEventsLogic struct {
// contains filtered or unexported fields
}
CleanupOrderEventsLogic removes only events that have already reached Redis and are older than the replay contract. Unpublished events are never deleted, even if an outage lasts longer than the normal retention period.
func NewCleanupOrderEventsLogic ¶ added in v1.14.19
func NewCleanupOrderEventsLogic(svcCtx *svc.ServiceContext) *CleanupOrderEventsLogic
func (*CleanupOrderEventsLogic) ProcessTask ¶ added in v1.14.19
type DeferCloseOrderLogic ¶
type DeferCloseOrderLogic struct {
// contains filtered or unexported fields
}
func NewDeferCloseOrderLogic ¶
func NewDeferCloseOrderLogic(svc *svc.ServiceContext) *DeferCloseOrderLogic
func (*DeferCloseOrderLogic) ProcessTask ¶
type PublishOrderEventsLogic ¶ added in v1.14.19
type PublishOrderEventsLogic struct {
// contains filtered or unexported fields
}
PublishOrderEventsLogic drains the durable order event outbox. Publishing is intentionally separate from writing the event: a Redis outage may delay a notification but can never roll back a committed payment state.
func NewPublishOrderEventsLogic ¶ added in v1.14.19
func NewPublishOrderEventsLogic(svcCtx *svc.ServiceContext) *PublishOrderEventsLogic
func (*PublishOrderEventsLogic) ProcessTask ¶ added in v1.14.19
type ReconcilePaidOrdersLogic ¶ added in v1.14.0
type ReconcilePaidOrdersLogic struct {
// contains filtered or unexported fields
}
ReconcilePaidOrdersLogic treats the durable Paid state as an activation outbox. It repairs the database/Redis gap if a callback committed payment but Redis was unavailable before the activation task could be inserted.
func NewReconcilePaidOrdersLogic ¶ added in v1.14.0
func NewReconcilePaidOrdersLogic(svc *svc.ServiceContext) *ReconcilePaidOrdersLogic
func (*ReconcilePaidOrdersLogic) ProcessTask ¶ added in v1.14.0
type ReconcilePendingOrdersLogic ¶ added in v1.14.16
type ReconcilePendingOrdersLogic struct {
// contains filtered or unexported fields
}
ReconcilePendingOrdersLogic is a durable fallback for deferred close tasks. State transitions in CloseOrder remain conditional, so a late callback can safely race this scan without turning a paid order back into a close order.
func NewReconcilePendingOrdersLogic ¶ added in v1.14.16
func NewReconcilePendingOrdersLogic(svc *svc.ServiceContext) *ReconcilePendingOrdersLogic