Sha256: 9cceeb4578d4a6f6eb8ba51e31397fc33d611014c50180f3844de9a7c8f3a4a2

Contents?: true

Size: 1.32 KB

Versions: 8

Compression:

Stored size: 1.32 KB

Contents

#
# This class excapsulate asynchrnous things we can do during or immediately following checkout
# usually involving the payment or customer objects (which aren't available after checkout)
# Examples: Updating a patron phone or address
#
# This class is not for order-related processing things. See OrderProcessor for that
#
# This class WILL NOT RUN ASYNC in test envs
#
class CheckoutProcessor < Struct.new(:person, :first_name, :last_name, :address_hash, :phone, :time_zone)
  QUEUE = "checkout"

  def initialize(person, customer, address, phone, time_zone)
    self.person         = person
    self.first_name     = customer.first_name
    self.last_name      = customer.last_name
    self.address_hash   = address.attributes.to_options unless address.nil?
    self.phone          = phone
    self.time_zone      = time_zone
  end

  def self.process(person, customer, address, phone, time_zone)
    job = CheckoutProcessor.new(person, customer, address, phone, time_zone)
    
    if job.run_now?
      job.perform
    else
      Delayed::Job.enqueue job, :queue => QUEUE
    end
  end

  def perform
    self.person.update_name(self.first_name, self.last_name)
    self.person.update_address(self.address_hash, self.time_zone, nil, "checkout")
    self.person.add_phone_if_missing(self.phone)
  end

  def run_now?
    Rails.env.test?
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
artfully_ose-1.2.0.pre.24 app/models/job/checkout_processor.rb
artfully_ose-1.2.0.pre.23 app/models/job/checkout_processor.rb
artfully_ose-1.2.0.pre.21 app/models/job/checkout_processor.rb
artfully_ose-1.2.0.pre.20 app/models/job/checkout_processor.rb
artfully_ose-1.2.0.pre.19 app/models/job/checkout_processor.rb
artfully_ose-1.2.0.pre.18 app/models/job/checkout_processor.rb
artfully_ose-1.2.0.pre.17 app/models/job/checkout_processor.rb
artfully_ose-1.2.0.pre.16 app/models/job/checkout_processor.rb