Skip to content
/ omniva Public
forked from nebijokit/omniva

Library to interact with Omniva courier API

License

Notifications You must be signed in to change notification settings

Gamesh/omniva

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Omniva API

PHP wrapper for courier Omniva integration.

Build Status Maintainability Total Downloads

SensioLabsInsight Scrutinizer Code Quality

Examples

Get label

Returns Label response (stdClass object) with encoded PDF & barcode. For Response structure view getLabel phpdoc.

$client = new Client($username, $password);
$client->getLabel($parcel);

Get pickup points list

This endpoint returns list of pickup points. Pickup point can be Terminal or Post office. Field Type determines whether field is Terminal (Type: 0) or Post office (Type: 1).

// username & password is not necessary for pickup points
$client = new Client($username, $password);

$points = $client->getPickupPoints();

Create Shipment & get Label

use Omniva\Parcel;
use Omniva\Client;
use Omniva\Address;
use Omniva\Service;

$client = new Client($username, $password);

$shipment = $parcel->getShipment();
$id = $parcel->getId();

$omnivaParcel = new Parcel();
$omnivaParcel
    ->setWeight($parcel->getWeightInKg())
    ->setPartnerId($id)
    ->setComment($shipment->getRemark())
;

if ($shipment->getCodAmount()) {
    $omnivaParcel->setCodAmount($shipment->getCodAmount());
    $omnivaParcel->addService(Service::COD());
}

$sender = new Address();
$sender
    ->setName($shipment->getSender()->getName())
    ->setPhone($shipment->getSender()->getPhone())
    ->setCountryCode($shipment->getSender()->getCountry()->getCode())
    ->setCity($shipment->getSender()->getCity())
    ->setStreet($shipment->getSender()->getStreet())
    ->setPostCode($shipment->getSender()->getPostalCode())
;

if ($shipment->getSender()->getEmail()) {
    $sender->setEmail($shipment->getSender()->getEmail());
}

$omnivaParcel->setSender($sender);

$returnee = clone $sender;
$omnivaParcel->setReturnee($returnee);

$receiver = new Address();
$receiver
    ->setName($shipment->getReceiver()->getName())
    ->setCountryCode($shipment->getReceiver()->getCountry()->getCode())
;

if ($shipment->getReceiver()->getEmail()) {
    $receiver->setEmail($shipment->getReceiver()->getEmail());
}

if ($shipment->getReceiver()->getPhone()) {
    $receiver->setPhone($shipment->getReceiver()->getPhone());
}

if ($shipment->getReceiver()->isTypeTerminal()) {
    $terminal = $shipment->getReceiver()->getTerminal();

    $pickupPoint = new PickupPoint($terminal->getIdentifier());
    $pickupPoint->setType($terminal->isPostOffice() ? PickupPoint::TYPE_POST_OFFICE : PickupPoint::TYPE_TERMINAL);

    $receiver->setPickupPoint($pickupPoint);

    if ($shipment->getReceiver()->getPhone()) {
        $omnivaParcel->addService(Service::SMS());
    }

    if ($shipment->getReceiver()->getEmail()) {
        $omnivaParcel->addService(Service::EMAIL());
    }
} else {
    $receiver
        ->setCity($shipment->getReceiver()->getCity())
        ->setStreet($shipment->getReceiver()->getStreet())
        ->setPostCode($shipment->getReceiver()->getPostalCode())
    ;
}
$omnivaParcel->setReceiver($receiver);

$response = $client->createShipment($omnivaParcel);

$trackingNumber = $response->savedPacketInfo->barcodeInfo->barcode;
$parcel->setTrackingNumber($trackingNumber);
$omnivaParcel->setTrackingNumber($trackingNumber);

$response = $client->getLabel($omnivaParcel);

// PDF content
$content = $response->successAddressCards->addressCardData->fileData;

Ideas for further development

  • implement Client tracking
  • add Symfony\Constraint for data validation

About

Library to interact with Omniva courier API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%