PHP code example of tcgunel / omniship-common

1. Go to this page and download the library: Download tcgunel/omniship-common 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-common example snippets


Omniship::isSoap('Yurtici');   // true
Omniship::isSoap('MNG');       // false

$carrier = Omniship::isSoap($name)
    ? Omniship::create($name)
    : Omniship::create($name, $yourPsr18Client);

use Omniship\Omniship;

// Create a carrier instance
$carrier = Omniship::create('Yurtici');
$carrier->initialize([
    'username' => 'your-username',
    'password' => 'your-password',
    'testMode' => true,
]);

// Create a shipment
$response = $carrier->createShipment([
    'cargoKey' => 'ORDER-001',
    'invoiceKey' => 'INV-001',
    'shipTo' => new \Omniship\Common\Address(
        name: 'Mehmet Demir',
        street1: 'Kızılay Mah. 123. Sok. No:5',
        city: 'Ankara',
        district: 'Çankaya',
        phone: '05559876543',
    ),
    'packages' => [
        new \Omniship\Common\Package(weight: 2.5, desi: 3),
    ],
])->send();

if ($response->isSuccessful()) {
    echo $response->getTrackingNumber();
    echo $response->getShipmentId();
}

$response = $carrier->createShipment([...])->send();
$response->isSuccessful();
$response->getTrackingNumber();
$response->getShipmentId();
$response->getBarcode();

$response = $carrier->getTrackingStatus([
    'trackingNumber' => '330012345678',
])->send();

$info = $response->getTrackingInfo();
$info->status;          // ShipmentStatus enum
$info->trackingNumber;
$info->events;          // TrackingEvent[]

$response = $carrier->cancelShipment([
    'trackingNumber' => 'ORDER-001',
])->send();

$response->isSuccessful();
$response->isCancelled();

$carrier->setSoapClientFactory(
    fn (string $wsdl, array $options) => new LoggingSoapClient($wsdl, $options),
);

new Address(
    name: 'Alıcı Adı',
    company: 'Firma',
    street1: 'Adres satırı 1',
    street2: 'Adres satırı 2',
    city: 'İstanbul',           // İl
    district: 'Kadıköy',        // İlçe
    postalCode: '34700',
    country: 'TR',
    phone: '05551234567',
    email: '[email protected]',
    taxId: '1234567890',         // Vergi numarası
);

new Package(
    weight: 2.5,       // KG (metric default)
    length: 30,        // CM
    width: 20,         // CM
    height: 15,        // CM
    desi: 3,           // Volumetric weight (L*W*H/3000)
    quantity: 1,
    description: 'Elektronik ürün',
);