PHP code example of mohamedhekal / shipbridge-fedex

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

    

mohamedhekal / shipbridge-fedex example snippets


use Hekal\ShipBridge\Facades\ShipBridge;
use Hekal\ShipBridge\DTOs\Address;
use Hekal\ShipBridge\DTOs\CreateShipmentRequest;
use Hekal\ShipBridge\DTOs\Parcel;

$shipment = ShipBridge::driver('fedex')->createShipment(new CreateShipmentRequest(
    origin: new Address('المخزن', 'شارع ١', 'القاهرة', 'EG', phone: '01011111111', postalCode: '11511'),
    destination: new Address('العميل', 'شارع النيل', 'الجيزة', 'EG', phone: '01000000000', postalCode: '12613'),
    parcels: [new Parcel(weightKg: 1.2)],
    reference: 'ORD-42',
));

echo $shipment->trackingNumber;

// PDF label (base64) is in create response raw — persist it yourself:
$pdf = $shipment->raw['output']['transactionShipments'][0]['pieceResponses'][0]['packageDocuments'][0]['encodedLabel'] ?? null;

ShipBridge::driver('fedex')->track($shipment->trackingNumber);
ShipBridge::driver('fedex')->label($shipment->trackingNumber); // FedEx public tracking URL

ShipBridge::driver('fedex')->createShipment(...);  // POST /ship/v1/shipments
ShipBridge::driver('fedex')->track('7946...');    // POST /track/v1/trackingnumbers
ShipBridge::driver('fedex')->label('7946...');   // public tracking URL (PDF from create raw)