PHP code example of tcgunel / omniship-ptt

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


use Omniship\Omniship;

$carrier = Omniship::create('PTT');
$carrier->initialize([
    'musteriId' => 'your-customer-id',
    'sifre' => 'your-password',
    'testMode' => true, // false for production
]);

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

$response = $carrier->createShipment([
    'shipFrom' => new Address(
        name: 'Ahmet Yilmaz',
        street1: 'Ataturk Cad. No:42',
        city: 'Istanbul',
        district: 'Kadikoy',
        postalCode: '34710',
        country: 'TR',
        phone: '05551234567',
        email: '[email protected]',
    ),
    'shipTo' => new Address(
        name: 'Mehmet Demir',
        street1: 'Kizilirmak Cad. No:5',
        city: 'Ankara',
        district: 'Cankaya',
        postalCode: '06420',
        country: 'TR',
        phone: '05559876543',
    ),
    'packages' => [
        new Package(weight: 2.5, length: 30, width: 20, height: 15),
    ],
    'barcode' => 'PTT0000012345678',  // 

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

if ($response->isSuccessful()) {
    $info = $response->getTrackingInfo();
    echo $info->trackingNumber;
    echo $info->status->value;  // "delivered", "in_transit", etc.
    echo $info->carrier;        // "PTT Kargo"

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

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

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