Class: FriendlyShipping::Services::ShipEngine::CustomsItemsSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly_shipping/services/ship_engine/customs_items_serializer.rb

Overview

Serializes customs items for international labels.

Class Method Summary collapse

Class Method Details

.call(packages, options) ⇒ Array<Hash>

Returns the serialized customs items.

Parameters:

  • packages (Array<Physical::Package>)

    the packages to serialize

  • options (LabelOptions)

    options for the packages

Returns:

  • (Array<Hash>)

    the serialized customs items



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/friendly_shipping/services/ship_engine/customs_items_serializer.rb', line 12

def call(packages, options)
  packages.map do |package|
    package.items.group_by(&:sku).map do |sku, items|
      reference_item = items.first
      package_options = options.options_for_package(package)
      item_options = package_options.options_for_item(reference_item)
      {
        sku: sku,
        description: reference_item.description,
        quantity: items.count,
        value: {
          amount: reference_item.cost.to_d,
          currency: reference_item.cost.currency.to_s
        },
        harmonized_tariff_code: item_options.commodity_code,
        country_of_origin: item_options.country_of_origin
      }
    end
  end.flatten
end