Class: Customer::RadiantReward
- Inherits:
-
Object
- Object
- Customer::RadiantReward
- Defined in:
- app/services/customer/radiant_reward.rb
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.
3 4 5 6 7 8 |
# File 'app/services/customer/radiant_reward.rb', line 3 def initialize(customer, ={}) @customer = customer @profile = [:profile] || @customer.profile @options = @logger = [:logger] || Rails.logger end |
Instance Method Details
#address_qualifies? ⇒ Boolean
65 66 67 68 |
# File 'app/services/customer/radiant_reward.rb', line 65 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.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/services/customer/radiant_reward.rb', line 12 def enroll(customer_params=nil) if qualified? and (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 return @customer.save else return 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 |
# File 'app/services/customer/radiant_reward.rb', line 36 def pricing_program_eligible eligible_orders = orders_eligible.size if eligible_orders >= 2 code = "PP-RR3-30" elsif eligible_orders == 1 code = "PP-RR2-30" else code = "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
61 62 63 |
# File 'app/services/customer/radiant_reward.rb', line 61 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
54 55 56 57 58 59 |
# File 'app/services/customer/radiant_reward.rb', line 54 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?
50 51 52 |
# File 'app/services/customer/radiant_reward.rb', line 50 def qualified? #rr_qualified? profile_qualifies? and address_qualifies? end |
#status ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'app/services/customer/radiant_reward.rb', line 70 def status if @customer.customer_record&.rr_enrolled? :enrolled elsif qualified? :qualified else :not_available end end |