PHP code example of tcgunel / omniship-hepsijet
1. Go to this page and download the library: Download tcgunel/omniship-hepsijet 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/ */
tcgunel / omniship-hepsijet example snippets
use Omniship\Omniship;
use Omniship\Common\Address;
use Omniship\Common\Package;
$carrier = Omniship::create('HepsiJet');
$carrier->initialize([
'username' => 'your-username',
'password' => 'your-password',
'companyName' => 'YourCompany',
'abbreviationCode' => 'YRCMPNY',
'companyAddressId' => 'ADDR-001',
'currentXDockCode' => 'XD_CENTER',
'testMode' => true,
]);
$response = $carrier->createShipment([
'customerDeliveryNo' => 'YRCMPNY123456789',
'shipFrom' => new Address(
name: 'Ahmet Yılmaz',
street1: 'Atatürk Cad. No:42',
city: 'İstanbul',
district: 'Kadıköy',
),
'shipTo' => new Address(
name: 'Mehmet Demir',
street1: 'Kızılay Mah. 123. Sok. No:5',
city: 'Ankara',
district: 'Çankaya',
postalCode: '06420',
phone: '05559876543',
email: '[email protected] ',
),
'packages' => [
new Package(
weight: 2.5,
length: 30,
width: 20,
height: 15,
description: 'Elektronik ürün',
),
],
'deliveryType' => 'RETAIL', // RETAIL, MARKET_PLACE, EXPRESS, RETURNED
'productCode' => 'HX_STD', // HX_STD, HX_SD, HX_ND, HX_EX
])->send();
if ($response->isSuccessful()) {
echo $response->getTrackingNumber(); // "YRCMPNY123456789"
echo $response->getBarcode(); // Same as tracking number
echo $response->getShipmentId(); // Same as tracking number
}
$response = $carrier->getTrackingStatus([
'trackingNumber' => 'YRCMPNY123456789',
])->send();
if ($response->isSuccessful()) {
$info = $response->getTrackingInfo();
echo $info->status->name; // "DELIVERED"
echo $info->trackingNumber; // "YRCMPNY123456789"
echo $info->signedBy; // "Mehmet Demir" (if delivered)
foreach ($info->events as $event) {
echo $event->description; // "ACCEPTED", "OUT_FOR_DELIVERY", etc.
echo $event->occurredAt->format('Y-m-d H:i');
echo $event->location; // "Istanbul", "Ankara", etc.
}
}
$response = $carrier->cancelShipment([
'trackingNumber' => 'YRCMPNY123456789',
'deleteReason' => 'IPTAL', // Optional, defaults to "IPTAL"
])->send();
if ($response->isSuccessful() && $response->isCancelled()) {
echo 'Shipment cancelled';
}