PHP code example of shipper / aramex

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

    

shipper / aramex example snippets


use Shipper\Aramex\Aramex;

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

  use Aramex;

    "name" => 'John' // User’s Name, Sent By or in the case of the consignee, to the Attention of.
    "cell_phone" => '+123456789' // Phone Number
    "phone" => '+123456789' // Phone Number
    "email" => '[email protected]'
    "country_code" => 'US' // ISO 3166-1 Alpha-2 Code
    "city" => 'New York' // City Name
    "zip_code" => 10001 // Postal Code
    "line1" => 'Line 1 Details'
    "line2" => 'Line 2 Details'
    "line3" => 'Line 3 Details'
    "pickup_date" => time() // time parameter describe the date of the pickup
    "ready_time" => time() // time parameter describe the ready pickup date
    "last_pickup_time" => time() // time parameter
    "closing_time" => time() // time parameter
    "status" => 'Ready' // or Pending
    "pickup_location" => 'at company's reception' // location details
    "weight" => 12 // wieght of the pickup (in KG)
    "volume" => 80 // volume of the pickup  (in CM^3)

    $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;

            '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;
        }

    [
        'line1' => 'String|Required',
        'line2' => 'String',
        'line3' => 'String',
        'city' => 'String|Required',
        'state_code' => 'String',
        'postal_code' => 'String',
        'country_code' => 'String|max:2|min:2|Required',
        'longitude' => 'Double',
        'latitude' => 'Double',
        'building_number' => 'String',
        'building_name' => 'String',
    ]

    [
        'payment_type' => '', // default value in config file
        'product_group' => '', // default value in config file
        'product_type' => '', // default value in config file
        'weight' => 5.2, // IN KG (Kilograms)
        'number_of_pieces' => 'Integer|Required',
        'height' => 5, // Dimensions in CM (optional)
        'width' => 3,  // Dimensions in CM (optional)
        'length' => 2  // Dimensions in CM (optional)
    ]

        $originAddress = [
            'line1' => 'Test string',
            'city' => 'Amman',
            'country_code' => 'JO'
        ];

        $destinationAddress = [
            'line1' => 'Test String',
            'city' => 'Dubai',
            'country_code' => 'AE'
        ];

        $shipmentDetails = [
            'weight' => 5, // KG
            'number_of_pieces' => 2,
            'payment_type' => 'P', // if u don't pass it, it will take the config default value
            'product_group' => 'EXP', // if u don't pass it, it will take the config default value
            'product_type' => 'PPX', // if u don't pass it, it will take the config default value
            'height' => 5.5, // CM
            'width' => 3,  // CM
            'length' => 2.3  // CM
        ];

        $shipmentDetails = [
            'weight' => 5, // KG
            'number_of_pieces' => 2,
        ];

        $currency = 'USD';
        $data = Aramex::calculateRate($originAddress, $destinationAddress , $shipmentDetails , 'USD');

        if(!$data->error){
          dd($data);
        }
        else{
          // handle $data->errors
        }

        $shipments = [
            $createShipmentResults->Shipments->ProcessedShipment->ID,
            $anotherCreateShipmentResults->Shipments->ProcessedShipment->ID,
        ];

        $data = Aramex::trackShipments($shipments);

        $shipments = [
            $createShipmentResults->Shipments->ProcessedShipment->ID,
            $anotherCreateShipmentResults->Shipments->ProcessedShipment->ID,
        ];

        $data = Aramex::trackShipments($shipments);

        if (!$data->error){
          // Code Here
        }
        else {
        // handle error
        }


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


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



  $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="Shipper\Aramex\AramexServiceProvider"