Class: Workarea::Paypal::ApproveOrder

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

Instance Method Summary collapse

Constructor Details

#initialize(checkout, paypal_id) ⇒ ApproveOrder



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

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

Instance Method Details

#approved?Boolean



43
44
45
# File 'app/services/workarea/paypal/approve_order.rb', line 43

def approved?
  status == 'APPROVED' || direct_payment?
end

#detailsObject

As of this writing, PayPal only ever allows one purchase unit.



18
19
20
# File 'app/services/workarea/paypal/approve_order.rb', line 18

def details
  purchase_units.first
end

#paypal_orderObject



12
13
14
# File 'app/services/workarea/paypal/approve_order.rb', line 12

def paypal_order
  @paypal_order ||= Workarea::Paypal.gateway.get_order(@paypal_id).result
end

#performObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/services/workarea/paypal/approve_order.rb', line 22

def perform
  order.email ||= payer&.email_address

  set_shipping_address
  set_shipping_service
  set_billing_address

  payment.clear_credit_card
  payment.set_paypal(
    direct_payment_details.reverse_merge(
      paypal_id: @paypal_id,
      approved: true, #approved?
      payer_id: payer&.payer_id,
      details:  Paypal.transform_values(paypal_order)
    )
  )

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