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.