PHP code example of octw / aramex

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

    

octw / aramex example snippets


  use Octw\Aramex\Aramex;
  

  'Aramex' => Octw\Aramex\Aramex::class,
  

    use Aramex;
  

            'shipper' => [
                'name' => 'Steve', 
                'email' => '[email protected]', 
                'phone'      => '+123456789982',
                'cell_phone' => '+321654987789',
                'country_code' => 'US',
                'city' => 'New York',
                'zip_code' => 10001,
                'line1' => 'Line1 Details',
                'line2' => 'Line2 Details',
                'line3' => 'Line3 Details',
            ],
            'consignee' => [
                'name' => 'Steve',
                'email' => '[email protected]',
                'phone'      => '+123456789982',
                'cell_phone' => '+321654987789',
                'country_code' => 'US',
                'city' => 'New York',
                'zip_code' => 10001,
                'line1' => 'Line1 Details',
                'line2' => 'Line2 Details',
                'line3' => 'Line3 Details',
            ],
            'shipping_date_time' => time() + 50000, // shipping date
            'due_date' => time() + 60000,  // due date of the shipment
            'comments' => 'No Comment', // ,comments
            'pickup_location' => 'at reception', // location as pickup
            'pickup_guid' => $guid, // GUID taken from createPickup method (optional)
            'weight' => 1, // weight
            'goods_country' => null, // optional
            'number_of_pieces' => 1,  // number of items
            'description' => 'Goods Description, like Boxes of flowers', // description
            'reference' => '01020102' // reference to print on shipment report (policy)
            'shipper_reference' => '19191', // optional
            'consignee_reference' => '010101', // optional 
            'services' => 'CODS,FIRST,FRDM, .. ' // ',' seperated string, refer to services in the official documentation
            'cash_on_delivery_amount' => 10.32 // in case of CODS (in USD only "as they want")
            'insurance_amount' => 0, // optional
            'collect_amount' => 0, // optional
            'customs_value_amount' => 0, //optional (
  
        $callResponse = Aramex::createShipment([
            'shipper' => [
                'name' => 'Steve',
                'email' => '[email protected]',
                'phone'      => '+123456789982',
                'cell_phone' => '+321654987789',
                'country_code' => 'US',
                'city' => 'New York',
                'zip_code' => 32160,
                'line1' => 'Line1 Details',
                'line2' => 'Line2 Details',
                'line3' => 'Line3 Details',
            ],
            'consignee' => [
                'name' => 'Steve',
                'email' => '[email protected]',
                'phone'      => '+123456789982',
                'cell_phone' => '+321654987789',
                'country_code' => 'US',
                'city' => 'New York',
                'zip_code' => 32160,
                'line1' => 'Line1 Details',
                'line2' => 'Line2 Details',
                'line3' => 'Line3 Details',
            ],
            'shipping_date_time' => time() + 50000,
            'due_date' => time() + 60000,
            'comments' => 'No Comment',
            'pickup_location' => 'at reception',
            // 'pickup_guid' => $guid,
            'weight' => 1,
            'number_of_pieces' => 1,
            'description' => 'Goods Description, like Boxes of flowers',
        ]);
        if (!empty($callResponse->error))
        {
            foreach ($callResponse->errors as $errorObject) {
              handleError($errorObject->Code, $errorObject->Message);
            }
        }
        else {
          // extract your data here, for example
          // $shipmentId = $response->Shipments->ProcessedShipment->ID;
          // $labelUrl = $response->Shipments->ProcessedShipment->ShipmentLabel->LabelURL;
        }

  
  $data = Aramex::validateAddress([
    'line1':'Test', // optional (Passing it is recommended)
    'line2':'Test', // optional
    'line3':'Test', // optional
    'country_code':'JO',
    'postal_code':'', // optional
    'city':'Amman',
  ]);

 bash
  php artisan vendor:publish --provider="Octw\Aramex\AramexServiceProvider"
  
 php 
    $data = Aramex::createPickup([
    		'name' => 'MyName',
    		'cell_phone' => '+123123123',
    		'phone' => '+123123123',
    		'email' => '[email protected]',
    		'city' => 'New York',
    		'country_code' => 'US',
            'zip_code'=> 10001,
    		'line1' => 'The line1 Details',
            'line2' => 'The line2 Details',
    		'line3' => 'The line2 Details',
    		'pickup_date' => time() + 45000,
    		'ready_time' => time()  + 43000,
    		'last_pickup_time' => time() +  45000,
    		'closing_time' => time()  + 45000,
    		'status' => 'Ready', 
    		'pickup_location' => 'some location',
    		'weight' => 123,
    		'volume' => 1
    	]);

        // extracting GUID
       if (!$data->error)
          $guid = $data->pickupGUID;
 php
        $shipments = [ 
            $createShipmentResults->Shipments->ProcessedShipment->ID,
            $anotherCreateShipmentResults->Shipments->ProcessedShipment->ID,
        ];

        $data = Aramex::trackShipments($shipments);
 php
        $shipments = [ 
            $createShipmentResults->Shipments->ProcessedShipment->ID,
            $anotherCreateShipmentResults->Shipments->ProcessedShipment->ID,
        ];

        $data = Aramex::trackShipments($shipments);
        
        if (!$data->error){
          // Code Here
        }
        else {
        // handle error
        }
 php

        $data = Aramex::fetchCountries($countryCode); 
        // Or 
        $data = Aramex::fetchCountries();
 php

        $data = Aramex::fetchCities('AE');