Module: LoyaltyProgram::Benefits::DineInPoints
- Includes:
- SpecialBenefits::Campaign
- Defined in:
- app/my_lib/loyalty_program/benefits/dine_in_points.rb
Instance Method Summary collapse
-
#calc_with_loyalty_level(points, transaction) ⇒ Integer
Calculates the number of dine-in points a user will receive based on their loyalty level and the transaction they are making.
Methods included from SpecialBenefits::Campaign
#eligible_to_double_point?, #eligible_to_triple_point?
Instance Method Details
#calc_with_loyalty_level(points, transaction) ⇒ Integer
Calculates the number of dine-in points a user will receive based on their loyalty level and the transaction they are making.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/my_lib/loyalty_program/benefits/dine_in_points.rb', line 16 def calc_with_loyalty_level(points, transaction) user = transaction.user return points if user.blank? user_loyalty = user.user_loyalty return 0 if user_loyalty.blank? restaurant_country = transaction&.restaurant&.country dine_in_point = user_loyalty.dine_in_point_key_by_country(restaurant_country) benefit = user_loyalty.benefit_value(dine_in_point) points = (points.to_f * benefit).floor if eligible_to_triple_point?(transaction) points *= 3 elsif eligible_to_double_point?(transaction) points *= 2 end points end |