1. Go to this page and download the library: Download tcgunel/omniship-mng 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-mng example snippets
use Omniship\Omniship;
use Omniship\Common\Address;
use Omniship\Common\Package;
use Psr\SimpleCache\CacheInterface;
/** @var CacheInterface $cache */ // any PSR-16 cache works (Laravel's
// Cache::store(), Symfony Psr16Cache, etc.)
$mng = Omniship::create('MNG');
$mng->initialize([
// platform-wide IBM keys (from your apizone app)
'clientId' => env('MNG_CLIENT_ID'),
'clientSecret' => env('MNG_CLIENT_SECRET'),
// per-merchant MNG account
'customerNumber' => '1234567890', // merchant's MNG müşteri numarası
'password' => 'permanent-panel-pwd',
'identityType' => 1, // always 1
'testMode' => true, // sandbox vs production
'tokenCache' => $cache, // optional, see "JWT caching"
]);
$response = $mng->createShipment([
'referenceId' => 'OMN-12345', // unique, uppercased, ≤30 chars
'shipTo' => new Address(
name: 'Ad Soyad',
street1: 'Örnek mah. 123. sok. No:5 Daire:7',
city: 'Adana',
district:'Seyhan',
phone: '+905555555555',
email: '[email protected]',
),
'recipientCityCode' => 1, // from CBS Info — see below
'recipientDistrictCode' => 100,
'recipientTaxNumber' => '11111111110', // TC Kimlik (or placeholder)
'packages' => [
new Package(weight: 1.0, desi: 1.0, quantity: 1, description: 'Test'),
],
])->send();
if ($response->isSuccessful()) {
echo $response->getShipmentId(); // "614118757013" — MNG's shipment id
echo $response->getTrackingNumber(); // same as shipmentId
echo $response->getBarcode(); // "C@6B@H21FMLRPNAAA6J" — scannable
$label = $response->getLabel(); // ZPL string for Zebra printer
file_put_contents('label.zpl', $label->content);
} else {
echo $response->getMessage(); // human-readable MNG error description
echo $response->getCode(); // HTTP status
}
// in your order lifecycle hook
RegisterMngRecipientJob::dispatch($order);
// the job
public function handle(): void
{
$mng = $this->buildCarrier($this->order->shop);
$mng->createRecipient([
'shipTo' => $this->buildAddress($this->order),
'recipientCityCode' => $this->lookupCityCode(...),
'recipientDistrictCode' => $this->lookupDistrictCode(...),
'recipientTaxNumber' => $this->order->tc_no ?: '11111111110',
])->send();
$this->order->forceFill(['mng_recipient_registered_at' => now()])->save();
}
$response->getShipmentId(); // MNG shipment ID (12-digit numeric)
$response->getTrackingNumber(); // alias for getShipmentId()
$response->getBarcode(); // first piece's scannable barcode value
$response->getBarcodes(); // all pieces' barcode values
$response->getInvoiceId(); // MNG invoice number ("FM378349")
$response->getLabel(); // Omniship\Common\Label with ZPL content
// by your reference
$mng->getTrackingStatus(['referenceId' => 'OMN-12345'])->send();
// by MNG shipment id (12-digit numeric)
$mng->getTrackingStatus(['trackingNumber' => '614118757013'])->send();