Class: Spree::PaypalPlatform::CaptureOrder

Inherits:
Object
  • Object
show all
Defined in:
app/services/spree/paypal_platform/capture_order.rb

Overview

Captures a legacy Order via the PayPal Orders API and completes the Spree checkout.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paypal_order:) ⇒ CaptureOrder

Returns a new instance of CaptureOrder.

Parameters:



13
14
15
16
17
18
# File 'app/services/spree/paypal_platform/capture_order.rb', line 13

def initialize(paypal_order:)
  @paypal_order = paypal_order
  @order = paypal_order.order
  @gateway = paypal_order.gateway
  @amount = paypal_order.amount
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



20
21
22
# File 'app/services/spree/paypal_platform/capture_order.rb', line 20

def amount
  @amount
end

#gatewayObject (readonly)

Returns the value of attribute gateway.



20
21
22
# File 'app/services/spree/paypal_platform/capture_order.rb', line 20

def gateway
  @gateway
end

#orderObject (readonly)

Returns the value of attribute order.



20
21
22
# File 'app/services/spree/paypal_platform/capture_order.rb', line 20

def order
  @order
end

#paypal_orderObject (readonly)

Returns the value of attribute paypal_order.



20
21
22
# File 'app/services/spree/paypal_platform/capture_order.rb', line 20

def paypal_order
  @paypal_order
end

Instance Method Details

#callSpree::PaypalPlatform::Order



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/services/spree/paypal_platform/capture_order.rb', line 25

def call
  return paypal_order if order.completed? || order.canceled?

  gateway_response = gateway.capture(
    (amount.to_d * 100).to_i,
    paypal_order.paypal_id,
    { order_id: order.number }
  )

  order.with_lock do
    paypal_order.update!(data: gateway_response.params)
    paypal_order.create_payment!
    Spree::Dependencies.checkout_complete_service.constantize.call(order: order)
  end

  paypal_order
end