The current Canada Post cancellation process appears to be broken. When Canada Post returns an empty message, Karrio incorrectly interprets it as a successful cancellation.
<?xml version="1.0" encoding="UTF-8"?><messages xmlns="http://www.canadapost.ca/ws/messages"/>
For contract shipping, Canada Post provides two types of cancellation processes:
For non-contract shipping, the cancellation process may differ, and Karrio needs to account for this difference. Non-contract shipments do not rely on manifests, so the logic should handle direct refund requests for these shipments.
The process to void a shipment involves the following steps:
Retrieve the shipment ID:
Call the following endpoint to get the shipment URL (including the shipment ID):
GET https://soa-gw.canadapost.ca/rs/{{canada_post_cust_number}}/{{canada_post_cust_number}}/shipment?trackingPIN={{canada_post_tracking_number}}
Sample Response:
<?xml version="1.0" encoding="UTF-8"?>
<shipments xmlns="http://www.canadapost.ca/ws/shipment-v8">
<link rel="shipment" href="https://soa-gw.canadapost.ca/rs/{{canada_post_cust_number}}/{{canada_post_cust_number}}/shipment/{{canada_post_shipment_id}}" media-type="application/vnd.cpc.shipment-v8+xml"/>
</shipments>
Note: The shipment ID is also returned when the shipment is initially created. (Karrio likely already has the ID saved)
Void the shipment:
Use the shipment ID from the previous step and make the following request:
DELETE https://soa-gw.canadapost.ca/rs/{{canada_post_cust_number}}/{{canada_post_cust_number}}/shipment/{{canada_post_shipment_id}}
204 No Content
status.<?xml version="1.0" encoding="UTF-8"?>
<messages xmlns="http://www.canadapost.ca/ws/messages">
<message>
<code>8064</code>
<description>A Shipment can only be void if it is in a PROCESSED or PRINTED state. If it has been transmitted, a Refund request should be submitted.</description>
</message>
</messages>
To cancel a shipment that has already been included in a manifest but not shipped, follow these steps:
Retrieve the shipment ID:
Similar to Scenario 1, use the following endpoint to get the shipment URL and ID:
GET https://soa-gw.canadapost.ca/rs/{{canada_post_cust_number}}/{{canada_post_cust_number}}/shipment?trackingPIN={{canada_post_tracking_number}}
Request a refund:
Use the shipment ID to call the following endpoint with an XML body:
POST https://soa-gw.canadapost.ca/rs/{{canada_post_cust_number}}/{{canada_post_cust_number}}/shipment/{{canada_post_shipment_id}}/refund
Sample Request Body:
<shipment-refund-request xmlns="http://www.canadapost.ca/ws/shipment-v8">
<email>[email protected]</email>
</shipment-refund-request>
<?xml version="1.0" encoding="UTF-8"?>
<messages xmlns="http://www.canadapost.ca/ws/messages">
<message>
<code>7292</code>
<description>A refund has already been requested for this shipment. Note that refund requests may take a few days to be processed.</description>
</message>
</messages>
For non-contract shipments, the cancellation process does not involve manifests, since these shipments are paid immediately upon label creation there's only one endpoint for Request Shipment Refund
204 No Content
response as a successful cancellation.Differentiate between contract and non-contract shipping:
Verify and handle responses:
204 No Content
response is treated as successful.<messages>
tags).Add support for refunds in manifested shipments (Scenario 2):
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too