Class: Customer::RadiantReward
- Inherits:
-
Object
- Object
- Customer::RadiantReward
- Defined in:
- app/services/customer/radiant_reward.rb
Overview
Service object: radiant reward.
Instance Method Summary collapse
- #address_qualifies? ⇒ Boolean
-
#enroll(customer_params = nil) ⇒ Object
Check pricing program for radiant reward member, upgrades or set to base reward when initially enrolled.
-
#initialize(customer, options = {}) ⇒ RadiantReward
constructor
A new instance of RadiantReward.
-
#orders_eligible ⇒ Object
returns the number of eligible orders for the reward program.
- #pricing_program_eligible ⇒ Object
- #profile_qualifies? ⇒ Boolean
- #progress ⇒ Object
- #qualification_errors ⇒ Object
-
#qualified? ⇒ Boolean
rr_qualified?.
- #status ⇒ Object
Constructor Details
#initialize(customer, options = {}) ⇒ RadiantReward
Returns a new instance of RadiantReward.
4 5 6 7 8 9 |
# File 'app/services/customer/radiant_reward.rb', line 4 def initialize(customer, = {}) @customer = customer @profile = [:profile] || @customer.profile @options = @logger = [:logger] || Rails.logger end |
Instance Method Details
#address_qualifies? ⇒ Boolean
67 68 69 70 |
# File 'app/services/customer/radiant_reward.rb', line 67 def address_qualifies? address = @customer.main_address address and (address.country_iso3 == "USA" or address.state_code == "ON") end |
#enroll(customer_params = nil) ⇒ Object
Check pricing program for radiant reward member, upgrades or set to base
reward when initially enrolled.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/services/customer/radiant_reward.rb', line 13 def enroll(customer_params = nil) if qualified? && ((new_program = pricing_program_eligible).discount_percentage >= @customer.pricing_program_discount) # Upgrade pricing @customer.validate_rr = true @customer.customer_record&.update_attribute!(:rr_enrolled, true) @customer.tier2_program_pricing = new_program @customer.attributes = customer_params if customer_params @customer.save else false end end |
#orders_eligible ⇒ Object
returns the number of eligible orders for the reward program
31 32 33 34 |
# File 'app/services/customer/radiant_reward.rb', line 31 def orders_eligible @customer.orders.so_only.invoiced.where(Order[:line_total].gteq(200)) .where(Order[:shipped_date].gteq(1.year.ago)) end |
#pricing_program_eligible ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/services/customer/radiant_reward.rb', line 36 def pricing_program_eligible eligible_orders = orders_eligible.size code = if eligible_orders >= 2 "PP-RR3-30" elsif eligible_orders == 1 "PP-RR2-30" else "PP-RR1-25" end pp = Coupon::Tier2ProgramPricing.find_by(code: code) raise "Pricing Program #{code} not found in Coupon::Tier2ProgramPricing table." unless pp pp end |
#profile_qualifies? ⇒ Boolean
63 64 65 |
# File 'app/services/customer/radiant_reward.rb', line 63 def profile_qualifies? @profile.name.starts_with?('TP') or @profile.name.starts_with?('DL') end |
#progress ⇒ Object
26 27 28 |
# File 'app/services/customer/radiant_reward.rb', line 26 def progress enroll if @customer.customer_record&.rr_enrolled? end |
#qualification_errors ⇒ Object
56 57 58 59 60 61 |
# File 'app/services/customer/radiant_reward.rb', line 56 def qualification_errors errors = [] errors << "Customer must have main address in USA or Ontario province" unless address_qualifies? errors << "Customer must be a Trade Professional (TP-*)" unless profile_qualifies? errors end |
#qualified? ⇒ Boolean
rr_qualified?
52 53 54 |
# File 'app/services/customer/radiant_reward.rb', line 52 def qualified? profile_qualifies? and address_qualifies? end |
#status ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'app/services/customer/radiant_reward.rb', line 72 def status if @customer.customer_record&.rr_enrolled? :enrolled elsif qualified? :qualified else :not_available end end |