Skip to content
This repository has been archived by the owner on Jun 13, 2018. It is now read-only.

canada_post_pws - undefined method `[]' for Seattle, WA, 98109 United States:ActiveMerchant::Shipping::Location #105

Closed
ericbrooke opened this issue Aug 20, 2013 · 4 comments · Fixed by #108

Comments

@ericbrooke
Copy link

block in sanitize_zipactive_shipping (0.10.0) lib/active_shipping/shipping/carriers/canada_post_pws.rb

742 def sanitize_zip(hash)
743 [:postal_code, :zip].each do |attr|
744 hash[attr].gsub!(/\s+/,'') if hash[attr]
745 end
746 hash
747 end

attr :postal_code
hash Seattle, WA, 98109 United States

88 responseCP = @cp.find_rates(origin, destination, packages)

@jnormore
Copy link
Contributor

Looks like you're passing a string for the origin param when it should be a hash, please see https://github.com/Shopify/active_shipping/blob/master/test/unit/carriers/canada_post_pws_rating_test.rb for usage examples

@ericbrooke
Copy link
Author

So is this another difference between the carriers? As the same data works for UPS, and this is how I am initializing origin..

   origin = ActiveMerchant::Shipping::Location.new(:country => leave.country,:province => leave.province,:city => leave.city,:zip => leave.post_code)

Full data build:

# Build Active shipping objects

   specs = Package.find(shipment.package_id)
   package = ActiveMerchant::Shipping::Package.new(specs.weight,[specs.height,specs.length,specs.width])

   leave = Location.find(shipment.source_id)
   arrive = Location.find(shipment.destination_id)

   origin = ActiveMerchant::Shipping::Location.new(:country => leave.country,:province => leave.province,:city => leave.city,:zip => leave.post_code)
   destination = ActiveMerchant::Shipping::Location.new(:country => arrive.country,:province => arrive.province,:city => arrive.city,:zip => arrive.post_code)

@jnormore jnormore reopened this Aug 20, 2013
@jnormore
Copy link
Contributor

right, I see you are passing a location object now, this is a difference. will look into this later today

@ericbrooke
Copy link
Author

Thanks Jason. It appears that my hash is being converted into a string by Location

Seattle, WA, 98109 United States

its seems to be missing a comma after the zip code

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants