PHP code example of tcgunel / omniship-aras

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


use Omniship\Omniship;

$carrier = Omniship::create('Aras');
$carrier->initialize([
    'username' => 'your-username',
    'password' => 'your-password',
    'testMode' => true, // false for production
    'senderAccountAddressId' => '', // optional
]);

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

$response = $carrier->createShipment([
    'shipTo' => new Address(
        name: 'Ahmet Yilmaz',
        street1: 'Ataturk Cad. No:1',
        city: 'Istanbul',
        district: 'Kadikoy',
        phone: '05551234567',
    ),
    'packages' => [
        new Package(
            weight: 1.5,
            length: 30,
            width: 20,
            height: 15,
            description: 'Elektronik urun',
        ),
    ],
    'integrationCode' => 'ORD-001',       // >getMessage();       // error description
    echo $response->getCode();          // Aras result code
}

'barcodes' => ['1234567801', '1234567802'],

// Generate labels using default template
$html = $carrier->generateLabels([
    'shipFrom' => $shipFrom,
    'shipTo' => $shipTo,
    'packages' => $packages,
    'integrationCode' => '12345678',
    'paymentType' => PaymentType::SENDER,
    'cashOnDelivery' => false,
]);

// Output or save the HTML
file_put_contents('labels.html', $html);

$customTemplate = '<div class="my-label">
    <h1>{{carrierName}}</h1>
    <p>{{receiverName}} - {{receiverPhone}}</p>
    <p>{{receiverAddress}}</p>
    <p>Entegrasyon: {{integrationCode}}</p>
    <p>Barkod: {{barcodeNumber}}</p>
    <p>Paket: {{pieceNumber}} / {{totalPieces}}</p>
</div>';

$html = $carrier->generateLabels($shipmentData, $customTemplate);

$labels = $carrier->getLabelData($shipmentData);

foreach ($labels as $label) {
    echo $label->integrationCode;
    echo $label->barcodeNumber;
    echo "{$label->pieceNumber}/{$label->totalPieces}";
}

### Track Shipment

Tracking uses the `GetOrderWithIntegrationCode` SOAP method to look up shipment by integration code.


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

if ($response->isSuccessful()) {
    echo 'Shipment cancelled';
} else {
    echo $response->getMessage();
}