Business::CanadaPost - A module to fetch shipping costs for Canada Post.
#initialise object - specifying from postal code, and canada post merchant id
my $shiprequest = Business::CanadaPost->new( merchantid => 'CPC_DEMO_XML',
frompostal => 'M1P1C0',
testing => 1 );
# add an item to be shipped
$shiprequest->additem(quantity => 1,
height => 60,
width => 15,
length => 60,
weight => 7,
description => 'box o stuff',
readytoship => 1);
# set more parameters on the item being shipped
$shiprequest->getrequest() || print "Failed sending request: " . $shiprequest->geterror() . "\n";
print "There are " . $shiprequest->getoptioncount() . " available shipping methods.\n";
Business::CanadaPost is a Perl library created to allow users to fetch real-time options and pricing quotes on shipments sent from Canada using Canada Post.
To get off of the development server, you'll need to get an account from Canada Post's "Sell Online" service. While testing, use user id CPC_DEMO_XML and specify a parameter of 'testing' with a value of 1 to the new() constructor, so it knows to use Canada Post's devel server. If you don't, and don't have an account, you'll only receive errors.
This module requires strict, Exporter, and LWP.
Creates a new Business::CanadaPost object. Different objects available are:
'en' for English, and 'fr' for French. (Default: en)
This is used to override the setting in our sell online profile for the from address you would be shipping from. Format is A1A1A1 (A being any upper-case character between A-Z, and 1 being any digit 0-9)
If not specified, it will default to your setting in your Canada Post Sell Online(tm) profile.
Your turnaround time in hours. This is the amount of time between receiving the order and shipping it out. It is used to create a shipping and delivery date for the item. If none is specified, it will default to what you have set in your profile.
If you have nothing set in your profile, it will assume you are shipping next-day.
This is your merchant ID assigned to you by Canada Post. It usually begins with CPC_. You can use CPC_DEMO_XML if you're testing and using Canada Post's test servers. (Default: none. You need to set this or the module will return a fatal error.)
Total value of the shipment you're mailing. This is used to calculate whether or not a signature will be required, and whether it will need to include more insurance to cover the item (beyond the $100 included in the original shipment.) (Default: 0.00)
Possible values are 'metric' and 'imperial'.
If set to metric, you will be specifying height, length, and width in cm, and weight in kg.
If set to imperial, you will be specifying height, length, and width in in, and weight in lb.
Possible values: 1 or 0.
Specifies whether you're using a production account, or a testing account. If you're in testing mode, you'll be connecting to Canada Post's test servers, which run on less stable hardware, on a slower link to the Internet, and are rate-throttled.
An array containing the items in your shipment. Array elements are:
(quantity, weight, length, width, height, description, readytoship [1 or 0])
readytoship specifies that you have the item already boxed or prepared for shipment.
If this is set to 0, then Canada Post server's will calculate the most appropriate box listed in your account profile, and use it for its dimensions and shipping cost.
Most errors are fatal. The tool tries to guess for you if a value seems out of whack.
Used to fetch the error set when a function return 0 for failure.
$object->getrequest or print "Error: " . $object->geterror() . "\n";
Used to change the language.
$object->setlanguage('fr'); # changes messages to french.
Specifies city being shipped to.
Specifies whether account is in testing.
Specifies country being mailed to.
Specifies Canada Post merchant ID.
Specifies imperial or metric measurements.
Specifies postal code item is being shipped from.
$object->setfrompostalcode(''); # will reset postal code back to default set in canada post profile
Specifies postal code/zip code item is being shipped to.
Specifies province/state being shipped to.
Specifies turnaround time in hours.
Specifies total value of items being shipped.
Adds an item to be shipped to the request.
$object->additem(length => 5,
height => 3,
width => 2,
weight => 5,
description => "box of cookies",
readytoship => 1,
quantity => 1);
Weight, length, height, and width are the only requirements.
If not specified, quantity will default to 1, readytoship will default to 0, and description will default to an empty string.
Builds request, sends it to Canada Post, and parses the results.
returns 1 on success.
Returns number of available shipping options.
my $available_options = $object->getoptioncount();
Returns 1 or 0 based on whether or not a signature would be required for these deliveries.
my $signature_required = $object->getsignature();
Returns 1 or 0 based on whether or not extra insurance coverage is required (and included) in prices.
my $insurance_included = $object->getinsurance();
Receives an option number between 1 and $object->getoptioncount() and returns that option's name.
print "First option available is: " . $object->getshipname(1) . "\n";
Operates the same as getshipname, but returns cost of that shipping method.
print "First option would cost: " . $object->getshiprate(1) . " to ship.\n";
Operates the same as getshipname, but returns assumed shipment date.
print "Item would be shipped out on " . $object->getshipdate(1) . "\n";
Operates the same as getshipname, but returns when the approximate delivery date would be based on a shipping date of $object->getshipdate();
print "Assuming a delivery date of " . $object->getshipdate(1) .
", this item would arrive on: " . $object->getdelvdate(1) . "\n";
Operates the same as getshipname, but returns which day of the week $object->getdelvdate() lands on numerically. (1 .. 6; 1 == Sunday, 6 == Saturday)
print "Your item would likely be delivered on the " .
$object->getdayofweek(1) . " day of the week.\n";
Operates the same as getshipname, but returns whether or not the current option provides for next day AM delivery service.
printf("This item is %savailable for next day delivery\n",
$object->getnextdayam(1) == 1 ? '' : 'NOT ');
Operates the same as getshipname, but returns estimated number of days required to ship the item.
print "This shipping method would take approximately: " . $object->getestshipdays() .
" days to arrive.\n";
Returns whether or not delivery confirmation is included in price quotes.
my $confirmation_included = $object->getconfirmation();
Returns any extra comments Canada Post might include with your quote.
my $extra_info = $object->getcomments();
Probably lots. E-mail me at <firstname.lastname@example.org> should you locate any.
This module was written by Justin Wheeler <email@example.com> Feel free to e-mail me with any comments/questions/concerns/ideas/etc.
For more information on how Canada Post's XML shipping system works, please see http://188.8.131.52/DevelopersResources
Copyright (C) 2005 Justin Wheeler / datademons
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details, available at http://www.gnu.org/licenses/gpl.html.
1 POD Error
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
To install Business::CanadaPost, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.