Aller au contenu

omnibus/canada-post Référence de l’API

Étage
Fournisseur · Omnibus
Version
2.x
Suite de conformité
branchée, CI non lue
Vérifié en réel
Son README ne le dit pas
Licence
MIT
composer require omnibus/canada-post:2.x-dev

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é.

Omnibus\CanadaPost

  • Api class

    Canada Post's REST web services: XML in and out, basic auth with the API username and password.

    5 methods · 3 properties · 2 constants

  • CanadaPostGatewayFactory class

    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

    10 options

  • Mapping class

    Canada Post's shapes for ours: kilograms, centimetres, postal codes without the space.

    4 methods · 1 constant

Omnibus\CanadaPost\Action

  • PickupAction class

    Get Nearest Post Office (GET /rs/postoffice): post offices near a Canadian address.

    3 methods

  • RatingAction class

    Get Rates (POST /rs/ship/price): every service for the parcel, with the contract's prices when there is one.

    3 methods

  • ShippingAction class

    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).

    3 methods

  • TrackingAction class

    Get 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 $customerNumber
public readonly ?string $contractId
public 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(): string

Api::call()

public function call(string $method, string $path, ?string $body, string $contentType, ?string $accept = null, string $locale = 'en-CA'): \SimpleXMLElement|string

One call; XML back as a SimpleXMLElement without namespaces, or the raw bytes of a document.

Api::parse()

public static function parse(string $content): \SimpleXMLElement

Api::contract()

public function contract(): bool

CanadaPostGatewayFactory 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

OptionDefault
contract_idnull
sandboxfalse
omnibus.apifunction (Config $c) { $http = $this->http ?? HttpClient::create(); return new Api($http, (string) $c['username'], (string) $c['password'], (string) …
omnibus.action.ratingstatic fn(Config $c) => $c->get('rates') ? null : new RatingAction()
omnibus.action.shippingnew ShippingAction()
omnibus.action.trackingnew TrackingAction()
omnibus.action.pickupnew PickupAction()
usernamerequired
passwordrequired
customer_numberrequired

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): string

Mapping::addressXml()

public static function addressXml(Address $a, ?string $province = null): string

Mapping::e()

public static function e(string $s): string

Mapping::status()

public static function status(?string $code, ?string $description = null): TrackingStatus

Omnibus\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): bool

PickupAction::execute()

public function execute(Request $request): void

RatingAction 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): bool

RatingAction::execute()

public function execute(Request $request): void

ShippingAction 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): bool

ShippingAction::execute()

public function execute(Request $request): void

TrackingAction 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): bool

TrackingAction::execute()

public function execute(Request $request): void