0.0
No commit activity in last 3 years
No release in over 3 years
A Simple Ruby Class that communicates with Canada Post Server and provides a shipping estimate.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Canada Post¶ ↑

Canada Post PHP Class will communicates with Canada Post Server and gets the shipping estimate. Its basic and can be extended.

How to Use¶ ↑

As per Canada Post’s specification, make sure Port 30000 is opened.

At first require the gem.

require 'canada_post'

cPost = CanadaPost.new

Set your manufacturer CPCID, postal code by calling the function setManufacturer

merchant = {
  :merchantCPCID => 'CPC_DEMO_XML',
  :fromPostalCode => 'L1JK9',
  :turnAroundTime => 24,
  :itemsPrice => 14
}
cPost.setMerchant merchant

Then set the Customer address in the format shown below, again in associative array format.

Note: city and provOrState are optional. Only Postal Code and country is required.

customer = {
  :city => 'Brampton',
  :provOrState => 'Ontario',
  :country => 'CA',        
  :postalCode => 'L1JK9'   
}
cPost.setCustomer customer

Then, add the products needed to be shipped (add as many as you want), in the format shown below:

item = {
  :quantity => 1,
  :weight => 2,
  :length => 3,
  :width => 1,
  :height => 8,
  :description => 'some Description about Product'
}
cPost.addItem item

Then, invoke the method below (returns XML format of details from Canada Post Server):

response = cPost.getRates

License¶ ↑

The gem is based on CanadaPost PHP class.

The script has been released under MIT License.