Class: FriendlyShipping::Services::ShipEngine::SerializeLabelShipment

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

Class Method Summary collapse

Class Method Details

.call(shipment:, options:, test:) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/friendly_shipping/services/ship_engine/serialize_label_shipment.rb', line 8

def call(shipment:, options:, test:)
  shipment_hash = {
    label_format: options.label_format,
    label_download_type: options.label_download_type,
    shipment: {
      service_code: options.shipping_method.service_code,
      ship_to: serialize_address(shipment.destination),
      ship_from: serialize_address(shipment.origin),
      packages: serialize_packages(shipment.packages, options)
    }
  }
  # A carrier might not be necessary if the service code is unique within ShipEngine.
  if options.shipping_method.carrier
    shipment_hash[:shipment][:carrier_id] = options.shipping_method.carrier.id
  end

  if international?(shipment)
    shipment_hash[:shipment][:customs] = serialize_customs(shipment.packages, options)
  end

  if test
    shipment_hash[:test_label] = true
  end

  if options.label_image_id
    shipment_hash[:label_image_id] = options.label_image_id
  end

  shipment_hash
end