Class: SpreePaypalCheckout::Order
- Defined in:
- app/models/spree_paypal_checkout/order.rb
Defined Under Namespace
Classes: AlreadyCapturedError, NotCapturedError
Instance Method Summary collapse
-
#capture! ⇒ SpreePaypalCheckout::Order
Capture the PayPal order in PayPal API.
- #completed? ⇒ Boolean
-
#create_payment! ⇒ Spree::Payment
Create a Spree::Payment record for this PayPal order.
-
#paypal_order ⇒ PaypalServerSdk::ApiResponse
gets the PayPal order from PayPal API.
-
#paypal_payment_id ⇒ String
gets the PayPal payment ID from the PayPal order only available for authorized or captured orders.
Instance Method Details
#capture! ⇒ SpreePaypalCheckout::Order
Capture the PayPal order in PayPal API
42 43 44 45 46 |
# File 'app/models/spree_paypal_checkout/order.rb', line 42 def capture! raise AlreadyCapturedError if completed? CaptureOrder.new(paypal_order: self).call end |
#completed? ⇒ Boolean
61 62 63 |
# File 'app/models/spree_paypal_checkout/order.rb', line 61 def completed? status == 'COMPLETED' end |
#create_payment! ⇒ Spree::Payment
Create a Spree::Payment record for this PayPal order
29 30 31 32 33 34 35 36 37 38 |
# File 'app/models/spree_paypal_checkout/order.rb', line 29 def create_payment! raise NotCapturedError unless completed? SpreePaypalCheckout::CreatePayment.new( order: order, paypal_order: self, gateway: payment_method, amount: amount ).call end |
#paypal_order ⇒ PaypalServerSdk::ApiResponse
gets the PayPal order from PayPal API
57 58 59 |
# File 'app/models/spree_paypal_checkout/order.rb', line 57 def paypal_order @paypal_order ||= gateway.client.orders.get_order({ 'id' => paypal_id }) end |
#paypal_payment_id ⇒ String
gets the PayPal payment ID from the PayPal order only available for authorized or captured orders
51 52 53 |
# File 'app/models/spree_paypal_checkout/order.rb', line 51 def paypal_payment_id @paypal_payment_id ||= data.dig('purchase_units', 0, 'payments', 'captures', 0, 'id') end |