tibezh / ukrposhta-php-sdk
Contains integration with Ukrposhta service.
0.0.1
2023-11-30 15:09 UTC
Requires
- php: >=8.1.0
- guzzlehttp/guzzle: ^7.8
- psr/log: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.40
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10
This package is auto-updated.
Last update: 2024-09-05 10:18:55 UTC
README
An Ukrposhta PHP SDK based on the official Ukrposhta API.
Table of Contents
Requirements
This library uses PHP 8.1+.
To use the Ukrposhta API, you need to have Bearer and Token for each API sub-portal (eCom, StatusTracking and AddressClassifier). After signing the contract, the bearer and token are issued by your manager. You can find more information here.
Available Features
- Status Tracking - available.
- Address Classifier (counterparty) - planned.
- Shipments - planned.
Installation
To get started, simply require the project using Composer.
composer require tibezh/ukrposhta-php-sdk
Examples
Status Tracking
Request last status by barcode:
/** @var \Ukrposhta\Tracking\Entities\TrackingStatusInterface $barcodeLastStatus */ $barcodeLastStatus = (new \Ukrposhta\Tracking\Tracking()) ->setAccessToken('[BEARER-STATUS-TRACKING-ACCESS-TOKEN]') // To get results in English. // ->$this->setRequestLang('EN') ->requestBarcodeLastStatus('[BARCODE]'); // Prints event name value of the last status for the given barcode. print $barcodeLastStatus->getEventName();
Request all statuses by barcode:
/** @var \Ukrposhta\Tracking\Entities\TrackingStatusCollectionInterface $barcodeLastStatuses */ $barcodeLastStatuses = (new \Ukrposhta\Tracking\Tracking()) ->setAccessToken('[BEARER-STATUS-TRACKING-ACCESS-TOKEN]') // To get results in English. // ->$this->setRequestLang('EN') ->requestBarcodeStatuses('[BARCODE]'); // Prints "[date]: [eventName]" of each status for the given barcode. foreach ($data->all() as $item) { print $item->getDate()->format('c') . ': ' . $item->getEventName(); print '<br>'; }
Request route by barcode:
/** @var \Ukrposhta\Tracking\Entities\TrackingRouteInterface $barcodeRoute */ $barcodeRoute = (new \Ukrposhta\Tracking\Tracking()) ->setAccessToken('[BEARER-STATUS-TRACKING-ACCESS-TOKEN]') // To get results in English. // ->$this->setRequestLang('EN') ->requestBarcodeRoute('[BARCODE]'); // Prints "[from] -> [to]" information for the given barcode. print $barcodeRoute->getFrom() ' -> ' . $barcodeRoute->getTo();