awd-studio/nova-poshta

v0.4.0 2017-11-30 04:43 UTC

README

Build Status Coverage Status Latest Stable Version Total Downloads License

PHP SDK for Nova Poshta API (alpha)

Integrate your PHP apps with Nova Poshta post company API

This open-source library allows you to integrate Nova Poshta API into your apps.

About Nova Poshta company:

Today Nova Poshta is a leader in express delivery owing to its innovation approach and hard work on efficiency improvement. By anticipating Client needs, the company constantly comes up with new products and services.

Nova Poshta’s business isn’t solely about parcels and cargoes delivery. We pride ourselves in e-commerce market development and deployment of complex technological solutions helping businesses to expand on the international scale.

Nova Poshta puts into your service:

  • Over 2500 depots all over Ukraine
  • Over 2500 vehicles
  • 36 cutting-edge sorting stations
  • Over 16 000 qualified employees
  • More than 60 million shipments a year
  • Over 350 cash desks carrying out money transfers
  • Modern logistics complex of 4000 sq. m.
  • Transparent fees and loyalty programs
  • Dedicated customer service and support
  • Track and Trace

More information.

Features

  • Track packages
  • Getting branch-offices
  • Getting common dictionaries
  • Counting delivery cost (future)
  • Determine the date of delivery (future)
  • Contingency (TTN) management (future)

Requirements

  • PHP v5.5 or higher (PHP 7+ is recommended)
  • Composer package manager
  • An API token
  • Guzzle or PHP_CURL libraries for sending HTTP-requests (optional - you can define yourself HTTP-driver)

Install

composer require awd-studio/nova-poshta

Usage

Authorize:

<?php

use NovaPoshta\Settings\Settings;

$key      = 'myAuthKeyHash';
$settings = Settings::getInstance()->auth($key);

Track:

<?php

use NovaPoshta\Settings\Settings;
use NovaPoshta\Models\TrackingDocument;

$key      = 'myAuthKeyHash';
$settings = Settings::getInstance()->auth($key);

$trackNum = '01234567890123'; // Valid track number
$status   = TrackingDocument::track($settings, $trackNum);

Get branch-offices:

<?php

use NovaPoshta\Settings\Settings;
use NovaPoshta\Models\Address;

$key      = 'myAuthKeyHash';
$settings = Settings::getInstance()->auth($key);

/**
 * Optional parameters.
 * 
 * @see https://devcenter.novaposhta.ua/docs/services/556d7ccaa0fe4f08e8f7ce43/operations/556d8211a0fe4f08e8f7ce45
 */
$options = [
    'BicycleParking'     => '1',
    'TypeOfWarehouseRef' =>'9a68df70-0267-42a8-bb5c-37f427e36ee4',
    'PostFinance'        => '1',
    'CityName'           =>'Київ',
    'CityRef'            => '20982d74-9b6c-11e2-a57a-d4ae527baec3',
];

// Or set city REF for quick searching:
// $options = [
//     'SettlementRef' => 'e71629ab-4b33-11e4-ab6d-005056801329'
// ];

$address = Address::getBranches($settings, $options);

Get addresses refs:

<?php

use NovaPoshta\Settings\Settings;
use NovaPoshta\Models\Address;

$key      = 'myAuthKeyHash';
$settings = Settings::getInstance()->auth($key);

$address  = new Address($settings);

$response = $address->getAreas(); // Areas

$options = [
    'CityRef' => 'ebc0eda9-93ec-11e3-b441-0050568002cf',
];
$response = $address->getStreet($options); // Streets

$response = $address->getSettlements($options); // Settlements

Online searching methods:

<?php

use NovaPoshta\Settings\Settings;
use NovaPoshta\Models\Address;

$key      = 'myAuthKeyHash';
$settings = Settings::getInstance()->auth($key);

$address  = new Address($settings);

// Just start typing, no needed save values to database!

$options = [
    'CityName' => 'К',
    //'CityName' => 'Ки',
    //'CityName' => 'Киї',
];
$response = $model->searchSettlements($options); // Get towns list

$options = [
    'StreetName'    => 'Шев',
    'SettlementRef' => 'e715719e-4b33-11e4-ab6d-005056801329',
    'Limit'         => 10,
];
$response = $model->searchSettlements($options); // Get streets

Common dictionaries:

<?php

use NovaPoshta\Settings\Settings;
use NovaPoshta\Models\Common;
use NovaPoshta\Models\Address;

$key      = 'myAuthKeyHash';
$settings = Settings::getInstance()->auth($key);

$recipientCityRef = '8d5a980d-391c-11dd-90d9-001a92567626';

$common   = new Common($settings);
$response = $common->getCargoTypes();
// Or
$response = $common->getPalletsList();
// Or
$response = $common->getMessageCodeText();
// Or
$response = $common->getTimeIntervals($recipientCityRef);

// Get warehouse types
$address  = new Address($settings);
$response = $model->getWarehouseTypes();

See details. All methods implements.