Module: Modules::TicketTransactions::RewardPoints
- Includes:
- LoyaltyProgram::Benefits::DineInPoints
- Included in:
- Api::V5::TicketTransactionSerializer, GiveTicketRewardWorker
- Defined in:
- app/my_lib/modules/ticket_transactions/reward_points.rb
Overview
typed: ignore
Instance Method Summary collapse
-
#calc_dynamic_points(ticket_transaction_id, _for_serializer = false) ⇒ Integer, Float
Calculates reward points for a ticket transaction based on total price and currency.
Instance Method Details
#calc_dynamic_points(ticket_transaction_id, _for_serializer = false) ⇒ Integer, Float
Business Logic - Currency Points Conversion:
-
**SGD & MYR**: 1 point = 1 cent (1:1 ratio) Example: $10.50 SGD = 1050 cents → 1050 points (floor) → user earns 1050 points
-
*THB*: 1 point = 100 baht (1:100 ratio) Example: ฿1050 THB → 10.5 points (floor) → user earns 10 points
Why SGD and MYR are treated identically: Both currencies use the same points-to-currency ratio to maintain consistent reward value across Southeast Asian markets. This simplifies the loyalty program and provides fair earning rates regardless of country.
Configuration: If different conversion rates are needed per currency in the future, consider extracting this logic to a configurable Country model attribute (e.g., `points_conversion_ratio`) instead of hardcoding currency checks.
Calculates reward points for a ticket transaction based on total price and currency.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/my_lib/modules/ticket_transactions/reward_points.rb', line 27 def calc_dynamic_points(ticket_transaction_id, _for_serializer = false) ticket_transaction = TicketTransaction.find_by(id: ticket_transaction_id) return 0 if ticket_transaction.nil? || !ticket_transaction.active? # User won't get points if the ticket transaction is created from website return 0 if ticket_transaction.created_from_website? price_currency = ticket_transaction.total_price_currency price_cents = ticket_transaction.total_price_cents price_amount = HhMoney.new(price_cents, price_currency).amount.to_f points = case price_currency when Country::SINGAPORE_CURRENCY_CODE, Country::MALAYSIA_CURRENCY_CODE price_amount.floor else (price_amount / 100.0).floor end calc_with_loyalty_level(points, ticket_transaction) end |