PHP code example of popphp / pop-shipping

1. Go to this page and download the library: Download popphp/pop-shipping library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

popphp / pop-shipping example snippets


use Pop\Shipping\Shipping;
use Pop\Shipping\Adapter\Fedex;

$shipping = new Shipping(
    new Fedex('USER_KEY', 'PASSWORD', 'ACCOUNT_NUM', 'METER_NUM', 'WSDL_FILE')
);

use Pop\Shipping\Shipping;
use Pop\Shipping\Adapter\Ups;

$shipping = new Shipping(
    new Ups('ACCESS_KEY', 'USER_ID', 'PASSWORD')
);

use Pop\Shipping\Shipping;
use Pop\Shipping\Adapter\Usps;

$shipping = new Shipping(
    new Usps('USERNAME', 'PASSWORD')
);

use Pop\Shipping\Shipping;
use Pop\Shipping\Adapter\Ups;

$shipping = new Shipping(
    new Ups('ACCESS_KEY', 'USER_ID', 'PASSWORD')
);

// Set the 'ship to' address
$shipping->shipTo([
    'address' => '123 Main St.',
    'city'    => 'Some Town',
    'state'   => 'LA',
    'zip'     => '12345',
    'country' => 'US'
]);

// Set the 'ship from' address
$shipping->shipFrom([
    'company'  => 'Widgets Inc',
    'address1' => '456 Some St.',
    'address2' => 'Suite 100',
    'city'     => 'Some Town',
    'zip'      => '12345',
    'country'  => 'US'
]);

// Set the package dimensions
$shipping->setDimensions([
    'length' => 12,
    'height' => 10,
    'width'  => 8
], 'IN');

// Set the package weight
$shipping->setWeight(5.4, 'LBS');

// Go get the rates
$shipping->send();

if ($shipping->isSuccess()) {
    foreach ($shipping->getRates() as $service => $rate) {
        echo $service . ': ' . $rate . PHP_EOL;
    }
}