7
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/friendly_shipping/services/ups/serialize_package_node.rb', line 7
def self.call(
xml:,
package:,
reference_numbers: {},
delivery_confirmation_code: nil,
shipper_release: false,
transmit_dimensions: true,
declared_value: false
)
xml.Package do
xml.PackagingType do
xml.Code('02')
end
if package.items.any?(&:description)
xml.Description(package.items.map(&:description).compact.join(', '))
end
if transmit_dimensions && package.dimensions.all? { |dim| !dim.value.zero? && !dim.value.infinite? }
xml.Dimensions do
xml.UnitOfMeasurement do
xml.Code('IN')
end
xml.Length(package.length.convert_to(:inches).value.to_f.round(3))
xml.Width(package.width.convert_to(:inches).value.to_f.round(3))
xml.Height(package.height.convert_to(:inches).value.to_f.round(3))
end
end
xml.PackageWeight do
xml.UnitOfMeasurement do
xml.Code('LBS')
end
xml.Weight([package.weight.convert_to(:pounds).value.to_f.round(2).ceil, 1].max)
end
xml.PackageServiceOptions do
if shipper_release
xml.ShipperReleaseIndicator
end
if delivery_confirmation_code
xml.DeliveryConfirmation do
xml.DCISType(delivery_confirmation_code)
end
end
if declared_value
xml.DeclaredValue do
xml.CurrencyCode('USD')
monetary_value = package.items.inject(Money.new(0, 'USD')) do |package_sum, item|
package_sum + (item.cost || Money.new(0, 'USD'))
end
xml.MonetaryValue(monetary_value)
end
end
end
reference_numbers.each do |reference_code, reference_number|
xml.ReferenceNumber do
xml.Code(reference_code)
xml.Value(reference_number)
end
end
end
end
|