PHP code example of postabezhranic / apisdk

1. Go to this page and download the library: Download postabezhranic/apisdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

postabezhranic / apisdk example snippets




$pbh = new \postabezhranic\api\Pbh('userId', 'apikey');


// příklad správného balíku
$pbh->addItem([
    'kod' => '2-546',
    'psc' => '110 00',
    'ulice' => '17. listopadu',
    'mesto' => 'Praha 5', 
    'stat' => 'HU',
    'prepravce' => 60,
    'jmeno' => 'Adresát',
]);

// příklad správného balíku se službami
$pbh->addItem([
    'kod' => '2-545',
    'psc' => '110 00',
    'ulice' => '17. listopadu',
    'mesto' => 'Praha 5', 
    'stat' => 'HU',
    'prepravce' => 60,
    'jmeno' => 'Adresát',
    'sluzby' => [
	'sluzba' => [
	    '@attributy' => [
	        'key' => 'val', //vygeneruje <sluzba key="val">
	    ]
	    'nazev' => 'PP',
	    'hodnota' => '1',
	]
    ]
]);


$result = $pbh->sendItems();

$result = $pbh->getPackageInfo('2-545'); //kod viz example-send-packages
var_dump($result); //výsledek dotazu, pokud je vše dobře, vrátí se state ok

$pbh = new Pbh('userId', 'apikey'); //zde zadáme ID uživatele a api klíč


$pbh->useTransactionMode(); 

$pbh->addProduct([
    'productcode' => '1-545',
    'name' => 'test',
    'photo' => 'https://www.postabezhranic.cz/styl/images/logo-posta-bez-hranic.png',
]);

$pbh->addProduct([
    'productcode' => '1-5454',
    'productcodeOther' => 'some-code',
    'name' => 'test2',
    'photo' => 'https://www.postabezhranic.cz/styl/images/logo-posta-bez-hranic.png',
]);


$result = $pbh->sendProducts(); 
var_dump($result);

$pbh->addItem([
    'kod' => '2-545',
    'psc' => '110 00',
    'ulice' => '17. listopadu',
    'mesto' => 'Praha 5', 
    'stat' => 'RO',
    'prepravce' => 23,
    'jmeno' => 'Adresát',
    'produkty' => [
	[
	    'id' => '123456789',
	    'mnozstvi' => '1',
	],[
	    'id' => '12345678',
	    'mnozstvi' => '1',
	]
    ]
]);