Class: Customer::RadiantReward

Inherits:
Object
  • Object
show all
Defined in:
app/services/customer/radiant_reward.rb

Instance Method Summary collapse

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, options={})
  @customer = customer
  @profile = options[:profile] || @customer.profile
  @options = options
  @logger = options[:logger] || Rails.logger
end

Instance Method Details

#address_qualifies?Boolean

Returns:

  • (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_eligibleObject

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_eligibleObject



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

Returns:

  • (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

#progressObject



26
27
28
# File 'app/services/customer/radiant_reward.rb', line 26

def progress
  enroll if @customer.customer_record&.rr_enrolled?
end

#qualification_errorsObject



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?

Returns:

  • (Boolean)


50
51
52
# File 'app/services/customer/radiant_reward.rb', line 50

def qualified? #rr_qualified?
  profile_qualifies? and address_qualifies?
end

#statusObject



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