active_shipping icon indicating copy to clipboard operation
active_shipping copied to clipboard

Stamps#find_rates does not accept multiple packages?

Open stephen-puiszis opened this issue 9 years ago • 0 comments

I'm need to integrate with multiple carriers for shipping estimates and have run into some inconsistencies. The one of most concern is ::Stamps#find_rates not accepting multiple packages, while UPS / FedEx accept multiple packages. Is this an intentional design decision based on the Stamps.com API? I'm going through their documentation and am not seeing anything related. Would supporting Stamps.com with multiple packages be as simple as adding something similar to ::UPS#build_package_nodes? (everything below is copied and linked to the respective file on master)

Stamps

    def find_rates(origin, destination, package, options = {})
      origin = standardize_address(origin)
      destination = standardize_address(destination)
      request = build_rate_request(origin, destination, package, options)
      commit(:GetRates, request)
    end

UPS:

   def find_rates(origin, destination, packages, options = {})
      origin, destination = upsified_location(origin), upsified_location(destination)
      options = @options.merge(options)
      packages = Array(packages)
      access_request = build_access_request
      rate_request = build_rate_request(origin, destination, packages, options)
      response = commit(:rates, save_request(access_request + rate_request), options[:test])
      parse_rate_response(origin, destination, packages, response, options)
    end

FedEx

def find_rates(origin, destination, packages, options = {})
      options = @options.merge(options)
      packages = Array(packages)

      rate_request = build_rate_request(origin, destination, packages, options)

      xml = commit(save_request(rate_request), (options[:test] || false))

      parse_rate_response(origin, destination, packages, xml, options)
    end

UPS#build_package_nodes

    build_packages_nodes(xml, packages, imperial)

    def build_packages_nodes(xml, packages, imperial)
      packages.map do |pkg|
        xml.RequestedPackageLineItems do
          xml.GroupPackageCount(1)
          build_package_weight_node(xml, pkg, imperial)
          build_package_dimensions_node(xml, pkg, imperial)
        end
      end
    end
end

stephen-puiszis avatar May 10 '16 21:05 stephen-puiszis