Class: SpreeStripe::TaxPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/spree_stripe/tax_presenter.rb

Constant Summary collapse

SHIPPING_TAX_CODE =
'txcd_92010001'.freeze
TAX_BEHAVIOR =
'exclusive'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order:) ⇒ TaxPresenter



6
7
8
# File 'app/presenters/spree_stripe/tax_presenter.rb', line 6

def initialize(order:)
  @order = order
end

Instance Attribute Details

#orderObject (readonly)

Returns the value of attribute order.



10
11
12
# File 'app/presenters/spree_stripe/tax_presenter.rb', line 10

def order
  @order
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/presenters/spree_stripe/tax_presenter.rb', line 12

def call
  {
    currency: order.currency.downcase,
    line_items: build_line_items_attributes(order.line_items),
    customer_details: {
      address: build_address_attributes(order.tax_address),
      address_source: 'shipping',
    },
    shipping_cost: {
      amount: calculate_shipping_cost(order.shipments),
      tax_behavior: TAX_BEHAVIOR,
      tax_code: SHIPPING_TAX_CODE
    },
    expand: [
      'line_items.data.tax_breakdown',
      'shipping_cost.tax_breakdown'
    ]
  }
end