GithubHelp home page GithubHelp logo

ziad181 / laravel-usps Goto Github PK

View Code? Open in Web Editor NEW

This project forked from johnpaulmedina/laravel-usps

0.0 0.0 0.0 73 KB

Laravel USPS Package to integrate USPS Address and Shipping API

PHP 100.00%

laravel-usps's Introduction

Laravel-USPS

Laravel-USPS is a composer package that allows you to integrate the USPS Address / Shipping API / Rates Calculator. This package is ported from @author Vincent Gabriel https://github.com/VinceG/USPS-php-api

  • Requires a valid USPS API Username
  • Tested on Laravel 8

Installation

Begin by installing this package through Composer. Run this command from the Terminal:

composer require johnpaulmedina/laravel-usps

Laravel integration

For Laravel 5.5 and later, this package will be auto discovered and registered.

To wire this up in your Laravel 5.4 project you need to add the service provider. Open config/app.php, and add a new item to the providers array.

Johnpaulmedina\Usps\UspsServiceProvider::class,

Then you must also specify the alias in config/app.php. Add a new item to the Aliases array.

'Usps' => Johnpaulmedina\Usps\Facades\Usps::class,

This will allow integration by adding the Facade Use Usps;

Laravel Config

Add your USPS username config in config/services.php.

'usps' => [
		'username' => "XXXXXXXXXXXX",
		'testmode' => false,
	],

Example Controller Usage

The only method completed for Laravel is the Usps::validate, Usps::rate which is defined in vendor/johnpaulmedina/laravel-usps/src/Usps/Usps.php. As this package was developed for internal use I did not bring over all the features but you are more than welcome to contribute the methods you need and I will merge them. I suggest looking at the original PHP-Wrapper by @VinceG USPS PHP-Api as I ported those clases and autoloaded them to use in the Usps.php file.

<?php

namespace App\Http\Controllers;

use App\Http\Requests;
use Illuminate\Support\Facades\Request;
use Johnpaulmedina\Usps;

class USPSController extends Controller
{
    public function index() {
        return response()->json(
            Usps::validate( 
                Request::input('Address'), 
                Request::input('Zip'), 
                Request::input('Apartment'), 
                Request::input('City'), 
                Request::input('State')
            )
        );
    }

    public function trackConfirm() {
        return response()->json(
            Usps::trackConfirm( 
                Request::input('id')
            )
        );
    }

    public function trackConfirmRevision1() {
        return response()->json(
            Usps::trackConfirm( 
                Request::input('id'),
                'Acme, Inc'
            )
        );
    }
    
    public function rate(Request $request) {
    
        $usps_rate = Usps::rate(
            [
                'Service' => $request->input('Service', 'PRIORITY COMMERCIAL'),
                'FirstClassMailType' => $request->input('FirstClassMailType', ''),
                'ZipOrigination' => $request->input('ZipOrigination', '91601'),
                'ZipDestination' => $request->input('ZipDestination', $zipcode),
                'Pounds' => $request->input('Pounds', $weight),
                'Ounces' => $request->input('Ounces', 0),
                'Container' => $request->input('Container', 'VARIABLE'),
                'Machinable' => $request->input('Machinable', 'True'),
            ]
        );


        $usps_return_rate = Arr::get($usps_rate, 'rate.RateV4Response.Package.Postage.Rate');
        $usps_return_weight = Arr::get($usps_rate, 'rate.RateV4Response.Package.Pounds');


        return response()->json([
            'rate' => $usps_return_rate,
            'weight'=> $usps_return_weight,
            'usps' => $usps_rate
        ]);
	
    }
    
}

Contributors

@pdbreen @bredmor @scs-ben @daveore090

@VinceG Original README.MD

USPS PHP API

This wrapper allows you to perform some basic calls to the USPS api. Some of the features currently supported are:

  • Rate Calculator (Both domestic and international)
  • Zip code lookup by address
  • City/State lookup by zip code
  • Verify address
  • Create Priority Shipping Labels
  • Create Open & Distribute Shipping Labels
  • Create International Shipping Labels (Express, Priority, First Class)
  • Service Delivery Calculator
  • Confirm Tracking

Requirements

  • PHP >= 8.0
  • USPS API Username
    • Laravel 8

Authors

laravel-usps's People

Contributors

johnpaulmedina avatar daveore090 avatar pdbreen avatar ziad181 avatar bredmor avatar neodisco avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.