tibezh/ukrposhta-php-sdk

Contains integration with Ukrposhta service.

0.0.1 2023-11-30 15:09 UTC

This package is auto-updated.

Last update: 2024-05-29 10:00:02 UTC


README

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