NAME

Shipment::CanadaPost

VERSION

version 3.10

SYNOPSIS

use Shipment::CanadaPost;
use Shipment::Address;
use Shipment::Package;

my $shipment = Shipment::CanadaPost->new(
  from_address => Shipment::Address->new( ... ),
  to_address => Shipment::Address->new( ... ),
  packages => [ Shipment::Package->new( ... ), ],
);

foreach my $service ( $shipment->all_services ) {
  print $service->id . " (" . $service->cost . ")\n";
}

$shipment->rate( 'express' );
print $shipment->service->cost . "\n";

$shipment->ship( 'ground' );
$shipment->get_package(0)->label->save;

NAME

Shipment::CanadaPost - Interface to Canada Post Web Services API

ABOUT

This class provides an interface to the Canada Post Web Services API. You must sign up for a developer access key in order to make use of this module.

https://www.canadapost-postescanada.ca/information/app/drc/home

It is an extension of Shipment::Base.

Class Attributes

username, password

Credentials required to access Canada Post Web Services

endpoint

This determines whether you will use the development or production environment * ct.soa-gw.canadapost.ca (development) * soa-gw.canadapost.ca (production)

contract_id

The Canada Post contract number which unlocks restricted services, negotiated rates, and payment accounts

currency

Only CAD currency is supported

customs_currency, customs_conversion, customs_reason

Currency, conversion rate and reason used for customs clearance

Default: CAD

non-delivery handling

RASE - Return at Sender's Expense RTS - Return to Sender ABAN - Abandon

Default: RTS

services_rates

get rates when building services

Class Methods

_messages

Parse a web services xml messages response and return as text

_build_services

This calls DiscoverServices or GetRates (if services_rates attribute is set))

Defaults to shipping to Canada

Each service that is returned is added to services

The following service mapping is used: * ground => DOM.RP / DOM.EP (Regular/Expedited Parcel) USA.TP / USA.EP (USA Tracked Packet / Expedited Parcel) or INT.TP / INT.IP.AIR / INT.IP.SURF (International Tracked Packet / Parcel) / INT.XP * express => DOM.XP / USA.XP / INT.XP (Xpresspost) * priority => DOM.PC (Priority) or INT.PW.PARCEL (Priority Worldwide)

This method ignores what is in $self->packages and uses a single package weighing 1 pound for rating. The idea is to list what services are available, but for accurate rating, the rate method should be used.

rate

This calls the GetRates service for the selected service id

ship

This method calls the CreateShipment service

Manifests are not supported, transmit-shipment is always set to true

cpc-pickup-indicator is always set to true with the requested-shipping-point set to the from postal code

Only payment on account is currently supported

Note: this method calls the curl binary instead of using LWP::UserAgent or Net::Curl due to a bug in the Canada Post API shipping service endpoint. It also writes the xml to a temporary file.

AUTHOR

Andrew Baerg @ <andrew at pullingshots dot ca>

http://pullingshots.ca/

BUGS

Please contact me directly.

COPYRIGHT

Copyright (C) 2021 Andrew J Baerg, All Rights Reserved

NO WARRANTY

Absolutely, positively NO WARRANTY, neither express or implied, is offered with this software. You use this software at your own risk. In case of loss, no person or entity owes you anything whatsoever. You have been warned.

LICENSE

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Andrew Baerg <baergaj@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2018 by Andrew Baerg.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.