PHPackages                             nextgenbite/laravel-shipping - 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. nextgenbite/laravel-shipping

ActiveLibrary[API Development](/categories/api)

nextgenbite/laravel-shipping
============================

Shipping package for Laravel. Supported providers: CanadaPost, USPS, UPS, FedEx and Purolator.

00PHP

Since Nov 29Pushed 1y ago1 watchersCompare

[ Source](https://github.com/nextgenbite/laravel-shipping)[ Packagist](https://packagist.org/packages/nextgenbite/laravel-shipping)[ RSS](/packages/nextgenbite-laravel-shipping/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Shipping package for Laravel
============================

[](#shipping-package-for-laravel)

Supported shipping providers:

- UPS REST/OAuth API
- FedEx REST/OAuth API
- Canada Post
- USPS
- Purolator

Package can be used outside the Laravel environment as well (by making individual shipping provider requests).

Supported API services:

Shipping ProviderRate APIShipment APIUPS REST✓✓FedEx REST✓✓Canada Post✓✓Purolator✓✓USPS✓-### Install package

[](#install-package)

```
composer require nextgenbite/laravel-shipping
```

### Run migrations

[](#run-migrations)

```
php artisan migrate
```

### Setup .env variables

[](#setup-env-variables)

```
CANADA_POST_CUSTOMER_NUMBER=
CANADA_POST_USERNAME=
CANADA_POST_PASSWORD=

PUROLATOR_KEY=
PUROLATOR_PASSWORD=
PUROLATOR_BILLING_ACCOUNT=
PUROLATOR_REGISTERED_ACCOUNT=
PUROLATOR_USER_TOKEN=

UPS_CLIENT_ID=
UPS_CLIENT_SECRET=
UPS_USER_ID=
UPS_ACCOUNT_NUMBER=

USPS_USERNAME=
USPS_PASSWORD=

FEDEX_CLIENT_ID=
FEDEX_CLIENT_SECRET=
FEDEX_ACCOUNT_NUMBER=

SHIPPING_SANDBOX=false

```

### Using sandbox credentials

[](#using-sandbox-credentials)

In order to use test credentials just add param "true" in the \*Credentials() object or set environment variable SHIPPING\_SANDBOX=false.

### Models

[](#models)

There are 4 Eloquent models available: ShippingService, ShippingBox, ShippingOption and ShippingOptionPrice.

ShippingBox and ShippingOptionPrice are used for service Flat. Creating ShippingBox and creating ShippingOptionPrice will allow users to set flat rate shipping prices.

### Shipping Quotes

[](#shipping-quotes)

#### Retrieve all shipping rates, for all enabled shipping providers.

[](#retrieve-all-shipping-rates-for-all-enabled-shipping-providers)

```
$exceptions = [];

$rates = app(\Mitrik\Shipping\Facades\Shipping::class)->rates(
    new Address(
        'Ivan',
        'Mitrikeski',
        '',
        '321 Lakeshore Rd W',
        '',
        'Mississauga',
        'L5H 1G0',
        'ON',
        'CA'
    ),
    new Address(
        'Ivan',
        'Mitrikeski',
        '',
        '100 City Centre Dr',
        '',
        'Mississauga',
        'L5B 2C9',
        'ON',
        'CA'
    ),
    new \Mitrik\Shipping\ServiceProviders\Box\BoxCollection([
        new BoxMetric(20, 10, 5, 1)
    ]),
    $exceptions
);
```

Fourth parameter `$exceptions` is optional. If provided function will push all exception to provided array. If not provided, an exception will be thrown each time there is an issue retrieving a quote.

##### Canada Post

[](#canada-post)

```
use Mitrik\Shipping\ServiceProviders\Address\Address;
use Mitrik\Shipping\ServiceProviders\Box\BoxCollection;
use Mitrik\Shipping\ServiceProviders\Box\BoxMetric;
use Mitrik\Shipping\ServiceProviders\ServiceCanadaPost\ServiceCanadaPost;
use Mitrik\Shipping\ServiceProviders\ServiceCanadaPost\ServiceCanadaPostCredentials;

$credentials = new ServiceCanadaPostCredentials(env('CANADA_POST_CUSTOMER_NUMBER'), env('CANADA_POST_USERNAME'), env('CANADA_POST_PASSWORD'));
$canadaPost = new ServiceCanadaPost($credentials);

$rates = $canadaPost->rate(
    new Address(
        'Ivan',
        'Mitrikeski',
        '',
        '321 Lakeshore Rd W',
        '',
        'Mississauga',
        'L5H 1G0',
        'ON',
        'CA'
    ),
    new Address(
        'Ivan',
        'Mitrikeski',
        '',
        '100 City Centre Dr',
        '',
        'Mississauga',
        'L5B 2C9',
        'ON',
        'CA'
    ),
    new BoxCollection([
        new BoxMetric(20, 10, 5, 1)
    ])
);
```

#### Purolator

[](#purolator)

```
use Mitrik\Shipping\ServiceProviders\Address\Address;
use Mitrik\Shipping\ServiceProviders\Box\BoxCollection;
use Mitrik\Shipping\ServiceProviders\Box\BoxMetric;
use Mitrik\Shipping\ServiceProviders\ServicePurolator\ServicePurolator;
use Mitrik\Shipping\ServiceProviders\ServicePurolator\ServicePurolatorCredentials;

$credentials = new ServicePurolatorCredentials(env('PUROLATOR_KEY'), env('PUROLATOR_PASSWORD'), env('PUROLATOR_BILLING_ACCOUNT'), env('PUROLATOR_REGISTERED_ACCOUNT'), env('PUROLATOR_USER_TOKEN'), env('PUROLATOR_SANDBOX'));
$purolator = new ServicePurolator($credentials);

$rates = $purolator->rate(
    new Address(
        'Ivan',
        'Mitrikeski',
        '',
        '321 Lakeshore Rd W',
        '',
        'Mississauga',
        'L5H 1G0',
        'ON',
        'CA'
    ),
    new Address(
        'Ivan',
        'Mitrikeski',
        '',
        '100 City Centre Dr',
        '',
        'Mississauga',
        'L5B 2C9',
        'ON',
        'CA'
    ),
    new BoxCollection([
        new BoxMetric(20, 10, 5, 1)
    ])
);
```

#### UPS

[](#ups)

```
use Mitrik\Shipping\ServiceProviders\Address\Address;
use Mitrik\Shipping\ServiceProviders\Box\BoxCollection;
use Mitrik\Shipping\ServiceProviders\Box\BoxMetric;
use Mitrik\Shipping\ServiceProviders\ServiceUPS\ServiceUPS;
use Mitrik\Shipping\ServiceProviders\ServiceUPS\ServiceUPSCredentials;

$credentials = new ServiceUPSCredentials(env('UPS_ACCESS_KEY'), env('UPS_USER_ID'), env('UPS_PASSWORD'));
$serviceUPS = new ServiceUPS($credentials);

$rates = $serviceUPS->rate(
    new Address(
        'Ivan',
        'Mitrikeski',
        '',
        '321 Lakeshore Rd W',
        '',
        'Mississauga',
        'L5H 1G0',
        'ON',
        'CA'
    ),
    new Address(
        'Ivan',
        'Mitrikeski',
        '',
        '100 City Centre Dr',
        '',
        'Mississauga',
        'L5B 2C9',
        'ON',
        'CA'
    ),
    new BoxCollection([
        new BoxMetric(20, 10, 5, 1)
    ])
);
```

#### USPS

[](#usps)

```
use Mitrik\Shipping\ServiceProviders\Address\Address;
use Mitrik\Shipping\ServiceProviders\Box\BoxCollection;
use Mitrik\Shipping\ServiceProviders\Box\BoxMetric;
use Mitrik\Shipping\ServiceProviders\ServiceUSPS\ServiceUSPS;
use Mitrik\Shipping\ServiceProviders\ServiceUSPS\ServiceUSPSCredentials;

$credentials = new ServiceUSPSCredentials(env('USPS_USERNAME'), env('USPS_PASSWORD'));
$usps = new ServiceUSPS($credentials);

$rates = $usps->rate(
    new Address(
        'Ivan',
        'Mitrikeski',
        '',
        '1 Wall St',
        '',
        'New York',
        '10005',
        'NY',
        'US'
    ),
    new Address(
        'Ivan',
        'Mitrikeski',
        '',
        '1 Wall St',
        '',
        'New York',
        '10005',
        'NY',
        'US'
    ),
    new BoxCollection([
        new BoxMetric(20, 10, 5, 1)
    ])
);
```

#### FedEx

[](#fedex)

```
use Mitrik\Shipping\ServiceProviders\Address\Address;
use Mitrik\Shipping\ServiceProviders\Box\BoxCollection;
use Mitrik\Shipping\ServiceProviders\Box\BoxMetric;
use Mitrik\Shipping\ServiceProviders\ServiceFedEx\ServiceFedEx;
use Mitrik\Shipping\ServiceProviders\ServiceFedEx\ServiceFedExCredentials;

$credentials = new ServiceFedExCredentials(env('FEDEX_CLIENT_ID'), env('FEDEX_CLIENT_SECRET'), env('FEDEX_ACCOUNT_NUMBER'));
$fedEx = new ServiceFedEx($credentials);

$rates = $fedEx->rate(
    new Address(
        'Ivan',
        'Mitrikeski',
        '',
        '1 Wall St',
        '',
        'New York',
        '10005',
        'NY',
        'US'
    ),
    new Address(
        'Ivan',
        'Mitrikeski',
        '',
        '1 Wall St',
        '',
        'New York',
        '10005',
        'NY',
        'US'
    ),
    new BoxCollection([
        new BoxMetric(20, 10, 5, 1)
    ])
);
```

#### Flat

[](#flat)

```
use Mitrik\Shipping\ServiceProviders\Address\Address;
use Mitrik\Shipping\ServiceProviders\Box\BoxCollection;
use Mitrik\Shipping\ServiceProviders\Box\BoxMetric;
use Mitrik\Shipping\ServiceProviders\ServiceFlat\ServiceFlat;

$flat = new ServiceFlat();

$rates = $flat->rate(
    new Address(
        'Ivan',
        'Mitrikeski',
        '',
        '321 Lakeshore Rd W',
        '',
        'Mississauga',
        'L5H 1G0',
        'ON',
        'CA'
    ),
    new Address(
        'Ivan',
        'Mitrikeski',
        '',
        '100 City Centre Dr',
        '',
        'Mississauga',
        'L5B 2C9',
        'ON',
        'CA'
    ),
    new BoxCollection([
        new BoxMetric(35, 26, 5, 1)
    ])
);
```

#### Creating shipping boxes

[](#creating-shipping-boxes)

```
$modelShippingBox = new ShippingBox();
$modelShippingBox->length = 35;
$modelShippingBox->width = 26;
$modelShippingBox->height = 5;
$modelShippingBox->max_weight = 5;
$modelShippingBox->save();
```

#### Creating shipping option for Flat service

[](#creating-shipping-option-for-flat-service)

```
$modelShippingService = ShippingService::whereName('Flat')->first();

$modelShippingOption = new ShippingOption();
$modelShippingOption->shipping_service_id = $modelShippingService->id;
$modelShippingOption->code = 'FREE.PICKUP';
$modelShippingOption->name = 'Free Pickup';
$modelShippingOption->is_enabled = true;
$modelShippingOption->is_internal = false;
$modelShippingOption->save();
```

#### Creating Flat service prices

[](#creating-flat-service-prices)

```
$modelShippingBox = ShippingBox::whereUuid('SOME_BOX_UUID')->first();
$modelShippingOption = ShippingOption::whereUuid('SOME_OPTION_UUID')->first();

$modelShippingOptionPrice = new ShippingOptionPrice();
$modelShippingOptionPrice->shipping_box_id = $modelShippingBox->id;
$modelShippingOptionPrice->shipping_option_id = $modelShippingOption->id;
$modelShippingOptionPrice->shipping_service_id = $modelShippingOption->shipping_service_id;
$modelShippingOptionPrice->price = 10.99;
$modelShippingOptionPrice->save();
```

### Creating Shipments

[](#creating-shipments)

##### Canada Post

[](#canada-post-1)

```
use Mitrik\Shipping\ServiceProviders\Address\Address;
use Mitrik\Shipping\ServiceProviders\Box\BoxCollection;
use Mitrik\Shipping\ServiceProviders\Box\BoxMetric;
use Mitrik\Shipping\ServiceProviders\ServiceCanadaPost\ServiceCanadaPost;
use Mitrik\Shipping\ServiceProviders\ServiceCanadaPost\ServiceCanadaPostCredentials;

$credentials = new ServiceCanadaPostCredentials(env('CANADA_POST_CUSTOMER_NUMBER'), env('CANADA_POST_USERNAME'), env('CANADA_POST_PASSWORD'));
$canadaPost = new ServiceCanadaPost($credentials);

$result = $canadaPost->ship(
    new ShipFrom(
        name: 'Ivan Mitrikeski',
        attentionName: 'Ivan Mitrikeski',
        address: new Address(
            'Ivan',
            'Mitrikeski',
            '',
            '321 Lakeshore Rd W',
            '',
            'Mississauga',
            'L5H 1G0',
            'ON',
            'CA'
        ),
        phone: new Phone('+1', '555', '1231234'),
        company: 'Test'
    ),
    new ShipTo(
        'John Smith',
        'John Smith',
        new Address(
            'John',
            'Smith',
            '',
            '100 City Centre Dr',
            '',
            'Mississauga',
            'L5B 2C9',
            'ON',
            'CA'
        ),
        new Phone('+1', '555', '1231234')
    ),
    new BoxCollection([
        new BoxMetric(20, 10, 5, 1)
    ]),
    new ServiceProviderService('DOM.RP', ''),
    null,
    [
        'delivery-spec' => [
            'settlement-info' => [
                'contract-id' => '0042708517'
            ]
        ]
    ]
);
```

#### Purolator

[](#purolator-1)

```
use Mitrik\Shipping\ServiceProviders\Address\Address;
use Mitrik\Shipping\ServiceProviders\Box\BoxCollection;
use Mitrik\Shipping\ServiceProviders\Box\BoxMetric;
use Mitrik\Shipping\ServiceProviders\ServicePurolator\ServicePurolator;
use Mitrik\Shipping\ServiceProviders\ServicePurolator\ServicePurolatorCredentials;

$credentials = new ServicePurolatorCredentials(env('PUROLATOR_KEY'), env('PUROLATOR_PASSWORD'), env('PUROLATOR_BILLING_ACCOUNT'), env('PUROLATOR_REGISTERED_ACCOUNT'), env('PUROLATOR_USER_TOKEN'), env('PUROLATOR_SANDBOX'));
$purolator = new ServicePurolator($credentials);

$result = $purolator->ship(
    new ShipFrom(
        'Ivan Mitrikeski',
        'Ivan Mitrikeski',
        new Address(
            'Ivan',
            'Mitrikeski',
            '',
            '321 Lakeshore Rd W',
            '',
            'Mississauga',
            'L5H 1G0',
            'ON',
            'CA'
        ),
        new Phone('+1', '555', '1231234'),
        ''
    ),
    new ShipTo(
        'John Smith',
        'John Smith',
        new Address(
            'John',
            'Smith',
            '',
            '100 City Centre Dr',
            '',
            'Mississauga',
            'L5B 2C9',
            'ON',
            'CA'
        ),
        new Phone('+1', '555', '1231234')
    ),
    new BoxCollection([
        new BoxMetric(20, 10, 5, 1)
    ]),
    new ServiceProviderService('PurolatorExpress', '')
);
```

#### UPS

[](#ups-1)

```
use Mitrik\Shipping\ServiceProviders\Address\Address;
use Mitrik\Shipping\ServiceProviders\Box\BoxCollection;
use Mitrik\Shipping\ServiceProviders\Box\BoxMetric;
use Mitrik\Shipping\ServiceProviders\ServiceUPS\ServiceUPS;
use Mitrik\Shipping\ServiceProviders\ServiceUPS\ServiceUPSCredentials;

$credentials = new ServiceUPSCredentials(env('UPS_ACCESS_KEY'), env('UPS_USER_ID'), env('UPS_PASSWORD'));
$serviceUPS = new ServiceUPS($credentials);

$result = $serviceUPS->ship(
    new ShipFrom(
        'Ivan Mitrikeski',
        'Ivan Mitrikeski',
        new Address(
            'Ivan',
            'Mitrikeski',
            '',
            '1 Wall St',
            '',
            'New York',
            '10005',
            'NY',
            'US'
        ),
        new Phone('+1', '555', '1231234'),
        ''
    ),
    new ShipTo(
        'John Smith',
        'John Smith',
        new Address(
            'John',
            'Smith',
            '',
            '1 Wall St',
            '',
            'New York',
            '10005',
            'NY',
            'US'
        ),
        new Phone('+1', '555', '1231234')
    ),
    new BoxCollection([
        new BoxImperial(20, 10, 5, 1)
    ]),
    new ServiceProviderService('03', '')
);
```

#### FedEx

[](#fedex-1)

```
use Mitrik\Shipping\ServiceProviders\Address\Address;
use Mitrik\Shipping\ServiceProviders\Box\BoxCollection;
use Mitrik\Shipping\ServiceProviders\Box\BoxMetric;
use Mitrik\Shipping\ServiceProviders\ServiceFedEx\ServiceFedEx;
use Mitrik\Shipping\ServiceProviders\ServiceFedEx\ServiceFedExCredentials;

$credentials = new ServiceFedExCredentials(env('FEDEX_CLIENT_ID'), env('FEDEX_CLIENT_SECRET'), env('FEDEX_ACCOUNT_NUMBER'));
$fedEx = new ServiceFedEx($credentials);

$result = $fedEx->ship(
    new ShipFrom(
        'Ivan Mitrikeski',
        'Ivan Mitrikeski',
        new Address(
            'Ivan',
            'Mitrikeski',
            '',
            '1 Wall St',
            '',
            'New York',
            '10005',
            'NY',
            'US'
        ),
        new Phone('+1', '555', '1231234'),
        ''
    ),
    new ShipTo(
        'John Smith',
        'John Smith',
        new Address(
            'John',
            'Smith',
            '',
            '1 Wall St',
            '',
            'New York',
            '10005',
            'NY',
            'US'
        ),
        new Phone('+1', '555', '1231234')
    ),
    new BoxCollection([
        new BoxImperial(20, 10, 5, 1)
    ]),
    new ServiceProviderService('FEDEX_2_DAY', '')
);
```

Testing
=======

[](#testing)

Update phpunit.xml env variables before running tests.

```

```

```
composer test
```

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b175b842f738680ac1c57cfd3b848e1305b50b33ce5cff33989deed4cf95bfee?d=identicon)[nextgenbite](/maintainers/nextgenbite)

---

Top Contributors

[![nextgenbite](https://avatars.githubusercontent.com/u/98073256?v=4)](https://github.com/nextgenbite "nextgenbite (11 commits)")

### Embed Badge

![Health badge](/badges/nextgenbite-laravel-shipping/health.svg)

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

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M479](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M271](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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