Skip to content

paveltizek/balikobot-php

 
 

Repository files navigation

Balikobot API

Created as part of inspishop e-commerce platform by inspirum team.

Latest Stable Version Build Status Coverage Status Quality Score PHPStan Total Downloads Software License

Offers implementation of Balikobot API described in the documentation

  • Support for all API requests
  • Simple add/track/drop package methods
  • All package options are accessible via setter/getter methods
  • The entire code is covered by unit tests
  • Customizable Requester for easy functionality expandability (caching, etc.)

Usage example

All the code snippets shown here are modified for clarity, so they may not be executable.

// init balikobot class
$requester = new Requester($apiUser, $apiKey);
$balikobot = new Balikobot($requester);
$data      = [];

// create new package collection for specific shipper
$packages = new PackageCollection(Shipper::CP);

// create new package
$package = new Package();
$package->setServiceType(ServiceType::CP_NP);
$package->setRecName('Josef Novák');
$package->setRecZip('11000');
$package->setRecCountry(Country::CZECH_REPUBLIC);
$package->setRecPhone('776555888');
$package->setCodPrice(1399.00);
$package->setCodCurrency(Currency::CZK);

// add package to collection
$packages->add($package);

// upload packages to balikobot
$orderedPackages = $balikobot->addPackages($packages);

// save package IDs
$data['packages'] = $orderedPackages->getPackageIds();

// save track URL for each package
foreach($orderedPackages as $orderedPackage) {
  $data['trackUrl'][] = $orderedPackage->getTrackUrl();
}

// order shipment for packages
$orderedShipment = $balikobot->orderShipment($orderedPackages);

// save order ID and labels URL
$data['orderId']     = $orderedShipment->getOrderId();
$data['labelsUrl']   = $orderedShipment->getLabelsUrl();
$data['handoverUrl'] = $orderedShipment->getHandoverUrl();

/*
var_dump($data);
[
  'packages'    => [
    0 => 42719
    1 => 42720
  ]
  'trackUrl'    => [
    0 => 'https://www.postaonline.cz/trackandtrace/-/zasilka/cislo?parcelNumbers=DR00112233M'
    1 => 'https://www.postaonline.cz/trackandtrace/-/zasilka/cislo?parcelNumbers=DR00112234M' 
  ]
  'orderId'     => 2757
  'labelsUrl'   => 'https://pdf.balikobot.cz/cp/eNorMTIwt9A1NbYwM76cMBAXAn4.'
  'handoverUrl' => 'https://pdf.balikobot.cz/cp/eNorMTIwt9A1NbawtARcMBAhAoU.'
]
*/

System requirements

Installation

$ composer require inspirum/balikobot

Version

Support all options for Balikobot API described in the documentation (v1.883, 2020-04-24).

Usage

The module contains several helper classes that contain most of the constants needed to work with the Balikobot API.

Support all options for Balikobot API described in given documentation.

Extension over Client that uses custom DTO classes as an input and output for its methods.

Testing

To run unit tests, run:

$ composer test:test

To show coverage, run:

$ composer test:coverage

For testing purposes, you can use these credentials:

  • API username: balikobot_test2cztest
  • API key: #lS1tBVo

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email tomas.novotny@inspirum.cz instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Balikobot API

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%