Lue dans les fichiers PHP du paquet au commit 870a2807eff7 : ses espaces de noms, classes, interfaces et énumérations, leurs constantes, propriétés et méthodes publiques avec leur PHPDoc, et les options que prennent ses fabriques. Rien n’en est exécuté.
ApiclassCanada Post's REST web services: XML in and out, basic auth with the API username and password.
5 methods · 3 properties · 2 constants
CanadaPostGatewayFactoryclassoptions: username: '%env(CANADA_POST_USERNAME)%' # API key's username and password (Developer Program) password: '%env(CANADA_POST_PASSWORD)%' customer_number: '%env(CANADA_POST_CUSTOMER)%' contract_id: null # a commercial contract, for contract shipping and rates sandbox: true # ct.soa-gw.canadapost.ca rates: [...] # optional: configured prices instead of Get Rates
10 options
MappingclassCanada Post's shapes for ours: kilograms, centimetres, postal codes without the space.
4 methods · 1 constant
PickupActionclassGet Nearest Post Office (GET /rs/postoffice): post offices near a Canadian address.
3 methods
RatingActionclassGet Rates (POST /rs/ship/price): every service for the parcel, with the contract's prices when there is one.
3 methods
ShippingActionclassA non-contract shipment (POST /rs/{customer}/ncshipment, paid by the card on file) or, with a contract, a contract shipment (POST /rs/{customer}/{customer}/shipment), then its label downloaded from the artifact link. Options: sender_province and recipient_province (two letters, Canadian addresses need them), label_format (PDF or ZPL).
3 methods
TrackingActionclassGet Tracking Detail (GET /vis/track/pin/{pin}/detail): the significant events, oldest first.
3 methods
Omnibus\CanadaPost
Api class
final class Api Api.php:11
Canada Post's REST web services: XML in and out, basic auth with the API username and password.
const LIVE = 'https://soa-gw.canadapost.ca'const TEST = 'https://ct.soa-gw.canadapost.ca'public readonly string $customerNumberpublic readonly ?string $contractIdpublic readonly bool $sandbox
Api::__construct()
public function __construct(readonly HttpClientInterface $http, readonly string $username, readonly string $password, public readonly string $customerNumber, public readonly ?string $contractId = null, public readonly bool $sandbox = false, readonly int $timeout = 20)Api::base()
public function base(): stringApi::call()
public function call(string $method, string $path, ?string $body, string $contentType, ?string $accept = null, string $locale = 'en-CA'): \SimpleXMLElement|stringOne call; XML back as a SimpleXMLElement without namespaces, or the raw bytes of a document.
Api::parse()
public static function parse(string $content): \SimpleXMLElementApi::contract()
public function contract(): boolCanadaPostGatewayFactory class
final class CanadaPostGatewayFactory extends GatewayFactory CanadaPostGatewayFactory.php:22
options: username: '%env(CANADA_POST_USERNAME)%' # API key's username and password (Developer Program) password: '%env(CANADA_POST_PASSWORD)%' customer_number: '%env(CANADA_POST_CUSTOMER)%' contract_id: null # a commercial contract, for contract shipping and rates sandbox: true # ct.soa-gw.canadapost.ca rates: [...] # optional: configured prices instead of Get Rates
Options
| Option | Default | |
|---|---|---|
contract_id | null | |
sandbox | false | |
omnibus.api | function (Config $c) {
$http = $this->http ?? HttpClient::create();
return new Api($http, (string) $c['username'], (string) $c['password'], (string) … | |
omnibus.action.rating | static fn(Config $c) => $c->get('rates') ? null : new RatingAction() | |
omnibus.action.shipping | new ShippingAction() | |
omnibus.action.tracking | new TrackingAction() | |
omnibus.action.pickup | new PickupAction() | |
username | required | |
password | required | |
customer_number | required |
Mapping class
final class Mapping Mapping.php:9
Canada Post's shapes for ours: kilograms, centimetres, postal codes without the space.
const SERVICES = ['DOM.RP' => 'Regular Parcel', 'DOM.EP' => 'Expedited Parcel', 'DOM.XP' => 'Xpresspost', 'DOM.PC' => 'Priority', 'USA.EP' => 'Expedited Parcel USA', 'USA.XP'…
Mapping::postcode()
public static function postcode(Address $a): stringMapping::addressXml()
public static function addressXml(Address $a, ?string $province = null): stringMapping::e()
public static function e(string $s): stringMapping::status()
public static function status(?string $code, ?string $description = null): TrackingStatusOmnibus\CanadaPost\Action
PickupAction class
final class PickupAction implements ActionInterface, ApiAwareInterface PickupAction.php:16
Get Nearest Post Office (GET /rs/postoffice): post offices near a Canadian address.
PickupAction::__construct()
public function __construct()PickupAction::supports()
public function supports(Request $request): boolPickupAction::execute()
public function execute(Request $request): voidRatingAction class
final class RatingAction implements ActionInterface, ApiAwareInterface RatingAction.php:15
Get Rates (POST /rs/ship/price): every service for the parcel, with the contract's prices when there is one.
RatingAction::__construct()
public function __construct()RatingAction::supports()
public function supports(Request $request): boolRatingAction::execute()
public function execute(Request $request): voidShippingAction class
final class ShippingAction implements ActionInterface, ApiAwareInterface ShippingAction.php:21
A non-contract shipment (POST /rs/{customer}/ncshipment, paid by the card on file) or, with a contract, a contract shipment (POST /rs/{customer}/{customer}/shipment), then its label downloaded from the artifact link. Options: sender_province and recipient_province (two letters, Canadian addresses need them), label_format (PDF or ZPL).
ShippingAction::__construct()
public function __construct()ShippingAction::supports()
public function supports(Request $request): boolShippingAction::execute()
public function execute(Request $request): voidTrackingAction class
final class TrackingAction implements ActionInterface, ApiAwareInterface TrackingAction.php:17
Get Tracking Detail (GET /vis/track/pin/{pin}/detail): the significant events, oldest first.
TrackingAction::__construct()
public function __construct()TrackingAction::supports()
public function supports(Request $request): boolTrackingAction::execute()
public function execute(Request $request): void