Class: Workarea::Paypal::Update

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order, payment, shipping, token) ⇒ Update

Returns a new instance of Update.



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

def initialize(order, payment, shipping, token)
  @order = order
  @payment = payment
  @shipping = shipping
  @token = token
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order.



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

def order
  @order
end

#paymentObject (readonly)

Returns the value of attribute payment.



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

def payment
  @payment
end

#shippingObject (readonly)

Returns the value of attribute shipping.



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

def shipping
  @shipping
end

#tokenObject (readonly)

Returns the value of attribute token.



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

def token
  @token
end

Instance Method Details

#applyObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/workarea/paypal/update.rb', line 17

def apply
  order.email ||= details.email
  set_shipping_address(details.params)
  set_shipping_service
  set_billing_address(details.params)

  payment.clear_credit_card
  payment.set_paypal(
    token:    details.token,
    payer_id: details.payer_id,
    details:  details.params
  )

  Pricing.perform(order, shipping)
  payment.adjust_tender_amounts(order.total_price)
end

#detailsObject



13
14
15
# File 'app/services/workarea/paypal/update.rb', line 13

def details
  @details ||= Workarea::Paypal.gateway.details_for(token)
end