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

ActiveLibrary[API Development](/categories/api)

pdt256/shipping
===============

Shipping Rate API

1.0.1(6y ago)1814.6k↓31.3%12[5 issues](https://github.com/pdt256/shipping/issues)[2 PRs](https://github.com/pdt256/shipping/pulls)MITPHPPHP &gt;=7.1CI failing

Since Nov 30Pushed 4y ago4 watchersCompare

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

READMEChangelog (3)Dependencies (2)Versions (4)Used By (0)

PHP Shipping API
----------------

[](#php-shipping-api)

[![Test Coverage](https://camo.githubusercontent.com/d1383d1e79115137d2ba8e32d39825cd068ac471801bc06fa62bd6259ffac9f3/687474703a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d38362532352d677265656e2e737667)](https://camo.githubusercontent.com/d1383d1e79115137d2ba8e32d39825cd068ac471801bc06fa62bd6259ffac9f3/687474703a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d38362532352d677265656e2e737667)[![Build Status](https://camo.githubusercontent.com/f2189604e78015a2688d0cb95abb4e72274ef16df0d3d97ecc7dbba116932310/68747470733a2f2f7472617669732d63692e6f72672f7064743235362f7368697070696e672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/pdt256/shipping)[![Downloads](https://camo.githubusercontent.com/1ae29f0ded91ed033ab5c53e740bc8e36f7ac7de7aada58bbf4b2442c217d786/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7064743235362f7368697070696e672e737667)](https://packagist.org/packages/pdt256/shipping)[![License](https://camo.githubusercontent.com/0f4be9b066d1c2e1c1257e600d6d1a4e77d305bf1627791ab31fe14d3e6548e7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7064743235362f7368697070696e672e737667)](https://github.com/pdt256/shipping/blob/master/LICENSE.txt)

A shipping rate wrapper for USPS, UPS, and Fedex.

Introduction
------------

[](#introduction)

This is a PHP shipping package that wraps API calls to UPS, FedEx, and USPS for shipping rates. Multiple packages can be added to get additional rates.

All code (including tests) conform to the PSR-2 coding standards. The namespace and autoloader are using the PSR-4 standard.

All pull requests are processed by Travis CI to conform to PSR-2 and to verify all unit tests pass.

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

[](#installation)

Add the following lines to your `composer.json` file.

```
{
    "require": {
        "pdt256/shipping": "1.0.*"
    }
}
```

Example
-------

[](#example)

Create a shipment object:

```
$shipment = new Shipment;
$shipment
    ->setFromIsResidential(false)
    ->setFromStateProvinceCode('IN')
    ->setFromPostalCode('46205')
    ->setFromCountryCode('US')
    ->setToIsResidential(true)
    ->setToPostalCode('20101')
    ->setToCountryCode('US');

$package = new Package;
$package
    ->setLength(12)
    ->setWidth(4)
    ->setHeight(3)
    ->setWeight(3);

$shipment->addPackage($package);
```

UPS (Stub) Example
------------------

[](#ups-stub-example)

Below is an example request to get shipping rates from the UPS API.

Notice: The below line uses a stub class to fake a response from the UPS API. You can immediately use this method in your code until you get an account with UPS.

```
'requestAdapter' => new RateRequest\StubUPS(),
```

```
use pdt256\Shipping\UPS;
use pdt256\Shipping\RateRequest;

$ups = new UPS\Rate([
    'prod'           => false,
    'accessKey'      => 'XXXX',
    'userId'         => 'XXXX',
    'password'       => 'XXXX',
    'shipperNumber'  => 'XXXX',
    'shipment'       => $shipment,
    'approvedCodes'  => [
        '03', // 1-5 business days
        '02', // 2 business days
        '01', // next business day 10:30am
        '13', // next business day by 3pm
        '14', // next business day by 8am
    ],
    'requestAdapter' => new RateRequest\StubUPS(),
]);

$rates = $ups->getRates();
```

Output array sorted by cost: (in cents)

```
array (
  0 =>
  pdt256\Shipping\Quote::__set_state(array(
     'code' => '03',
     'name' => 'UPS Ground',
     'cost' => 1910,
     'transitTime' => NULL,
     'deliveryEstimate' => NULL,
     'carrier' => 'ups',
  )),
  1 =>
  pdt256\Shipping\Quote::__set_state(array(
     'code' => '02',
     'name' => 'UPS 2nd Day Air',
     'cost' => 4923,
     'transitTime' => NULL,
     'deliveryEstimate' => NULL,
     'carrier' => 'ups',
  )),
  2 =>
  pdt256\Shipping\Quote::__set_state(array(
     'code' => '13',
     'name' => 'UPS Next Day Air Saver',
     'cost' => 8954,
     'transitTime' => NULL,
     'deliveryEstimate' => NULL,
     'carrier' => 'ups',
  )),
  3 =>
  pdt256\Shipping\Quote::__set_state(array(
     'code' => '01',
     'name' => 'UPS Next Day Air',
     'cost' => 9328,
     'transitTime' => NULL,
     'deliveryEstimate' => NULL,
     'carrier' => 'ups',
  )),
)
```

USPS (Stub) Example
-------------------

[](#usps-stub-example)

```
use pdt256\Shipping\USPS;
use pdt256\Shipping\RateRequest;

$usps = new USPS\Rate([
	'prod'     => false,
	'username' => 'XXXX',
	'password' => 'XXXX',
	'shipment' => $shipment,
	'approvedCodes'  => [
		'1', // 1-3 business days
		'4', // 2-8 business days
	],
	'requestAdapter' => new RateRequest\StubUSPS(),
]);

$rates = $usps->getRates();
```

Output array sorted by cost: (in cents)

```
array (
  0 =>
  pdt256\Shipping\Quote::__set_state(array(
     'code' => '4',
     'name' => 'Parcel Post',
     'cost' => 1001,
     'transitTime' => NULL,
     'deliveryEstimate' => NULL,
     'carrier' => 'usps',
  )),
  1 =>
  pdt256\Shipping\Quote::__set_state(array(
     'code' => '1',
     'name' => 'Priority Mail',
     'cost' => 1220,
     'transitTime' => NULL,
     'deliveryEstimate' => NULL,
     'carrier' => 'usps',
  )),
)
```

Fedex (Stub) Example
--------------------

[](#fedex-stub-example)

```
use pdt256\Shipping\Fedex;
use pdt256\Shipping\RateRequest;

$fedex = new Fedex\Rate([
	'prod'           => FALSE,
	'key'            => 'XXXX',
	'password'       => 'XXXX',
	'accountNumber' => 'XXXX',
	'meterNumber'   => 'XXXX',
	'dropOffType'  => 'BUSINESS_SERVICE_CENTER',
	'shipment'       => $shipment,
	'approvedCodes'  => [
		'FEDEX_EXPRESS_SAVER',  // 1-3 business days
		'FEDEX_GROUND',         // 1-5 business days
		'GROUND_HOME_DELIVERY', // 1-5 business days
		'FEDEX_2_DAY',          // 2 business days
		'STANDARD_OVERNIGHT',   // overnight
	],
	'requestAdapter' => new RateRequest\StubFedex(),
]);

$rates = $fedex->getRates();
```

Output array sorted by cost: (in cents)

```
array (
  0 =>
  pdt256\Shipping\Quote::__set_state(array(
     'code' => 'GROUND_HOME_DELIVERY',
     'name' => 'Ground Home Delivery',
     'cost' => 1655,
     'transitTime' => 'THREE_DAYS',
     'deliveryEstimate' => NULL,
     'carrier' => 'fedex',
  )),
  1 =>
  pdt256\Shipping\Quote::__set_state(array(
     'code' => 'FEDEX_EXPRESS_SAVER',
     'name' => 'Fedex Express Saver',
     'cost' => 2989,
     'transitTime' => NULL,
     'deliveryEstimate' =>
    DateTime::__set_state(array(
       'date' => '2014-09-30 20:00:00',
       'timezone_type' => 3,
       'timezone' => 'UTC',
    )),
     'carrier' => 'fedex',
  )),
  2 =>
  pdt256\Shipping\Quote::__set_state(array(
     'code' => 'FEDEX_2_DAY',
     'name' => 'Fedex 2 Day',
     'cost' => 4072,
     'transitTime' => NULL,
     'deliveryEstimate' =>
    DateTime::__set_state(array(
       'date' => '2014-09-29 20:00:00',
       'timezone_type' => 3,
       'timezone' => 'UTC',
    )),
     'carrier' => 'fedex',
  )),
  3 =>
  pdt256\Shipping\Quote::__set_state(array(
     'code' => 'STANDARD_OVERNIGHT',
     'name' => 'Standard Overnight',
     'cost' => 7834,
     'transitTime' => NULL,
     'deliveryEstimate' =>
    DateTime::__set_state(array(
       'date' => '2014-09-26 20:00:00',
       'timezone_type' => 3,
       'timezone' => 'UTC',
    )),
     'carrier' => 'fedex',
  )),
)
```

Unit Tests:
-----------

[](#unit-tests)

```
    vendor/bin/phpunit
```

### With Code Coverage:

[](#with-code-coverage)

```
    vendor/bin/phpunit --coverage-text --coverage-html coverage_report
```

### With Live API Tests:

[](#with-live-api-tests)

```
    ./live_phpunit.sh
```

Run Coding Standards Test:
--------------------------

[](#run-coding-standards-test)

```
    vendor/bin/phpcs --standard=PSR2 src/ tests/
```

### License

[](#license)

The MIT License (MIT)

Copyright (c) 2014 Jamie Isaacs

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance14

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~919 days

Total

3

Last Release

2350d ago

Major Versions

v0.2-beta → 1.0.02019-12-11

### Community

Maintainers

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

---

Top Contributors

[![pdt256](https://avatars.githubusercontent.com/u/370440?v=4)](https://github.com/pdt256 "pdt256 (21 commits)")[![perk11](https://avatars.githubusercontent.com/u/1924829?v=4)](https://github.com/perk11 "perk11 (16 commits)")[![troydavisson](https://avatars.githubusercontent.com/u/318954?v=4)](https://github.com/troydavisson "troydavisson (12 commits)")[![harikt](https://avatars.githubusercontent.com/u/120454?v=4)](https://github.com/harikt "harikt (5 commits)")[![dranzd](https://avatars.githubusercontent.com/u/167126?v=4)](https://github.com/dranzd "dranzd (1 commits)")

---

Tags

uspsupsFedExship

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[shippo/shippo-php

A PHP library for connecting with multiple carriers (FedEx, UPS, USPS) using Shippo.

1711.8M2](/packages/shippo-shippo-php)[gabrielbull/ups-api

PHP UPS API

4642.4M10](/packages/gabrielbull-ups-api)[gavroche/ups-api

PHP UPS API

45613.2k](/packages/gavroche-ups-api)[verbb/postie

Get shipping rates, tracking status and print labels with Australia Post, UPS, USPS, FedEx, DHL Express, and more.

1218.9k](/packages/verbb-postie)[octw/aramex

A Library to integrate with Aramex APIs

2925.2k](/packages/octw-aramex)[ivanmitrikeski/laravel-shipping

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

206.8k2](/packages/ivanmitrikeski-laravel-shipping)

PHPackages © 2026

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