Skip to content

helppc/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 v2 described in the documentation

  • Support for all API requests
  • Simple add/track/drop package methods
  • All package options are accessible via setter and getter methods
  • The entire code is covered by unit and integration 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.

// get credentials
$apiUser = getenv('BALIKOBOT_API_USER');
$apiKey  = getenv('BALIKOBOT_API_KEY');

// 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.'
]
*/

See more available methods documentation in Usage section.

System requirements

Installation

Run composer require command:

$ composer require inspirum/balikobot

or add a requirement to your composer.json:

"inspirum/balikobot": "^5.0"

Version

Support all options for Balikobot API v2 described in the official documentation until v1.901 (2021-01-18).

If you want to use older API v1, please use ^4.0 version:

"inspirum/balikobot": "^4.0"

More details are available in changelog.

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

You can also run only Unit or Integration test suites, run:

$ composer test:unit
$ composer test:integration

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

PHP library for Balikobot API.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%