PHP code example of stripyhorse / stripyhorse-php

1. Go to this page and download the library: Download stripyhorse/stripyhorse-php 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/ */

    

stripyhorse / stripyhorse-php example snippets




$config = StripyHorse\Configuration::getDefaultConfiguration()
    ->setAccessToken('sh_live_YOUR_KEY');

$render = new StripyHorse\Api\RenderApi(null, $config);
$out = $render->renderZpl(new StripyHorse\Model\RenderInputBody([
    'zpl'    => '^XA^FO50,50^A0N,45,45^FDHello^FS^XZ',
    'preset' => '4x6',
]));
file_put_contents('label.png', base64_decode($out->getLabels()[0]->getPng()));

$convert = new StripyHorse\Api\ConvertApi(null, $config);
$result = $convert->convertDocument(new SplFileObject('shipping-label.pdf'), preset: '4x6');
foreach ($result->getPages() as $page) {
    // send $page->getZpl() to your printer
}

$out = $convert->convertHtml(new StripyHorse\Model\HtmlInputBody([
    'html'   => '<div style="position:absolute;left:40px;top:40px;font-size:50px">Hello</div>
                 <zpl-barcode type="code128" data="00123456789"
                   style="left:40px;top:150px;width:600px;height:150px"></zpl-barcode>',
    'preset' => '4x6',
]));
echo $out->getZpl();

$sim = new StripyHorse\Api\SimulatorApi(null, $config);

$printer = $sim->createPrinter(new StripyHorse\Model\CreatePrinterInputBody([
    'name' => 'ci-run-42', 'preset' => '4x6',
]));

// Point the system under test at the printer, exactly like hardware:
$addr = $printer->getTcp()->getHost() . ':' . $printer->getTcp()->getPort();

// ... run your fulfillment code against $addr ...

// Then assert on what it printed:
$jobs = $sim->listJobs($printer->getId());
assert(count($jobs->getJobs()) === 1);

// Reproduce a paper-out jam and watch jobs hold in the buffer:
$sim->setPrinterFaults($printer->getId(), new StripyHorse\Model\Faults(['paper_out' => true]));
bash
composer