easypost/easypost-php

EasyPost Shipping API Client Library for PHP

Installs: 8 356

Dependents: 0

Stars: 50

Watchers: 31

Forks: 14

Open Issues: 5

Language: PHP

2.1.1 2015-07-01 17:22 UTC

README

EasyPost is a simple shipping API. You can sign up for an account at https://easypost.com

Installation

There are two ways to install:

Require Library

require_once("/path/to/lib/easypost.php");

or via Composer:

Create or add the following to composer.json in your project root:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/EasyPost/easypost-php"
        }
    ],
    "require": {
        "easypost/easypost-php": "dev-master"
    }
}

Install composer dependancies:

php composer.phar install

Require dependancies:

require_once("/path/to/vendor/autoload.php");

Example

require_once("path/to/vendor/autoload.php");
\EasyPost\EasyPost::setApiKey('cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi');

$to_address = \EasyPost\Address::create(
    array(
        "name"    => "Dirk Diggler",
        "street1" => "388 Townsend St",
        "street2" => "Apt 20",
        "city"    => "San Francisco",
        "state"   => "CA",
        "zip"     => "94107",
        "phone"   => "415-456-7890"
    )
);
$from_address = \EasyPost\Address::create(
    array(
        "company" => "Simpler Postage Inc",
        "street1" => "764 Warehouse Ave",
        "city"    => "Kansas City",
        "state"   => "KS",
        "zip"     => "66101",
        "phone"   => "620-123-4567"
    )
);
$parcel = \EasyPost\Parcel::create(
    array(
        "predefined_package" => "LargeFlatRateBox",
        "weight" => 76.9
    )
);
$shipment = \EasyPost\Shipment::create(
    array(
        "to_address"   => $to_address,
        "from_address" => $from_address,
        "parcel"       => $parcel
    )
);

$shipment->buy($shipment->lowest_rate());

echo $shipment->postage_label->label_url;

Documentation

Up-to-date documentation at: https://www.easypost.com/docs

Tests

Install dev dependancies:

php composer.phar install --dev

Run tests:

path/to/bin/phpunit