PHP code example of onestopmobile / printnode-sdk

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

    

onestopmobile / printnode-sdk example snippets


use OneStopMobile\PrintNodeSdk\Enums\PrintContentType;
use OneStopMobile\PrintNodeSdk\Payloads\CreatePrintJobPayload;
use OneStopMobile\PrintNodeSdk\PrintNodeConfig;
use OneStopMobile\PrintNodeSdk\PrintNodeSdk;

$sdk = new PrintNodeSdk(new PrintNodeConfig(
    apiKey: getenv('PRINTNODE_API_KEY') ?: '',
));

$whoAmI = $sdk->whoAmI();
$email = $whoAmI->email;
$computers = $sdk->computers()->all();
$printers = $sdk->printers()->all();

$printJobId = $sdk->printJobs()->create(
    new CreatePrintJobPayload(
        printerId: 123,
        title: 'Shipping label',
        contentType: PrintContentType::PdfUri,
        content: 'https://example.com/label.pdf',
    ),
    idempotencyKey: 'label-123',
);

use OneStopMobile\PrintNodeSdk\Payloads\CreateChildAccountPayload;

$childAccount = $sdk->account()->create(
    new CreateChildAccountPayload(
        email: '[email protected]',
        password: 'secret-password',
        creatorRef: 'customer-123',
        apiKeys: ['production'],
        tags: [
            'customer_id' => '123',
        ],
    ),
);

use OneStopMobile\PrintNodeSdk\Values\ChildAccountContext;

$childAccount = ChildAccountContext::byEmail('[email protected]');

$tags = $sdk->account()->getTag('team', $childAccount);

use OneStopMobile\PrintNodeSdk\Laravel\Facades\DispatchPrint;

$result = DispatchPrint::printer(123)->pdfUrl(
    'https://example.com/packing-slip.pdf',
    title: 'Pakbon 1001',
);

$result = DispatchPrint::printer(123)
    ->source('warehouse')
    ->option('copies', 2)
    ->raw('^XA^FO50,50^FDHello^FS^XZ', title: 'Label 1001');

$result = DispatchPrint::printer(123)
    ->source('warehouse')
    ->zpl('^XA^FO50,50^FDHello^FS^XZ', title: 'Label 1001');

use OneStopMobile\PrintNodeSdk\Printing\PrintManager;

public function __invoke(PrintManager $print): void
{
    $print->printer(123)->pdfUrl(
        'https://example.com/packing-slip.pdf',
        title: 'Pakbon 1001',
    );
}

use OneStopMobile\PrintNodeSdk\Printing\PrintManagerConfig;

$print = $sdk->printingWithConfig(new PrintManagerConfig(
    defaultSource: 'warehouse',
    logFailures: true,
    logSuccess: false,
));

$result = DispatchPrint::to($order->printer_reference)
    ->pdfUrl('https://example.com/packing-slip.pdf', title: 'Pakbon 1001');

'default_child_account' => [
    'by' => 'email',
    'value' => '[email protected]',
],

'printing' => [
    'policy' => [
        'enabled' => true,
        'allowed_environments' => ['production'],
        'action_outside_allowed_environments' => 'skip',
    ],
    'logging' => [
        'enabled' => true,
        'channel' => 'stack',
        'log_skipped' => true,
        'log_success' => false,
        'log_failures' => true,
        '
bash
php artisan vendor:publish --tag=printnode-config