Class: SolidusAfterpay::ShippingRateBuilderService

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/solidus_afterpay/shipping_rate_builder_service.rb

Instance Method Summary collapse

Methods inherited from BaseService

call

Constructor Details

#initialize(order:) ⇒ ShippingRateBuilderService

Returns a new instance of ShippingRateBuilderService.



5
6
7
8
9
# File 'app/services/solidus_afterpay/shipping_rate_builder_service.rb', line 5

def initialize(order:)
  @order = order

  super()
end

Instance Method Details

#callObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/solidus_afterpay/shipping_rate_builder_service.rb', line 11

def call
  order.shipments.map do |shipment|
    shipment.shipping_rates.map do |rate|
      shipping_rate_presenter = SolidusAfterpay::ShippingRatePresenter.new(shipping_rate: rate)

      {
        id: rate.id.to_s,
        name: rate.name,
        description: rate.display_price,
        shipping_amount: shipping_rate_presenter.amount_with_taxes.round(4).to_s,
        currency: rate.currency,
        order_amount: shipping_rate_presenter.order_amount.round(4).to_s
      }
    end
  end.flatten
end