Skip to content

Ximik/CanadaPost

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A Simple Ruby Class that communicates with Canada Post Server and provides a shipping estimate.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages