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
72
73
74
75
76
|
# File 'lib/friendly_shipping/services/ups_json/generate_rates_payload.rb', line 7
def self.call(shipment:, options:)
payload =
{
RateRequest: {
PickupType: {
Code: options.pickup_type_code
},
CustomerClassification: {
Code: options.customer_classification_code
},
Shipment: {
Shipper: GenerateAddressHash.call(location: options.shipper || shipment.origin, international: international?(shipment), shipper_number: options.shipper_number),
ShipTo: GenerateAddressHash.call(location: shipment.destination, international: international?(shipment)),
ShipFrom: GenerateAddressHash.call(location: shipment.origin),
PaymentDetails: {
ShipmentCharge: [
{
Type: "01", BillShipper: {
AccountNumber: options.shipper_number
}
}
]
},
NumOfPieces: shipment.packages.count
}
}
}
if options.customer_context.present?
payload[:RateRequest][:Request] = { TransactionReference: { CustomerContext: options.customer_context } }
end
payload[:RateRequest][:Shipment][:Package] = shipment.packages.map do |package|
package_options = options.options_for_package(package)
transmit_dimensions = package_options.transmit_dimensions || false
GeneratePackageHash.call(
package: package,
package_flavor: 'rates',
transmit_dimensions: transmit_dimensions
)
end
if options.pickup_date && options.sub_version.to_i >= 2205
payload[:RateRequest][:Shipment][:DeliveryTimeInformation] = {
PackageBillType: "03", Pickup: {
Date: options.pickup_date.strftime('%Y%m%d'),
Time: options.pickup_date.strftime('%H%M%S')
}
}
end
if options.shipping_method
payload[:RateRequest][:Shipment][:Service] = { Code: options.shipping_method.service_code }
end
payload[:RateRequest][:Shipment][:ShipmentServiceOptions] = {
UPScarbonneutralIndicator: options.carbon_neutral,
SaturdayDelivery: options.saturday_delivery,
SaturdayPickup: options.saturday_pickup
}.compact
if options.negotiated_rates
payload[:RateRequest][:Shipment][:ShipmentRatingOptions] ||= {}
payload[:RateRequest][:Shipment][:ShipmentRatingOptions][:NegotiatedRatesIndicator] = "X"
end
payload
end
|