Step 1: Build the string request that will be sent to Sell Online
' The string is XML formatted and will contain
' information such as destination address and
' the list of items the consumer ordered
'
' TO DO : BUILD YOUR XML STRING HERE
' Important Note:
' --------------
' This sample is using merchant ID: "CPC_DEMO_HTML"
' Instead, you should use the merchant ID assigned to you by
' Canada Post -and- make sure that your profile is configured
' to return HTML (otherwise, you will receive XML and need an XML parser
' to understand it).
Dim xmlRequest
xmlRequest = "
en
CPC_DEMO_HTML
-
1
1.5
1
1
1
My Sample Item
Wisconsin
CANADA
H3K1E5
"
Step 2: The request has to be sent to Sell Online via an HTTP(S) POST request.
Below is the sample request in perl for sending HTTP(S) POST request.
#!/usr/bin/perl
use strict;
use warnings;
use LWP;
my $message = do {
open my $fh, '<', 'Request.xml' or die "Could not open file: $!";
local $/;
<$fh>;
};
my $url = 'https://qa-sellonline.canadapost.ca/sellonline/Rating';
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 });
$ua->proxy(qw/ http proxy:8080 /);
$ua->no_proxy('localhost');
my $req = HTTP::Request->new(POST => $url);
$req->header(Host => 'sellonline.canadapost.ca/sellonline/Rating');
$req->content_type('application/xml; charset=utf-8');
$req->content($message);
$req->authorization_basic('TransportUser', 'TransportUser');
my $response = $ua->request($req);
my $content = $response->decoded_content;
print $content;
Step 3 : Incorporate the response in your application page. Below is the sample response from sell online :
1
OK
1
1.0
0
Expedited
21.99
2018-09-10
2018-09-11
3
false
P_0
Regular
22.12
2018-09-10
2018-09-13
5
false
P_0
P_0
My Sample Item
2.0
1.5
30.0
20.0
20.0
1
My Sample Item
No
Yes
No