package order import "github.com/perfect-panel/server/internal/types" func getDiscount(discounts []types.SubscribeDiscount, inputMonths int64, isNewUser bool) float64 { for _, discount := range discounts { if discount.NewUserOnly && !isNewUser { continue } if inputMonths == discount.Quantity && discount.Discount > 0 && discount.Discount < 100 { return discount.Discount / float64(100) } } return 1 } // isNewUserOnlyForQuantity checks whether the matched discount tier has new_user_only enabled. func isNewUserOnlyForQuantity(discounts []types.SubscribeDiscount, inputQuantity int64) bool { for _, discount := range discounts { if inputQuantity == discount.Quantity { return discount.NewUserOnly } } return false }