Skip to content

nickcheek/USPSLookup

Repository files navigation

USPS API Wrapper

Latest Version on Packagist Total Downloads Scrutinizer Code Quality Build Status

USPS Verify Address

About

This was quickly thrown together for a project. Feel free to add to it as you see fit. I recently refactored each Service so I can add on as time goes.

Installation

You can install the package via composer:

composer require nickcheek/uspslookup

Then add the reference to the top of your controller

use \Nickcheek\USPSLookup\USPSLookup;

Usage

Set the USPS Username while creating the object:

$lookup = new USPSLookup('XXXXXXXXX');
$response = $lookup->Address()->verify('123 Anystreet','','Little Rock','AR','72204');

var_dump($response);

The above returns the following (I replaced the values with ***):

"Address2": "3017 P****E"
    +"City": "*****"
    +"State": "AR"
    +"Zip5": "7***9"
    +"Zip4": "2140"
    +"DeliveryPoint": "17"
    +"CarrierRoute": "****"
    +"DPVConfirmation": "Y"
    +"DPVCMRA": "N"
    +"DPVFootnotes": "AABB"
    +"Business": "N"
    +"CentralDeliveryPoint": "N"
    +"Vacant": "N"

Available Methods

Verify Address exists

$lookup = new \Nickcheek\USPSLookup\USPSLookup('XXXXXXXXX');
$find = $lookup->verify($address,$address2,$city,$state,$zip);

Tracking a Package

$lookup = new \Nickcheek\USPSLookup\USPSLookup('XXXXXXXXX');
$find = $lookup->Tracking()->track('9405511206019825745000');

Tracking Multiple Packages

$lookup = new \Nickcheek\USPSLookup\USPSLookup('XXXXXXXXX');
$track = array("9405511206019825745000","9405511206019825304382");
$find = $lookup->Tracking()->trackMultiple($track);

Find City/State that zip code belongs to

$lookup = new \Nickcheek\USPSLookup\USPSLookup('XXXXXXXXX');
$find = $lookup->Address()->cityState('72019');

Find City/State of multiple zip codes

$zips = array('72204','72203');
$lookup = new \Nickcheek\USPSLookup\USPSLookup('XXXXXXXXX');
$find = $lookup->Address()->cityState($zips);

Find Zip Code of address

$lookup = new \Nickcheek\USPSLookup\USPSLookup('XXXXXXXXX');
$find = $lookup->Address()->zipCode('1234 Anystreet','','Little Rock','AR');
	   

Get Rate of Package ($to,$from,$pounds,$ounces,$service) Available services: First Class,First Class Commercial,First Class HFP Commercial,Priority,Priority Commercial,Priority Cpp,Priority HFP Commercial,Retail Ground,etc...

$lookup = new \Nickcheek\USPSLookup\USPSLookup('XXXXXXXXX');
$find = $lookup->Price()->getRate('72204','37501','1','3','Priority');

Changelog

Please see CHANGELOG for more information what has changed recently.

Security

If you discover any security related issues, please email nick@nicholascheek.com.

Credits