Class: Workarea::Zipco::Checkout

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/zipco/checkout.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(checkout, user, options = {}) ⇒ Checkout

Returns a new instance of Checkout.

Parameters:

  • ::Workarea::Order


7
8
9
10
11
12
# File 'app/services/workarea/zipco/checkout.rb', line 7

def initialize(checkout, user, options = {})
  @checkout = checkout
  @user = user
  @options = options
  @order = Workarea::Order.where(zipco_order_id: zipco_order_id).first
end

Instance Attribute Details

#checkoutObject (readonly)

Returns the value of attribute checkout.



4
5
6
# File 'app/services/workarea/zipco/checkout.rb', line 4

def checkout
  @checkout
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'app/services/workarea/zipco/checkout.rb', line 4

def options
  @options
end

#orderObject (readonly)

Returns the value of attribute order.



4
5
6
# File 'app/services/workarea/zipco/checkout.rb', line 4

def order
  @order
end

#userObject (readonly)

Returns the value of attribute user.



4
5
6
# File 'app/services/workarea/zipco/checkout.rb', line 4

def user
  @user
end

Instance Method Details

#completeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/workarea/zipco/checkout.rb', line 14

def complete
  approved_referred_order = result == "approved" && order.zipco_referred?

  if result == "referred"
    order.set_zipco_referred_at!
  else
    order.update_attributes(zipco_referred_at: nil)
  end

  order.user_id = user.try(:id)

  Workarea::Pricing.perform(order, checkout.shipping)
  checkout.payment.adjust_tender_amounts(order.total_price)

  if order.zipco_referred?
    checkout.handle_zipco_referred
  elsif approved_referred_order
    checkout.handle_zipco_approved_referred
  else
    checkout.place_order
  end
end