1. Go to this page and download the library: Download mijora/omniva-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/ */
mijora / omniva-api example snippets
use Mijora\Omniva\OmnivaException;
use Mijora\Omniva\Shipment\Package\AdditionalService;
use Mijora\Omniva\Shipment\Package\Address;
use Mijora\Omniva\Shipment\Package\Contact;
use Mijora\Omniva\Shipment\Package\Measures;
use Mijora\Omniva\Shipment\Package\Cod;
use Mijora\Omniva\Shipment\Package\Package;
use Mijora\Omniva\Shipment\Shipment;
use Mijora\Omniva\Shipment\ShipmentHeader;
//create new shipment object
$shipment = new Shipment();
$shipment
->setComment('Test comment') //set comment, optional
->setShowReturnCodeEmail(true) //return code in receiver email, optional
->setShowReturnCodeSms(true); //return code in receiver sms, optional
//new shipment header object, ice codes, you can view at https://www.omniva.lt/public/files/failid/omniva-service-codes-lt-eng.pdf
//set package size and weight
$measures = new Measures();
$measures
->setWeight(6.689) //weight in kg, etPostcode('72201') //set postcode (LT, EE and FI are "00000", for LV the format is "LV-0000")
->setDeliverypoint('Kaunas') //set city and state (up to 80 chars)
->setOffloadPostcode('68594') //set terminal code if sending to parcel terminal
->setStreet('Guobu g. 5-266'); //set street, house and apartment number (up to 80 chars)
$receiverContact
->setAddress($receiverAddress) //assign address to receiver
->setEmail('[email protected]') //set receiver email
->setMobile('+37060000000') //set receiver phone (recommended in international format)
->setPersonName('Moby Simpson'); //set receiver full name
$package->setReceiverContact($receiverContact); //assign receiver to package
$senderContact = new Contact(); //sender contact object
$senderAddress = new Address(); //sender address object
$senderAddress
->setCountry('LV') //set country code (2 letters)
->setPostcode('LV-1234') //set postcode (LT, EE and FI are "00000", for LV the format is "LV-0000")
->setDeliverypoint('Riga') //set city and state (up to 80 chars)
->setStreet('Pils iela 3'); //set street, house and apartment number (up to 80 chars)
$senderContact
->setAddress($senderAddress) //assign address to sender
->setMobile('+37125700000') //set sender phone
->setPersonName('Stefan Dexter'); //set sender full name
$package->setSenderContact($senderContact); //assign sender to package
//set packages to shipment, in this case we assign 2 same packeges for shipment
$shipment->setPackages([$package, $package]);
//hide return code from customer SMS and email
$shipment->setShowReturnCodeSms(false);
$shipment->setShowReturnCodeEmail(false);
//set auth data
$shipment->setAuth($username, $password);
//register shipment to Omniva, on success, will return $result['barcodes'], else throw OmnivaException exception with error message
$result = $shipment->registerShipment();
use Mijora\Omniva\OmnivaException;
use Mijora\Omniva\Shipment\Label;
$label = new Label(); //new label object
$label->setAuth($username, $password); //set auth data
//return labels pdf or thow OmnivaException on error
//default function attributes downloadLabels($barcodes, $combine = true, $mode = 'I', $name = 'Omniva labels')
//$barcodes - string or array of strings
//$combine - if true, will add 4 labels per page, else 1 label per page
//$mode - I: return directly to browser preview, S: return pdf as string data, D: force browser to download
//$name - name of file
$label->downloadLabels($barcodes);
use Mijora\Omniva\OmnivaException;
use Mijora\Omniva\Shipment\Manifest;
use Mijora\Omniva\Shipment\Order;
use Mijora\Omniva\Shipment\Package\Address;
use Mijora\Omniva\Shipment\Package\Contact;
$address = new Address(); //sender address object
$address
->setCountry('LT') //set country code
->setPostcode('72201') //set post code
->setDeliverypoint('City') //set city
->setStreet('Test g.'); //set street
$senderContact = new Contact(); //sender contact object
$senderContact
->setAddress($address) //add address to to contact
->setMobile('+37060000000') //set phone
->setPersonName('Stefan Dexter'); //set sender full name
$manifest = new Manifest(); //new manifest object
$manifest
->setSender($senderContact) //add sender contact
->showBarcode(false) //disable barcode image display
->setSignatureLineLength(40) //change the length of the signature line
->setString('sender_address', 'Shop address') //change string in manifest. First value is string key. Available keys: sender_address, row_number, shipment_number, order_number, date, quantity, weight, recipient_address, courier_signature, sender_signature
->setColumnLength('row_number', 20); //change orders table column width. First value is column key. Available keys: row_number, shipment_number, order_number, date, quantity, weight, recipient_address
$order = new Order(); //new order object
$order->setTracking('BK000000000LT'); //set tracking number
$order->setQuantity('2'); //set quanitty of packages
$order->setWeight('1'); //set weight in kg
$order->setReceiver('Test receiver, City, 12345, LT'); //set full receiver address
$manifest->addOrder($order); //add order to manifest
//get manifest pdf
//first attribute - I: return directly to browser preview, S: return pdf as string data, D: force browser to download
//second - pdf file name
$manifest->downloadManifest('I', 'Manifest file name');
use Mijora\Omniva\OmnivaException;
use Mijora\Omniva\Shipment\CallCourier;
use Mijora\Omniva\Shipment\Package\Address;
use Mijora\Omniva\Shipment\Package\Contact;
$address = new Address(); //pickup address object
$address
->setCountry('LT') //set country code
->setPostcode('72201') //set post code
->setDeliverypoint('City') //set city
->setStreet('Test g.'); //set street
//pickup contact data
$senderContact = new Contact();
$senderContact
->setAddress($address) //assign pickup address object
->setMobile('+37060000000') //set phone
->setPersonName('Stefan Dexter'); //set full name of sender
//call courier object
$call = new CallCourier();
$call
->setAuthsetAuth($username, $password, $api_url, true); // set auth info. Username (debug_data = $call->getDebugData(); //return debug data which contain URL, HTTP code, request and response. only if debug = true
use Mijora\Omniva\OmnivaException;
use Mijora\Omniva\Shipment\CallCourier;
$address = new Address(); //pickup address object
$address
->setCountry('LT') //set country code
->setPostcode('72201') //set post code
->setDeliverypoint('City') //set city
->setStreet('Test g.'); //set street
//pickup contact data
$senderContact = new Contact();
$senderContact
->setAddress($address) //assign pickup address object
->setMobile('+37060000000') //set phone
->setPersonName('Stefan Dexter'); //set full name of sender
//call courier object
$call = new CallCourier();
// set auth info. Username (
use Mijora\Omniva\Locations\PickupPoints;
$omnivaPickupPointsObj = new PickupPoints(); //terminals object
//returns array list of terminals or OmnivaException on error
$terminals = $omnivaPickupPointsObj->getFilteredLocations('lt', 0, 'Kauno apskr.'); //can be optionally filtered by country code, type, and county
use Mijora\Omniva\Shipment\Tracking;
$tracking = new Tracking(); //tracking object
$tracking->setAuth($username, $password); //set auth data
//returns array of data or OmnivaException on error
$results = $tracking->getTracking($barcodes); //pass array of barcodes
//results array key will be tracking number and value will be array with date, event and state keys
if (is_array($results)) {
foreach ($results as $barcode => $tracking_data) {
echo '**************<br/>';
echo $barcode . '<br/>';
foreach ($tracking_data as $data) {
echo $data['date']->format('Y-m-d H:i:s') . ' ' . ' ' . $data['event'] . ' ' . $data['state'] . '<br/>';
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.