PHP code example of salamek / czech-post-api
1. Go to this page and download the library: Download salamek/czech-post-api 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/ */
salamek / czech-post-api example snippets
$username = 'my_api_username';
$password = 'my_api_password';
$cookieJar = __DIR__.'/cookieJar.txt';
$czechPostApi = new Salamek\CzechPostApi\Api($username, $password, $cookieJar);
$sender = new Salamek\CzechPostApi\Model\Sender('C9569', 'Olomouc', 'My Compamy s.r.o.', 'My Address', '77900', '[email protected] ', '+420123456789', 'http://www.example.cz', Country::CZ);
$recipient = new Salamek\CzechPostApi\Model\Recipient('Olomouc', 'Adam Schubert', 'My Address', '77900', '[email protected] ', '+420123456789', 'http://www.salamek.cz', Country::CZ, 'My Compamy a.s.');
$myPackageIdFromNumberSeries = 115;
$weight = 3.15;
$insurance = 100;
$package = new Salamek\CzechPostApi\Model\Package($myPackageIdFromNumberSeries, Product::PACKAGE_TO_HAND, $sender, $recipient, null, null, $insurance, [], 'Package desc', 1, 1, null);
try
{
$czechPostApi->createPackages([$package]);
}
catch (\Exception $e)
{
echo $e->getMessage() . PHP_EOL;
}
$sender = new Salamek\CzechPostApi\Model\Sender('Olomouc', 'My Compamy s.r.o.', 'My Address', '77900', '[email protected] ', '+420123456789', 'http://www.example.cz', Country::CZ);
$recipient = new Salamek\CzechPostApi\Model\Recipient('Olomouc', 'Adam Schubert', 'My Address', '77900', '[email protected] ', '+420123456789', 'http://www.salamek.cz', Country::CZ, 'My Compamy a.s.');
$myPackageIdFromNumberSeries = 115;
$weight = 3.15;
$insurance = 100;
$package = new Salamek\CzechPostApi\Model\Package($myPackageIdFromNumberSeries, Product::PACKAGE_TO_HAND, $sender, $recipient, null, null, $insurance, [], 'Package desc', 1, 1, null);
$rawPdf = Label::generateLabels([$package]);
file_put_contents($package->getPackageNumber() . '.pdf', $rawPdf);