PHP code example of diglin / swisspost-barcode-php-sdk
1. Go to this page and download the library: Download diglin/swisspost-barcode-php-sdk 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/ */
diglin / swisspost-barcode-php-sdk example snippets
{
" "diglin/barcode-swisspost-php-sdk": "1.*"
},
"repositories" : [
{
"type": "vcs",
"url": "[email protected] :diglin/barcode-swisspost-php-sdk.git"
}
]
}
/**
* Minimal options
*/
$options = array(
\WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_URL => $this->config->getWsdl(),
\WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_LOGIN => $this->config->getLogin(),
\WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_PASSWORD => $this->config->getPassword(),
\WsdlToPhp\PackageBase\AbstractSoapClientBase::WSDL_CLASSMAP => \Diglin\Swisspost\ClassMap::get(),
);
$generate = new \Diglin\Swisspost\ServiceType\Generate($options);
$barcodeDefinition = new \Diglin\Swisspost\StructType\BarcodeDefinition();
$barcodeDefinition
->setBarcodeType(\Diglin\Swisspost\EnumType\BarcodeType::VALUE_LSO_1)
->setImageFileType('PNG')
->setImageResolution(300);
$struct = new \Diglin\Swisspost\StructType\GenerateBarcode($this->config->getLanguage(), $barcodeDefinition);
try {
/* @var $response GenerateBarcodeResponse */
if ($generate->GenerateBarcode($struct) !== false) {
$response = $generate->getResult();
} else {
$response = $generate->getLastError();
}
// PNG Picture to use further
$barcode = $response->getData()->getBarcode();
// ... your code here
} catch (\SoapFault $e) {
switch ($e->faultcode) {
case 'HTTP':
echo 'Login and/or password is not correct' . PHP_EOL;
break;
default:
echo sprintf('Error occurred with the SOAP interface with the error message "%s"', $e->faultstring);
break;
}
}