PHPackages                             pralhadstha/aftership-laravel - 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. pralhadstha/aftership-laravel

ActiveLibrary[API Development](/categories/api)

pralhadstha/aftership-laravel
=============================

A modern Laravel wrapper for the AfterShip Tracking API with driver support, DTOs, and webhook handling.

v1.0.0(2mo ago)015MITPHPPHP ^8.2

Since Apr 1Pushed 2mo agoCompare

[ Source](https://github.com/pralhadstha/aftership-laravel)[ Packagist](https://packagist.org/packages/pralhadstha/aftership-laravel)[ RSS](/packages/pralhadstha-aftership-laravel/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (8)Versions (2)Used By (0)

AfterShip Laravel SDK
=====================

[](#aftership-laravel-sdk)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2a26cba81b152a37df6d618377e4580e26c671033b1e91d5d8310dd944ce8c0c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7072616c686164737468612f6166746572736869702d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pralhadstha/aftership-laravel)[![Total Downloads](https://camo.githubusercontent.com/e2c6c3f7265d1d35b1f54274bd60fe12f93e246947dcfb3b7ab893add5e2e9ac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7072616c686164737468612f6166746572736869702d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pralhadstha/aftership-laravel)[![License](https://camo.githubusercontent.com/685909515ac831b8b551af34d04b320d4f7d8115cbec621f954ed5a49d31fa5f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7072616c686164737468612f6166746572736869702d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/161211511919feae10ce713bd7e78a6b3591cfe6db61f6159aa8b78c4bea51e4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f7072616c686164737468612f6166746572736869702d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pralhadstha/aftership-laravel)[![Laravel](https://camo.githubusercontent.com/b21bc2003aa619c22eebfa5bcd69dca1cc7effe70502ebde76cd4801f3c84f9e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d3130253230253743253230313125323025374325323031322d4646324432303f7374796c653d666c61742d737175617265266c6f676f3d6c61726176656c266c6f676f436f6c6f723d7768697465)](https://laravel.com)

A modern, production-ready Laravel package for integrating with the [AfterShip Tracking API](https://www.aftership.com/docs/tracking) to track shipments, parcels, and deliveries across 1,200+ carriers worldwide. Supports DHL, FedEx, UPS, USPS, and more with a clean driver-based architecture, immutable DTOs, webhook verification, and full test support.

If you're building an e-commerce platform, order management system, or logistics dashboard in Laravel and need shipment tracking, courier detection, or delivery estimates from AfterShip, this package provides a clean, testable integration out of the box.

Why This Package?
-----------------

[](#why-this-package)

- **Driver Pattern** — Choose between the official AfterShip SDK or Laravel's HTTP client. Swap drivers without changing your code.
- **Immutable DTOs** — All API responses are mapped to typed, immutable Data Transfer Objects.
- **Webhook Support** — Built-in HMAC signature verification for secure webhook handling.
- **Testable** — Includes a `FakeDriver` for testing without API calls. No mocking needed.
- **Interactive Installer** — `php artisan aftership:install` guides you through setup with Laravel Prompts.
- **Laravel Auto-Discovery** — Zero-config service provider and facade registration.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.2
- Laravel 10, 11, or 12

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

[](#installation)

```
composer require pralhadstha/aftership-laravel
```

Then run the interactive installer:

```
php artisan aftership:install
```

The installer will guide you through:

- Selecting a driver (`sdk` or `http`)
- Installing the AfterShip SDK (if the `sdk` driver is selected)
- Configuring your API key
- Publishing the config file

### Manual Setup

[](#manual-setup)

If you prefer to configure manually, publish the config and set your `.env` values:

```
php artisan vendor:publish --tag=aftership-config
```

Configuration
-------------

[](#configuration)

Set your API key in `.env`:

```
AFTERSHIP_API_KEY=your-api-key
AFTERSHIP_DRIVER=sdk
```

Full configuration options in `config/aftership.php`:

```
return [
    'api_key'        => env('AFTERSHIP_API_KEY', ''),
    'driver'         => env('AFTERSHIP_DRIVER', 'sdk'),   // sdk, http
    'base_url'       => env('AFTERSHIP_BASE_URL', 'https://api.aftership.com'),
    'api_version'    => env('AFTERSHIP_API_VERSION', 'tracking/2026-01'), // HTTP driver only
    'timeout'        => env('AFTERSHIP_TIMEOUT', 30),
    'webhook_secret' => env('AFTERSHIP_WEBHOOK_SECRET', ''),
];
```

### Drivers

[](#drivers)

DriverDescriptionExtra dependency`sdk`Wraps the official [AfterShip Tracking SDK](https://github.com/AfterShip/tracking-sdk-php) (default)`aftership/tracking-sdk``http`Uses Laravel's HTTP client (`Http::`) directlyNoneIf you choose the `sdk` driver, the `aftership:install` command will install the SDK for you automatically. For manual setup, run:

```
composer require aftership/tracking-sdk
```

The `http` driver works out of the box with no extra dependencies.

Usage
-----

[](#usage)

### Tracking Shipments

[](#tracking-shipments)

```
use OmniCargo\Aftership\Laravel\Facades\AfterShip;

// Create a tracking
$tracking = AfterShip::tracking()->create([
    'tracking_number' => '1234567890',
    'slug' => 'dhl',
]);

// Get a tracking
$tracking = AfterShip::tracking()->get('tracking-id');

// List trackings
$collection = AfterShip::tracking()->list(['page' => 1, 'limit' => 10]);

// Update a tracking
$tracking = AfterShip::tracking()->update('tracking-id', [
    'title' => 'My Shipment',
]);

// Delete a tracking
AfterShip::tracking()->delete('tracking-id');

// Mark as completed
AfterShip::tracking()->markCompleted('tracking-id', 'DELIVERED');
```

### Couriers

[](#couriers)

```
// List all couriers
$couriers = AfterShip::courier()->list();

// Detect courier by tracking number
$detected = AfterShip::courier()->detect([
    'tracking_number' => '1234567890',
]);

// Get courier details
$courier = AfterShip::courier()->get('dhl');
```

### Delivery Estimates

[](#delivery-estimates)

```
$estimate = AfterShip::deliveryEstimate()->estimate([
    'slug' => 'dhl',
    'service_type_name' => 'Express',
    'origin_address' => 'New York, USA',
    'destination_address' => 'London, UK',
]);
```

### Dependency Injection

[](#dependency-injection)

```
use OmniCargo\Aftership\Laravel\Client\AfterShipClient;

class ShipmentController extends Controller
{
    public function __construct(
        private readonly AfterShipClient $aftership,
    ) {}

    public function show(string $id)
    {
        $tracking = $this->aftership->tracking()->get($id);

        return response()->json($tracking->toArray());
    }
}
```

### Webhooks

[](#webhooks)

```
use OmniCargo\Aftership\Laravel\Webhooks\WebhookHandler;

class AfterShipWebhookController extends Controller
{
    public function __construct(
        private readonly WebhookHandler $webhook,
    ) {}

    public function handle(Request $request)
    {
        $payload = $this->webhook->handle(
            $request->getContent(),
            $request->header('aftership-hmac-sha256'),
        );

        $event = $this->webhook->getEventName($payload);
        $tracking = $this->webhook->getTrackingData($payload);

        // Handle events: tracking.updated, tracking.delivered, tracking.exception
        match ($event) {
            'tracking.delivered' => $this->handleDelivered($tracking),
            'tracking.exception' => $this->handleException($tracking),
            default => null,
        };

        return response()->json(['status' => 'ok']);
    }
}
```

### DTOs

[](#dtos)

All API responses are mapped to immutable Data Transfer Objects:

- `TrackingData` — tracking information with checkpoints
- `CourierData` — courier details
- `DeliveryEstimateData` — estimated delivery date
- `TrackingCollection` — paginated list of trackings
- `CheckpointData` — individual checkpoint

```
$tracking = AfterShip::tracking()->get('id');

$tracking->trackingNumber;  // string
$tracking->slug;            // string
$tracking->tag;             // string (e.g., "InTransit", "Delivered")
$tracking->checkpoints;     // array
$tracking->toArray();       // array representation
```

### Error Handling

[](#error-handling)

The package throws specific exceptions for different API error scenarios:

```
use OmniCargo\Aftership\Laravel\Exceptions\AuthenticationException;
use OmniCargo\Aftership\Laravel\Exceptions\RateLimitException;
use OmniCargo\Aftership\Laravel\Exceptions\ApiException;

try {
    $tracking = AfterShip::tracking()->get('id');
} catch (AuthenticationException $e) {
    // Invalid or missing API key (401)
} catch (RateLimitException $e) {
    // Rate limit exceeded (429)
} catch (ApiException $e) {
    // Other API errors
    $e->getStatusCode();
    $e->getErrorType();
    $e->getMessage();
}
```

### Testing

[](#testing)

Use the built-in `FakeDriver` for testing without making real API calls:

```
use OmniCargo\Aftership\Laravel\AfterShipManager;
use OmniCargo\Aftership\Laravel\Contracts\ClientInterface;

// In your test
$this->app['config']->set('aftership.driver', 'fake');

$client = $this->app->make(ClientInterface::class);
$tracking = $client->tracking()->create([
    'tracking_number' => 'TEST123',
    'slug' => 'dhl',
]);

// Assert on the FakeDriver
$fakeDriver = $client->driver();
$this->assertTrue($fakeDriver->assertCalled('createTracking'));
```

Running Tests
-------------

[](#running-tests)

```
composer install
vendor/bin/phpunit
```

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

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Security
--------

[](#security)

If you discover any security-related issues, please report them via [GitHub Security Advisories](https://github.com/pralhadstha/aftership-laravel/security/advisories) instead of using the issue tracker.

Credits
-------

[](#credits)

- [Pralhad Kumar Shrestha](https://github.com/pralhadstha)

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance83

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

86d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d46fb8b473d604d2f5eb4e27451ef88b44e10a430c0a0ce89b4e501fcfe95b2?d=identicon)[pralhad](/maintainers/pralhad)

---

Top Contributors

[![pralhadstha](https://avatars.githubusercontent.com/u/6309194?v=4)](https://github.com/pralhadstha "pralhadstha (8 commits)")

---

Tags

aftershipaftership-sdkslaravellaravel-packagephpshipment-trackingapilaravelsdktrackingwebhookecommercedtoshippingdeliverycourierlogisticsparcelaftershipshipment-trackingdriver-pattern

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pralhadstha-aftership-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/pralhadstha-aftership-laravel/health.svg)](https://phpackages.com/packages/pralhadstha-aftership-laravel)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

815320.5k3](/packages/defstudio-telegraph)[simplestats-io/laravel-client

Analytics for Laravel. Track visitors, registrations, and payments. Discover which channels actually drive revenue, not just traffic. Server-side, GDPR compliant, ad-blocker proof.

5019.3k](/packages/simplestats-io-laravel-client)[spatie/laravel-export

Create a static site bundle from a Laravel app

672139.5k6](/packages/spatie-laravel-export)[api-platform/laravel

API Platform support for Laravel

59156.3k11](/packages/api-platform-laravel)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1232.2k16](/packages/fleetbase-core-api)

PHPackages © 2026

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