Class: Spree::PaypalPlatform::CaptureOrder
- Inherits:
-
Object
- Object
- Spree::PaypalPlatform::CaptureOrder
- 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
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#gateway ⇒ Object
readonly
Returns the value of attribute gateway.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#paypal_order ⇒ Object
readonly
Returns the value of attribute paypal_order.
Instance Method Summary collapse
- #call ⇒ Spree::PaypalPlatform::Order
-
#initialize(paypal_order:) ⇒ CaptureOrder
constructor
A new instance of CaptureOrder.
Constructor Details
#initialize(paypal_order:) ⇒ CaptureOrder
Returns a new instance of CaptureOrder.
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
#amount ⇒ Object (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 |
#gateway ⇒ Object (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 |
#order ⇒ Object (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_order ⇒ Object (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
#call ⇒ Spree::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 |