Class: Spree::PaypalPlatform::OrderPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/spree/paypal_platform/order_presenter.rb

Overview

Builds a PayPal Orders API create-order payload from a Spree order.

The storefront owns the address: we send purchase_units[].shipping from order.ship_address and pin it with SET_PROVIDED_ADDRESS so PayPal does not re-collect it. The amount breakdown sends only additional_tax_total — sending full tax_total double-counts included VAT and trips PayPal AMOUNT_MISMATCH.

Constant Summary collapse

PAYPAL_ITEM_NAME_MAX_LENGTH =
127

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ OrderPresenter

Returns a new instance of OrderPresenter.

Parameters:

  • order (Spree::Order)


22
23
24
# File 'app/presenters/spree/paypal_platform/order_presenter.rb', line 22

def initialize(order)
  @order = order
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order.



26
27
28
# File 'app/presenters/spree/paypal_platform/order_presenter.rb', line 26

def order
  @order
end

Instance Method Details

#to_json(*_args) ⇒ Hash

Returns body ready for client.orders.create_order.

Returns:

  • (Hash)

    body ready for client.orders.create_order



31
32
33
34
35
36
37
38
39
# File 'app/presenters/spree/paypal_platform/order_presenter.rb', line 31

def to_json(*_args)
  {
    'body' => PaypalServerSdk::OrderRequest.new(
      intent: PaypalServerSdk::CheckoutPaymentIntent::CAPTURE,
      purchase_units: [purchase_unit],
      payment_source: payment_source
    )
  }
end