PHPackages                             smart-dato/fedex-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. smart-dato/fedex-sdk

ActiveLibrary[API Development](/categories/api)

smart-dato/fedex-sdk
====================

This is my package fedex-sdk

0.0.10(4w ago)01.1k↓81.1%1MITPHPPHP ^8.2|^8.5

Since Nov 11Pushed 4w ago2 watchersCompare

[ Source](https://github.com/smart-dato/fedex-sdk)[ Packagist](https://packagist.org/packages/smart-dato/fedex-sdk)[ Docs](https://github.com/smart-dato/fedex-sdk)[ RSS](/packages/smart-dato-fedex-sdk/feed)WikiDiscussions main Synced yesterday

READMEChangelog (5)Dependencies (65)Versions (11)Used By (0)

This is my package fedex-sdk
============================

[](#this-is-my-package-fedex-sdk)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0ad7ddc1f0f2f6d0556df513c0db34519ef2a0a9cbb3c0fb637f951aff987c5d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736d6172742d6461746f2f66656465782d73646b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/smart-dato/fedex-sdk)[![GitHub Tests Action Status](https://camo.githubusercontent.com/02de2b245f30c7bd37d337c1ca6bfa57df60f0975b072881eaa3142cc74297f2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736d6172742d6461746f2f66656465782d73646b2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/smart-dato/fedex-sdk/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/ba3f40f562aaf1ef85d48c5db5efb361190689a6232e471d2bf63d86b6407f8f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f736d6172742d6461746f2f66656465782d73646b2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/smart-dato/fedex-sdk/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/80028019f8e7ffab65fcd2c7c6c656e2eb424e2b0da809c5ece59d909a5c70e7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736d6172742d6461746f2f66656465782d73646b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/smart-dato/fedex-sdk)

A comprehensive Laravel package for integrating with the FedEx REST API. This package provides OAuth 2.0 authentication, automatic token management, shipment creation, tracking, and more. Built with modern PHP practices and Laravel conventions.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require smart-dato/fedex-sdk
```

Publish the configuration file:

```
php artisan vendor:publish --tag="fedex-config"
```

### Environment Variables

[](#environment-variables)

Add the following variables to your `.env` file:

```
# FedEx Environment (sandbox or production)
FEDEX_ENVIRONMENT=sandbox

# FedEx OAuth Credentials
FEDEX_CLIENT_ID=your-client-id
FEDEX_CLIENT_SECRET=your-client-secret

# FedEx Account Number
FEDEX_ACCOUNT_NUMBER=your-account-number

# Optional: Label Response Options (URL_ONLY or LABEL)
FEDEX_LABEL_RESPONSE_OPTIONS=URL_ONLY

# Optional: Token Cache TTL in seconds (default: 3500)
FEDEX_TOKEN_CACHE_TTL=3500
```

### Getting FedEx API Credentials

[](#getting-fedex-api-credentials)

1. Go to [FedEx Developer Portal](https://developer.fedex.com/)
2. Create an account or sign in
3. Create a new project
4. Generate API credentials (Client ID and Client Secret)
5. Use sandbox credentials for testing and production credentials for live operations

Usage
-----

[](#usage)

### OAuth Authentication

[](#oauth-authentication)

The package handles OAuth authentication automatically. Tokens are cached to minimize API calls and automatically refreshed when needed.

```
use SmartDato\FedEx\Fedex;

class ShippingController extends Controller
{
    public function __construct(private Fedex $fedex)
    {
    }

    public function createShipment()
    {
        // The OAuth token is automatically managed
        $result = $this->fedex->createShipment($shipmentPayload);
    }
}
```

#### Manual Token Management

[](#manual-token-management)

If you need to manually manage tokens:

```
use SmartDato\FedEx\Fedex;

public function __construct(private Fedex $fedex)
{
}

// Force refresh the OAuth token
$newToken = $this->fedex->refreshToken();

// Get the OAuth client directly
$oauthClient = $this->fedex->getOAuthClient();

// Get current access token
$token = $oauthClient->getAccessToken();

// Clear cached token
$oauthClient->clearToken();
```

### Creating a Shipment

[](#creating-a-shipment)

```
use SmartDato\FedEx\Fedex;
use SmartDato\FedEx\Payloads\ShipmentPayload;
use SmartDato\FedEx\Payloads\ShipperPayload;
use SmartDato\FedEx\Payloads\RecipientPayload;
use SmartDato\FedEx\Payloads\AddressPayload;
use SmartDato\FedEx\Payloads\ContactPayload;
use SmartDato\FedEx\Payloads\RequestedPackageLineItemPayload;
use SmartDato\FedEx\Payloads\WeightPayload;
use SmartDato\FedEx\Enums\WeightUnitEnum;
use SmartDato\FedEx\Enums\PackagingTypeEnum;
use SmartDato\FedEx\Enums\PickupTypeEnum;

$shipment = ShipmentPayload::make()
    ->setShipper(
        ShipperPayload::make()
            ->setContact(
                ContactPayload::make()
                    ->setPersonName('John Doe')
                    ->setPhoneNumber('1234567890')
            )
            ->setAddress(
                AddressPayload::make()
                    ->setStreetLines(['123 Main St'])
                    ->setCity('Memphis')
                    ->setStateOrProvinceCode('TN')
                    ->setPostalCode('38115')
                    ->setCountryCode('US')
            )
    )
    ->setRecipient(
        RecipientPayload::make()
            ->setContact(
                ContactPayload::make()
                    ->setPersonName('Jane Smith')
                    ->setPhoneNumber('0987654321')
            )
            ->setAddress(
                AddressPayload::make()
                    ->setStreetLines(['456 Oak Ave'])
                    ->setCity('Los Angeles')
                    ->setStateOrProvinceCode('CA')
                    ->setPostalCode('90001')
                    ->setCountryCode('US')
            )
    )
    ->setRequestedPackageLineItems([
        RequestedPackageLineItemPayload::make()
            ->setWeight(
                WeightPayload::make()
                    ->setValue(10.0)
                    ->setUnits(WeightUnitEnum::LB)
            )
    ])
    ->setPickupType(PickupTypeEnum::DROPOFF_AT_FEDEX_LOCATION)
    ->setPackagingType(PackagingTypeEnum::YOUR_PACKAGING);

// Inject or resolve the Fedex service
$fedex = app(Fedex::class);
$response = $fedex->createShipment($shipment);
```

### Tracking a Shipment

[](#tracking-a-shipment)

```
use SmartDato\FedEx\Fedex;
use SmartDato\FedEx\Enums\TrackBy;

// Inject or resolve the Fedex service
$fedex = app(Fedex::class);

// Track by tracking number (default)
$tracking = $fedex->trackShipment('123456789012');

// Track by tracking number with detailed scans
$tracking = $fedex->trackShipment('123456789012', TrackBy::TRACKING_NUMBER, [
    'includeDetailedScans' => true,
]);

// Track by TCN (Tracking Control Number)
$tracking = $fedex->trackShipment('123456789012', TrackBy::TCN);

// Track by reference number with ship date range
$tracking = $fedex->trackShipment('REFERENCE123', TrackBy::REFERENCE_NUMBER, [
    'shipDateBegin' => '2024-01-01',
    'shipDateEnd' => '2024-01-31',
    'includeDetailedScans' => true,
]);

// Track multiple shipments at once
$tracking = $fedex->trackMultipleShipments([
    '123456789012',
    '123456789013',
    '123456789014',
], [
    'includeDetailedScans' => true,
]);
```

### Trade Documents (ETD Upload)

[](#trade-documents-etd-upload)

The Trade Documents endpoints are exposed on a dedicated sub-client via `Fedex::tradeDocuments()`. Three operations are supported: single document upload, multi-document upload (max 5 per call), and letterhead/signature image upload.

#### Upload a single document (pre or post-shipment)

[](#upload-a-single-document-pre-or-post-shipment)

```
use SmartDato\FedEx\Fedex;
use SmartDato\FedEx\Enums\CountryEnum;
use SmartDato\FedEx\Enums\EtdContentTypeEnum;
use SmartDato\FedEx\Enums\EtdWorkflowEnum;
use SmartDato\FedEx\Enums\ShipDocumentTypeEnum;
use SmartDato\FedEx\Payloads\EtdMetaPayload;
use SmartDato\FedEx\Payloads\EtdUploadDocumentPayload;

$payload = new EtdUploadDocumentPayload(
    workflowName: EtdWorkflowEnum::PRE_SHIPMENT,
    fileName: 'invoice.pdf',
    contentType: EtdContentTypeEnum::PDF,
    meta: new EtdMetaPayload(
        shipDocumentType: ShipDocumentTypeEnum::COMMERCIAL_INVOICE,
        originCountryCode: CountryEnum::US,
        destinationCountryCode: CountryEnum::CA,
    ),
);

$response = app(Fedex::class)
    ->tradeDocuments()
    ->upload($payload, '/path/to/invoice.pdf');
```

For post-shipment uploads, also pass `carrierCode`, `trackingNumber`, `shipmentDate`, and the FedEx origin/destination location codes returned by the create-shipment response.

#### Upload multiple documents in one call

[](#upload-multiple-documents-in-one-call)

```
use SmartDato\FedEx\Enums\CarrierCodeEnum;
use SmartDato\FedEx\Payloads\EtdMultiMetaPayload;
use SmartDato\FedEx\Payloads\EtdMultiUploadPayload;

$payload = new EtdMultiUploadPayload(
    workflowName: EtdWorkflowEnum::PRE_SHIPMENT,
    carrierCode: CarrierCodeEnum::FDXE,
    originCountryCode: CountryEnum::US,
    destinationCountryCode: CountryEnum::CA,
    metaData: [
        new EtdMultiMetaPayload(
            fileName: 'invoice.pdf',
            contentType: EtdContentTypeEnum::PDF,
            shipDocumentType: ShipDocumentTypeEnum::COMMERCIAL_INVOICE,
            filePath: '/path/to/invoice.pdf',
            fileReferenceId: 'CI_1',
            formCode: 'USMCA',
        ),
        new EtdMultiMetaPayload(
            fileName: 'origin.pdf',
            contentType: EtdContentTypeEnum::PDF,
            shipDocumentType: ShipDocumentTypeEnum::USMCA_CERTIFICATION_OF_ORIGIN,
            filePath: '/path/to/origin.pdf',
            fileReferenceId: 'CO_1',
            formCode: 'USMCA',
        ),
    ],
);

$response = app(Fedex::class)
    ->tradeDocuments()
    ->uploadMultiple($payload);
```

A maximum of 5 documents per call is enforced.

#### Upload a custom letterhead or signature image

[](#upload-a-custom-letterhead-or-signature-image)

```
use SmartDato\FedEx\Enums\LhsImageContentTypeEnum;
use SmartDato\FedEx\Enums\LhsImageIndexEnum;
use SmartDato\FedEx\Enums\LhsImageTypeEnum;
use SmartDato\FedEx\Payloads\LhsImageUploadPayload;

$payload = new LhsImageUploadPayload(
    referenceId: '1234',
    name: 'signature.png',
    contentType: LhsImageContentTypeEnum::PNG,
    imageType: LhsImageTypeEnum::SIGNATURE,
    imageIndex: LhsImageIndexEnum::IMAGE_1,
);

$response = app(Fedex::class)
    ->tradeDocuments()
    ->uploadLetterheadOrSignature($payload, '/path/to/signature.png');
```

Each upload method also accepts an optional `$customerTransactionId` argument that is passed as the `x-customer-transaction-id` header and echoed back in the response — useful for matching async/multi requests.

### OAuth Token Caching

[](#oauth-token-caching)

The package automatically caches OAuth tokens using Laravel's cache system. By default:

- Tokens are cached for 3500 seconds (just under 1 hour)
- Cache key is `fedex_oauth_token`
- Tokens are automatically refreshed when expired

You can customize these settings in the config file or via environment variables.

### Error Handling

[](#error-handling)

```
use SmartDato\FedEx\Fedex;
use Illuminate\Http\Client\ConnectionException;
use RuntimeException;

$fedex = app(Fedex::class);

try {
    $result = $fedex->createShipment($shipmentPayload);
} catch (ConnectionException $e) {
    // Handle connection errors
    Log::error('FedEx API connection error: ' . $e->getMessage());
} catch (RuntimeException $e) {
    // Handle OAuth or other runtime errors
    Log::error('FedEx API error: ' . $e->getMessage());
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [smart-dato](https://github.com/smart-dato)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance94

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 64.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Recently: every ~7 days

Total

10

Last Release

29d ago

PHP version history (2 changes)0.0.1PHP ^8.2

0.0.6PHP ^8.2|^8.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/c3006db55caec62526937fa2d941da32fc5e69e2ca86a52e87c8046da5958d82?d=identicon)[smart-dato](/maintainers/smart-dato)

---

Top Contributors

[![tschigo](https://avatars.githubusercontent.com/u/344100?v=4)](https://github.com/tschigo "tschigo (9 commits)")[![michael-tscholl](https://avatars.githubusercontent.com/u/178569346?v=4)](https://github.com/michael-tscholl "michael-tscholl (5 commits)")

---

Tags

laravelsmart-datofedex-sdk

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/smart-dato-fedex-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/smart-dato-fedex-sdk/health.svg)](https://phpackages.com/packages/smart-dato-fedex-sdk)
```

###  Alternatives

[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M100](/packages/dedoc-scramble)[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.6k3](/packages/defstudio-telegraph)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

44855.7k](/packages/harris21-laravel-fuse)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
