Class: Workarea::Affirm::Update

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/affirm/update.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(checkout, checkout_token) ⇒ Update

Returns a new instance of Update.



6
7
8
9
# File 'app/services/workarea/affirm/update.rb', line 6

def initialize(checkout, checkout_token)
  @checkout = checkout
  @checkout_token = checkout_token
end

Instance Attribute Details

#checkoutObject (readonly)

Returns the value of attribute checkout.



4
5
6
# File 'app/services/workarea/affirm/update.rb', line 4

def checkout
  @checkout
end

#checkout_tokenObject (readonly)

Returns the value of attribute checkout_token.



4
5
6
# File 'app/services/workarea/affirm/update.rb', line 4

def checkout_token
  @checkout_token
end

Instance Method Details

#applyObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/workarea/affirm/update.rb', line 15

def apply
  payment = checkout.payment
  order = checkout.order

  payment.set_affirm(
    checkout_token: checkout_token,
    details: details.body
  )
  payment.adjust_tender_amounts(order.total_price)

  order.save && payment.save
end

#detailsObject



11
12
13
# File 'app/services/workarea/affirm/update.rb', line 11

def details
  @details ||= Affirm.gateway.get_checkout(checkout_token)
end