PHP code example of shibin / aramex-laravel

1. Go to this page and download the library: Download shibin/aramex-laravel 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/ */

    

shibin / aramex-laravel example snippets


use Shibin\Aramex\DTO\Address;

$address = new Address(
    line1: 'Gardens Street',
    city: 'Amman',
    country_code: 'JO',
    name: 'John Doe',
    email: '[email protected]',
    phone: '0790000000',
    cell_phone: '0790000000',
);

use Shibin\Aramex\DTO\Shipment;

$shipment = new Shipment(
    shipper: $shipperAddress,     // Address Object
    consignee: $consigneeAddress, // Address Object
    shipping_date_time: time() + 3600,
    due_date: time() + 86400,
    pickup_location: 'Reception',
    weight: 2.5,
    number_of_pieces: 1,
    description: 'Electronics',
    payment_type: 'P', // P = Prepaid, C = Collect
);

use Shibin\Aramex\Facades\Aramex;

// Get all countries
$countries = Aramex::location()->countries();

// Get cities within a country
$cities = Aramex::location()->cities('SA'); // Saudi Arabia

use Shibin\Aramex\Facades\Aramex;
use Shibin\Aramex\DTO\Address;
use Shibin\Aramex\DTO\RateRequest;

// 1. Define Origin & Destination
$origin = new Address(line1: 'Street', city: 'Amman', country_code: 'JO');
$destination = new Address(line1: 'Street', city: 'Jeddah', country_code: 'SA');

// 2. Create Request
$request = new RateRequest(
    origin: $origin,
    destination: $destination,
    weight: 5.0,
    pieces: 1,
    currency: 'USD'
);

// 3. Calculate
$response = Aramex::rates()->calculate($request);

use Shibin\Aramex\Facades\Aramex;
use Shibin\Aramex\DTO\Address;
use Shibin\Aramex\DTO\Shipment;

$shipper = new Address(
    line1: 'Gardens St', city: 'Amman', country_code: 'JO',
    name: 'Shipper Name', email: '[email protected]', phone: '0790000000'
);

$consignee = new Address(
    line1: 'Fahad Rd', city: 'Riyadh', country_code: 'SA',
    name: 'Receiver Name', email: '[email protected]', phone: '0500000000'
);

$shipment = new Shipment(
    shipper: $shipper,
    consignee: $consignee,
    shipping_date_time: time() + 3600,
    due_date: time() + 86400,
    comments: 'Handle with care',
    pickup_location: 'Reception',
    weight: 2.5,
    number_of_pieces: 1,
    description: 'Electronics',
    payment_type: 'P'
);

$response = Aramex::shipments()->create($shipment);

// Access the Waybill Number
$waybill = $response->Shipments->ProcessedShipment->ID ?? null;

$shipmentNumber = "37133804481"; // The ID from the create shipment response

$response = Aramex::shipments()->printLabel($shipmentNumber);

if (isset($response->ShipmentLabel->LabelFileContents)) {
    $pdfContent = $response->ShipmentLabel->LabelFileContents;
    
    // Save to storage
    Storage::disk('public')->put("label_{$shipmentNumber}.pdf", $pdfContent);
}

$waybill = "37133804481";
$response = Aramex::tracking()->track([$waybill]);

use Shibin\Aramex\DTO\Pickup;

$pickup = new Pickup();
$pickup->address = $addressObject;
$pickup->pickup_location = 'Reception';
$pickup->pickup_date = strtotime('+1 day');
$pickup->ready_time = strtotime('10:00', $pickup->pickup_date);
$pickup->last_pickup_time = strtotime('15:00', $pickup->pickup_date);
$pickup->closing_time = strtotime('17:00', $pickup->pickup_date);
$pickup->weight = 5;
$pickup->volume = 2;

$response = Aramex::pickup()->create($pickup);

$isValid = Aramex::location()->validateAddress($addressObject);
bash
php artisan vendor:publish --tag=aramex-config