PHP code example of tsekka / omniva

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

    

tsekka / omniva example snippets


    use Tsekka\Omniva\Client;
    use Tsekka\Omniva\Parcel;
    use Tsekka\Omniva\Address;
    use Tsekka\Omniva\PickupPoint;

    /**
     * Set your authentication details.
     */
    $client = new Client(
        username: 'your Omniva web service username',
        password: 'your Omniva web service password'
    );

    /**
     * Set & define delivery service, 
     * pickup point's information 
     * and additional services. 
     */
    $parcel = new Parcel(
        deliveryService: 'PA'
    );
    $pickupPoint = new PickupPoint(
        offloadPostcode: 96094,
        type: 0
    );
    $parcel
        ->addAdditionalService('ST')
        ->addAdditionalService('SF');

    /**
     * Set & define receiver and returnee.
     */
    $receiver = new Address();
    $receiver->pickupPoint = $pickupPoint;
    $receiver->name = 'Jane Doe';
    $receiver->mobile = '+3725511223';
    $receiver->email = '[email protected]';
    $returnee = new Address();
    $returnee->country = 'EE';
    $returnee->name = 'John Roe';
    $returnee->mobile = '+3725566778';
    $returnee->email = '[email protected]';
    $returnee->postcode = '80040';
    $returnee->deliverypoint = 'PARNU';
    $returnee->street = 'Savi 20';
    $returnee->country = 'EE';
    $parcel->receiver = $receiver;
    $parcel->returnee = $returnee;

    /**
     * Generate the shipment & get the barcode
     */
    $barcode = $client->createShipment($parcel);

    /**
     * Request the label to be emailed to you from Omniva's server
     */
    $client->sendLabel($barcode, '[email protected]');

    /**
     * Or get the content of pdf file & save or output it
     */
    $fileData = $client->getLabel($barcode);
    $fileName = "label_{$barcode}.pdf";
    file_put_contents(storage_path() . "/{$fileName}", base64_decode($fileData));
    header('Content-type: application/pdf');
    header('Content-Disposition: attachment; filename="' . $fileName . '"');
    echo base64_decode($fileData);