Skip to content

omnibus/usps API reference

Floor
Provider · Omnibus
Version
2.x
Conformance suite
runs, no CI read
Verified for real
Its README does not say
Licence
MIT
composer require omnibus/usps:2.x-dev

Read from the package's own PHP files at the commit 4c3a6421dad4: its namespaces, classes, interfaces and enums, their public constants, properties and methods with their PHPDoc, and the options its factories take. Nothing of it is run.

Omnibus\Usps

  • Api class

    The USPS APIs v3 (apis.usps.com) on an OAuth2 client-credentials token.

    4 methods · 4 properties · 2 constants

  • Mapping class

    USPS's shapes for ours: pounds and inches, two-letter states, ZIP codes.

    4 methods · 1 constant

  • UspsGatewayFactory class

    options: client_id: '%env(USPS_CLIENT_ID)%' # an app in the USPS Developer Portal client_secret: '%env(USPS_CLIENT_SECRET)%' sandbox: true # apis-tem.usps.com crid: '%env(USPS_CRID)%' # for labels: the payer's Customer Registration ID, mid: '%env(USPS_MID)%' # Mailer ID and account: '%env(USPS_EPS_ACCOUNT)%' # Enterprise Payment System account rates: [...] # optional: configured prices instead of the Prices API

    11 options

Omnibus\Usps\Action

  • PickupAction class

    The Locations API: post offices and drop-off points near an address.

    3 methods

  • RatingAction class

    The Prices API: the base rate of each mail class for the parcel, from ZIP to ZIP (domestic) or to a country (international), one call a class.

    3 methods

  • ShippingAction class

    The Labels API: a domestic label (international labels need customs forms: not offered here), paid through the payment authorization.

    3 methods

  • TrackingAction class

    The Tracking API: the package's events, oldest first.

    3 methods

Omnibus\Usps

Api class

final class Api Api.php:15

The USPS APIs v3 (apis.usps.com) on an OAuth2 client-credentials token.

Labels are paid for through a payment authorization token, asked once per session from the Payments API with the CRID, MID and EPS account.

const LIVE = 'https://apis.usps.com'
const TEST = 'https://apis-tem.usps.com'
public readonly bool $sandbox
public readonly ?string $crid
public readonly ?string $mid
public readonly ?string $account

Api::__construct()

public function __construct(readonly HttpClientInterface $http, readonly string $clientId, readonly string $clientSecret, public readonly bool $sandbox = false, public readonly ?string $crid = null, public readonly ?string $mid = null, public readonly ?string $account = null, readonly int $timeout = 20)

Api::base()

public function base(): string

Api::call()

public function call(string $method, string $path, ?array $body = null, array $query = [], array $headers = []): array

Api::paymentToken()

public function paymentToken(): string

The X-Payment-Authorization-Token a label needs: who pays (option crid, mid, account).

Mapping class

final class Mapping Mapping.php:9

USPS's shapes for ours: pounds and inches, two-letter states, ZIP codes.

const CLASSES = ['USPS_GROUND_ADVANTAGE' => 'USPS Ground Advantage', 'PRIORITY_MAIL' => 'Priority Mail', 'PRIORITY_MAIL_EXPRESS' => 'Priority Mail Express', 'FIRST-CLASS_PAC…

Mapping::pounds()

public static function pounds(int $grams): float

Mapping::inches()

public static function inches(?int $cm): ?float

Mapping::address()

public static function address(Address $a, array $extra = []): array

Mapping::status()

public static function status(?string $category, ?string $eventType = null): TrackingStatus

UspsGatewayFactory class

final class UspsGatewayFactory extends GatewayFactory UspsGatewayFactory.php:23

options: client_id: '%env(USPS_CLIENT_ID)%' # an app in the USPS Developer Portal client_secret: '%env(USPS_CLIENT_SECRET)%' sandbox: true # apis-tem.usps.com crid: '%env(USPS_CRID)%' # for labels: the payer's Customer Registration ID, mid: '%env(USPS_MID)%' # Mailer ID and account: '%env(USPS_EPS_ACCOUNT)%' # Enterprise Payment System account rates: [...] # optional: configured prices instead of the Prices API

Options

OptionDefault
sandboxfalse
cridnull
midnull
accountnull
omnibus.apifunction (Config $c) { $http = $this->http ?? HttpClient::create(); return new Api($http, (string) $c['client_id'], (string) $c['client_secret'], (bo…
omnibus.action.ratingstatic fn(Config $c) => $c->get('rates') ? null : new RatingAction()
omnibus.action.shippingstatic fn(Config $c) => $c['crid'] && $c['mid'] && $c['account'] ? new ShippingAction() : null
omnibus.action.trackingnew TrackingAction()a label needs its payer
omnibus.action.pickupnew PickupAction()
client_idrequired
client_secretrequired

Omnibus\Usps\Action

PickupAction class

final class PickupAction implements ActionInterface, ApiAwareInterface PickupAction.php:15

The Locations API: post offices and drop-off points near an 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:18

The Prices API: the base rate of each mail class for the parcel, from ZIP to ZIP (domestic) or to a country (international), one call a class.

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:16

The Labels API: a domestic label (international labels need customs forms: not offered here), paid through the payment authorization.

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:16

The Tracking API: the package's events, oldest first.

TrackingAction::__construct()

public function __construct()

TrackingAction::supports()

public function supports(Request $request): bool

TrackingAction::execute()

public function execute(Request $request): void