verbb/shippy

A framework agnostic, multi-carrier shipping library for PHP.

Fund package maintenance!
verbb

1.1.0 2024-12-05 23:16 UTC

This package is auto-updated.

Last update: 2024-12-05 23:16:42 UTC


README

Cloner icon

Shippy

Shippy is a framework agnostic, multi-carrier shipping library for PHP. Its aim is to provide a consistent API around the many different shipping carriers for shipment rates, tracking, labels and more. It's free to use and doesn't require a subscription to SaaS providers.

Install

You can install the package via composer:

composer require verbb/shippy

Usage

As a quick example, use the following to fetch rates from UPS and FedEx.

use verbb\shippy\carriers\FedEx;
use verbb\shippy\carriers\UPS;
use verbb\shippy\models\Address;
use verbb\shippy\models\Package;
use verbb\shippy\models\Shipment;

// Create a shipment to set the from/to address details
$shipment = new Shipment([
    // You can supply config arrays for quick setting.
    'from' => new Address([
        'street1' => 'One Infinite Loop',
        'city' => 'Cupertino',
        'stateProvince' => 'CA',
        'postalCode' => '95014',
        'countryCode' => 'US',
    ]),
]);

// You can use traditional setters if you prefer
$toAddress = new Address();
$toAddress->setStreet1('1600 Amphitheatre Parkway');
$toAddress->setCity('Mountain View');
$toAddress->setStateProvince('CA');
$toAddress->setPostalCode('94043');
$toAddress->setCountryCode('US');
$shipment->setTo($toAddress);

// Create a package (or more) to represent what we're sending
// You can use fluent syntax if you prefer
$package = new Package()
    ->setLength(300)
    ->setWidth(100)
    ->setHeight(80)
    ->setWeight(2000)
    ->setDimensionUnit('mm')
    ->setWeightUnit('g');

$shipment->addPackage($package);

// Finally, add the carrier(s) we wish to fetch rates for. With multiple carriers, rates will be
// returned across all, sorted by cheapest to most expensive
$shipment->addCarrier(new UPS([
    'isProduction' => false,
    'clientId' => '•••••••••••••••••••••••••••••••••••',
    'clientSecret' => '•••••••••••••••••••••••••••••••••••',
    'accountNumber' => '••••••',
]));

$shipment->addCarrier(new FedEx([
    'isProduction' => false,
    'clientId' => '•••••••••••••••••••••••••••••••••••',
    'clientSecret' => '•••••••••••••••••••••••••••••••••••',
    'accountNumber' => '••••••',
]));

// Fetch the rates and print the response
$rateResponse = $shipment->getRates();

echo '<pre>';
print_r($rateResponse);
echo '</pre>';

Be sure to check out the full documentation.

Supported Carriers

Shippy supports the following carriers and features.

New Carriers

We'd love to grow the package to support as many carriers as we can. You can either:

  • Request a new carrier support, and we'll build it! We might need your API credentials to verify everything.
  • Use the documentation to create your own (and we can list it here as a community carrier).
  • Get in touch to arrange priority, sponsored development.

Documentation

Visit the Shippy documentation.

Support

For all feature requests, bugs and questions, create a Github issue here.

Shippy is actively maintained via Postie, a commercial Craft CMS plugin.

Sponsor

Shippy is MIT licensed, meaning it will always be free and open source – we love free stuff! If you'd like to show your support for the package, Sponsor development. We'd highly encourage this if you use this package for commercial purposes.