Class: FriendlyShipping::Services::Ups::SerializeRatingServiceSelectionRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly_shipping/services/ups/serialize_rating_service_selection_request.rb

Class Method Summary collapse

Class Method Details

.call(shipment:, options:) ⇒ Object



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
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/friendly_shipping/services/ups/serialize_rating_service_selection_request.rb', line 11

def self.call(shipment:, options:)
  shipper = options.shipper || shipment.origin

  xml_builder = Nokogiri::XML::Builder.new do |xml|
    xml.RatingServiceSelectionRequest do
      xml.Request do
        xml.RequestAction('Rate')
        # If no shipping method is given, request all of them
        # I one is given, omit the request option. It then becomes "Rate", the default.
        xml.RequestOption('Shop') unless options.shipping_method
        xml.SubVersion('1707')
        # Optional element to identify transactions between client and server.
        if options.customer_context
          xml.TransactionReference do
            xml.CustomerContext(options.customer_context)
          end
        end
      end

      xml.PickupType do
        xml.Code(options.pickup_type_code)
      end
      xml.CustomerClassification do
        xml.Code(options.customer_classification_code)
      end

      xml.Shipment do
        # not implemented: Shipment/Description element
        xml.Shipper do
          SerializeAddressSnippet.call(xml: xml, location: shipper)

          xml.ShipperNumber(options.shipper_number)
        end

        xml.ShipTo do
          SerializeAddressSnippet.call(xml: xml, location: shipment.destination)

          if options.
            xml.ShipperAssignedIdentificationNumber(options.)
          end
        end

        if shipper != shipment.origin
          xml.ShipFrom do
            SerializeAddressSnippet.call(xml: xml, location: shipment.origin)
          end
        end

        shipment.packages.each do |package|
          package_options = options.options_for_package(package)
          SerializePackageNode.call(
            xml: xml,
            package: package,
            transmit_dimensions: package_options.transmit_dimensions
          )
        end

        if options.shipping_method
          xml.Service do
            xml.Code options.shipping_method.service_code
          end
        end

        xml.ShipmentServiceOptions do
          xml.UPScarbonneutralIndicator if options.carbon_neutral
          xml.SaturdayDelivery if options.saturday_delivery
          xml.SaturdayPickup if options.saturday_pickup
        end

        if options.negotiated_rates
          xml.RateInformation do
            xml.NegotiatedRatesIndicator if options.negotiated_rates
          end
        end
      end
    end
  end
  xml_builder.to_xml
end