Class: Spree::PaypalPlatform::Order

Inherits:
Base
  • Object
show all
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

Instance Method Details

#capture!Spree::PaypalPlatform::Order

Capture the PayPal order via the Orders API.

Returns:

Raises:



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

Returns:

  • (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.

Returns:

  • (Spree::Payment)

Raises:



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_orderPaypalServerSdk::ApiResponse

Fresh PayPal order from the API.

Returns:

  • (PaypalServerSdk::ApiResponse)


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_idString, NilClass

Capture ID from the stored payload. Only present after capture.

Returns:

  • (String, NilClass)


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