bricre / royalmail-shipping-v3-sdk
Royal Mail Shipping V3 REST API SDK generated from swagger specification
dev-master
2022-12-30 11:22 UTC
Requires
- php: >=7.0|^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-10-29 06:25:46 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\SimplePsrResponseHandlerStack; use RoyalMail\SDK\V3Shipping\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 SimplePsrResponseHandlerStack(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