bricre / royalmail-tracking-v2-sdk
Royal Mail Tracking (for Server-side app) v2 REST API SDK generated from swagger specification
0.1.2
2021-05-21 13:53 UTC
Requires
- php: >=7.4|^8.0
- allansun/openapi-runtime: ^2.1
Requires (Dev)
- allansun/openapi-code-generator: ^0.2.3
- guzzlehttp/guzzle: ^v7.3.0
- monolog/monolog: ^2.2.0
- phpspec/prophecy: ^1.12
- phpspec/prophecy-phpunit: ^2.0
- phpunit/phpunit: ^9.5.4
This package is auto-updated.
Last update: 2024-11-21 22:00:35 UTC
README
PHP SDK generated from RoyalMail's Swagger File
Usage
First you need to follow RoyalMail's instruction to reigster your App and get credentials approved
Then configure your client (you only need to do this once for the whole process), you can do this at your application's initialization stage:
<?php use GuzzleHttp\Client as Guzzle; use OpenAPI\Runtime\Client; use OpenAPI\Runtime\ResponseHandler\JsonPsrResponseHandler; use OpenAPI\Runtime\ResponseHandlerStack; use RoyalMail\SDK\V2Tracking\ResponseTypes; Client::configure( new Guzzle([ 'base_uri' => 'https://api.royalmail.net', 'headers' => [ 'Accept' => 'application/json', 'X-Accept-RMG-Terms' => 'yes', 'X-IBM-Client-Id' => getenv('X-IBM-Client-Id'), 'X-IBM-Client-Secret' => getenv('X-IBM-Client-Secret'), ] ]), new ResponseHandlerStack([ JsonPsrResponseHandler::setResponseTypes(new ResponseTypes()) ]), );
Then in your actual business logic, run one of the three API methods exposed by RoyalMail
<?php use RoyalMail\SDK\V2Tracking\Api\API; use RoyalMail\SDK\V2Tracking\Model\EventsSuccessResponse; use RoyalMail\SDK\V2Tracking\Model\SignatureSuccessResponse; use RoyalMail\SDK\V2Tracking\Model\SummarySuccessResponse; $API = new API(); /** @var SummarySuccessResponse $summery */ $summary = $API->summary(['mailPieceId'=>'AA999999999GB']); /** @var EventsSuccessResponse $events */ $events = $API->events('AA999999999GB'); /** @var SignatureSuccessResponse $signature */ $signature = $API->signature('AA999999999GB');
Check APITest for more samples for how to debug