PHP code example of tcgunel / omniship-surat

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


use Omniship\Omniship;

$carrier = Omniship::create('Surat');
$carrier->initialize([
    'kullaniciAdi' => '1038106246',    // 10-digit Cari Kodu
    'sifre' => '123456',               // Cari Sifre (for shipment creation & cancel)
    'cariKodu' => '1038106246',        // Same Cari Kodu (for tracking)
    'webSifre' => '123456.Ff',         // Web Servis Sifresi (for tracking queries)
    'testMode' => true,
]);

use Omniship\Common\Address;
use Omniship\Common\Package;
use Omniship\Common\Enum\PaymentType;

$response = $carrier->createShipment([
    'shipTo' => new Address(
        name: 'Mehmet Demir',
        street1: 'Ataturk Cad. No:42',
        city: 'Ankara',
        district: 'Cankaya',
        phone: '05559876543',
        email: '[email protected]',
    ),
    'packages' => [
        new Package(weight: 2.5, desi: 3),
    ],
    'trackingNumber' => 'SIPARIS-001',     // OzelKargoTakipNo (your custom tracking code)
    'referenceNumber' => 'REF-001',        // Optional: group shipments
    'paymentType' => PaymentType::SENDER,  // SENDER (1=Pesin) or RECEIVER (2=Ucret Alici)
    'cargoType' => 3,                      // 1=Dosya, 2=Mi, 3=Koli
    'cargoContent' => 'Elektronik urun',   // Optional
])->send();

if ($response->isSuccessful()) {
    echo $response->getBarcode();        // 14-digit barcode from Surat
    echo $response->getTrackingNumber(); // OzelKargoTakipNo you provided
} else {
    echo $response->getMessage();        // Error description
}

$response = $carrier->createShipment([
    'shipTo' => new Address(/* ... */),
    'packages' => [new Package(weight: 1.0)],
    'trackingNumber' => 'COD-001',
    'cashOnDelivery' => true,
    'codAmount' => 150.50,               // KapidanOdemeTutari
    // KapidanOdemeTahsilatTipi: 1=Nakit, 2=POS
])->send();

$response = $carrier->getTrackingStatus([
    'trackingNumber' => 'SIPARIS-001',   // OzelKargoTakipNo or WebSiparisKodu
])->send();

if ($response->isSuccessful()) {
    $info = $response->getTrackingInfo();
    echo $info->trackingNumber;
    echo $info->status->value;           // DELIVERED, IN_TRANSIT, etc.

    foreach ($info->events as $event) {
        echo $event->description;
        echo $event->occurredAt->format('Y-m-d H:i');
        echo $event->location;
    }
}

$response = $carrier->cancelShipment([
    'trackingNumber' => 'SIPARIS-001',   // OzelKargoTakipNo
    'cancelReason' => 'Musteri istegi',  // Required: IptalNeden
])->send();

if ($response->isSuccessful() && $response->isCancelled()) {
    echo 'Shipment cancelled';
}