Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Shipping cost calculator for Kohana
PHP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
classes
config
views/sipy/usps
.gitignore
README.md
init.php

README.md

Sipy

Shipping cost calculator module for Kohana

USPS account

In theroy, you need to have to register an account for using API of USPS. Registering is super fast, and your account is in testing mode before s.o at USPS turns on production mode for you. The bad thing is testing mode is not copatible completely with all USPS API (Rate API for example). So I use my USPS account here in config file to let get the ball rolling instantly without going through painful approval process of USPS. So, be aware of limitation on API calling. Just use my account for evaluate the module, if you need to use this module on a live production app, get your own API key.

PROVIDER

Currently, this module supports USPS. I'm working on to support FedEx, UPS as well. Your pull request are welcome.

DEMO

I set up a simple Kohana app on PagodaBox use this module. Check it out. Sipy App use Sipy Module.

HOW TO USE

  • Just want to see how it work

    ./minion sipy:calculate
    
  • Implement with your app: copy config/sipy to your application/config and change the necessary value.

    <?php
    $sipy = Sipy::instance('usps');    
    $sipy->ship(array(
        'id' => '1st-domestic-test',
        'service' => 'PRIORITY',
        // Weight
        'weight' => 1.00,
        'weight_units' => 'lb',
        // Size
        'size_width' => 1.75,
        'size_length' => 8.8675,            
        'size_height' => 5.4375,
        'size_units' => 'in',
            ), array(
        'zip' => 80011,
        'state' => "CO",
        'country' => "US",
            ), array(
        'zip' => 95136,
        'state' => "CA",
        'country' => "US",
    ));
    
    echo Debug::dump($sipy->how_much('ALL'));
    
    //For internationmal shipping, 
    $sipy = Sipy::instance('usps');
    $sipy->ship(array(
        'service' => 9, //Mean priority internal medium flatrate box email
        'id' => '2nd-intl-test',
        // Weight
        'weight' => 1.00,
        'weight_units' => 'lb',
        // Size
        'size_width' => 1.75,
        'size_length' => 8.8675,            
        'size_height' => 5.4375,
        'size_units' => 'in',
        'ValueOfContents' => 10
            ), array(
        'zip' => 10022,
        'state' => "CA",
        'country' => "US",
            ), array(
        'country' => 'Vietnam'
    ));
    echo Debug::dump($sipy->how_much('ALL'));
    

API

JSON

curl -X POST -d '[{"service":9,"id":"2nd-intl-test","weight":1,"weight_units":"lb","size_width":1.75,"size_length":8.8675,"size_height":5.4375,"size_units":"in","ValueOfContents":10},{"zip":10022,"state":"CA","country":"US"},{"country":"Vietnam"}]' http://sipy.pagodabox.com/sipy/rate

curl -X POST -d '[{"id":"1st-domestic-test","service":"PRIORITY","weight":1,"weight_units":"lb","size_width":1.75,"size_length":8.8675,"size_height":5.4375,"size_units":"in"},{"zip":80011,"state":"CO","country":"US"},{"zip":95136,"state":"CA","country":"US"}]' http://sipy.pagodabox.com/sipy/rate

JSONP

Be default, jQuery use parameter "callback", so you can set this up with jQuery easily. Or try to test it:

curl http://sipy.pagodabox.com/sipy/rate.jsonp?callback=cb&package=[{"id":"1st-domestic-test","service":"PRIORITY","weight":1,"weight_units":"lb","size_width":1.75,"size_length":8.8675,"size_height":5.4375,"size_units":"in"},{"zip":80011,"state":"CO","country":"US"},{"zip":95136,"state":"CA","country":"US"}]
Something went wrong with that request. Please try again.