Class: Spree::PaypalPlatform::Order
- Defined in:
- app/models/spree/paypal_platform/order.rb
Overview
A persisted PayPal Orders API response, used by the legacy
/api/v2/storefront/paypal_orders flow.
Payment-session hosts do not write this table; they keep the same
payload on Spree::PaymentSession#external_data.
Defined Under Namespace
Classes: AlreadyCapturedError, NotCapturedError
Instance Method Summary collapse
-
#capture! ⇒ Spree::PaypalPlatform::Order
Capture the PayPal order via the Orders API.
- #completed? ⇒ TrueClass, FalseClass
-
#create_payment! ⇒ Spree::Payment
Create a Spree::Payment for this captured PayPal order.
-
#paypal_order ⇒ PaypalServerSdk::ApiResponse
Fresh PayPal order from the API.
-
#paypal_payment_id ⇒ String, NilClass
Capture ID from the stored payload.
Instance Method Details
#capture! ⇒ Spree::PaypalPlatform::Order
Capture the PayPal order via the Orders API.
51 52 53 54 55 |
# File 'app/models/spree/paypal_platform/order.rb', line 51 def capture! raise AlreadyCapturedError if completed? CaptureOrder.new(paypal_order: self).call end |
#completed? ⇒ TrueClass, FalseClass
78 79 80 |
# File 'app/models/spree/paypal_platform/order.rb', line 78 def completed? status == 'COMPLETED' end |
#create_payment! ⇒ Spree::Payment
Create a Spree::Payment for this captured PayPal order.
34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/spree/paypal_platform/order.rb', line 34 def create_payment! raise NotCapturedError unless completed? CreatePayment.new( order: order, paypal_order: self, gateway: payment_method, amount: amount ).call end |
#paypal_order ⇒ PaypalServerSdk::ApiResponse
Fresh PayPal order from the API.
71 72 73 |
# File 'app/models/spree/paypal_platform/order.rb', line 71 def paypal_order @paypal_order ||= gateway.client.orders.get_order({ 'id' => paypal_id }) end |
#paypal_payment_id ⇒ String, NilClass
Capture ID from the stored payload. Only present after capture.
62 63 64 |
# File 'app/models/spree/paypal_platform/order.rb', line 62 def paypal_payment_id @paypal_payment_id ||= data.dig('purchase_units', 0, 'payments', 'captures', 0, 'id') end |