Skip to content

The Ukrposhta API SDK for PHP provides a native interface to the Ukrposhta API services.

License

Notifications You must be signed in to change notification settings

tibezh/ukrposhta-php-sdk

Repository files navigation

Ukrpostha PHP SDK

Ukrposhta PHP SDK logo

An Ukrposhta PHP SDK based on the official Ukrposhta API.

Minimum PHP Version License CI codecov Latest Stable Version

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();

About

The Ukrposhta API SDK for PHP provides a native interface to the Ukrposhta API services.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages