diff --git a/internal/logic/public/order/getDiscount.go b/internal/logic/public/order/getDiscount.go index ee7dd4e..db107f3 100644 --- a/internal/logic/public/order/getDiscount.go +++ b/internal/logic/public/order/getDiscount.go @@ -16,13 +16,23 @@ func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64, isNewUs } // isNewUserOnlyForQuantity checks whether the matched discount tier has new_user_only enabled. +// Returns true only when all matching tiers for the given quantity require new-user status +// (i.e. no fallback tier with new_user_only=false exists). When both a new-user-only tier +// and a general tier exist for the same quantity, non-new-users can still purchase via the +// general tier, so this returns false. func isNewUserOnlyForQuantity(discounts []types.SubscribeDiscount, inputQuantity int64) bool { - for _, discount := range discounts { - if inputQuantity == discount.Quantity { - return discount.NewUserOnly + hasNewUserOnly := false + hasFallback := false + for _, d := range discounts { + if d.Quantity != inputQuantity { + continue + } + if d.NewUserOnly { + hasNewUserOnly = true + } else { + hasFallback = true } } - - return false + return hasNewUserOnly && !hasFallback } diff --git a/queue/logic/order/activateOrderLogic.go b/queue/logic/order/activateOrderLogic.go index 45a41cc..582f595 100644 --- a/queue/logic/order/activateOrderLogic.go +++ b/queue/logic/order/activateOrderLogic.go @@ -1319,12 +1319,22 @@ func (l *ActivateOrderLogic) RedemptionActivate(ctx context.Context, orderInfo * } // isNewUserOnlyForQuantity checks whether the matched discount tier has new_user_only enabled. +// Returns true only when all matching tiers for the given quantity require new-user status +// (i.e. no fallback tier with new_user_only=false exists). When both a new-user-only tier +// and a general tier exist for the same quantity, non-new-users can still purchase via the +// general tier, so this returns false. func isNewUserOnlyForQuantity(discounts []internaltypes.SubscribeDiscount, inputQuantity int64) bool { + hasNewUserOnly := false + hasFallback := false for _, d := range discounts { - if inputQuantity == d.Quantity { - return d.NewUserOnly + if d.Quantity != inputQuantity { + continue + } + if d.NewUserOnly { + hasNewUserOnly = true + } else { + hasFallback = true } } - - return false + return hasNewUserOnly && !hasFallback }