public function testInvalidCredentials()
 {
     //    $this->expectException();
     Shippo::setApiKey('invalid');
     try {
         $address = Shippo_Address::create();
     } catch (Shippo_AuthenticationError $e) {
         $this->assertEqual(401, $e->getHttpStatus());
     }
 }
<?php

/* This example demonstrates how to purchase a label for an international shipment.
Creating domestic shipment would follow a similiar proccess but would not require
the creation of CustomsItems and CustomsDeclaration objects. */
require_once 'lib/Shippo.php';
//replace <USERNAME> and <PASSWORD> with your credentials
Shippo::setCredentials("<USERNAME>", "<PASSWORD>");
//example fromAddress array object
$fromAddress = array('object_purpose' => 'PURCHASE', 'name' => 'Laura Behrens Wu', 'company' => 'Shippo', 'street1' => '215 Clayton St.', 'city' => 'San Francisco', 'state' => 'CA', 'zip' => '94117', 'country' => 'US', 'phone' => '+1 555 341 9393', 'email' => '*****@*****.**');
//example fromAddress array object
$toAddress = array('object_purpose' => 'PURCHASE', 'name' => 'Mr Hippo"', 'company' => 'London Zoo"', 'street1' => 'Regents Park', 'street2' => 'Outer Cir', 'city' => 'LONDON', 'state' => '', 'zip' => 'NW1 4RY', 'country' => 'GB', 'phone' => '+1 555 341 9393', 'email' => '*****@*****.**');
//example fromAddress array object
$parcel = array('length' => '5', 'width' => '5', 'height' => '5', 'distance_unit' => 'in', 'weight' => '2', 'mass_unit' => 'lb');
//example CustomsItems object. This is only required for int'l shipment only.
$customs_item = array('description' => 'T-Shirt', 'quantity' => '2', 'net_weight' => '1', 'mass_unit' => 'lb', 'value_amount' => '20', 'value_currency' => 'USD', 'origin_country' => 'US');
#Creating the CustomsDeclaration
#(CustomsDeclarations are only required for international shipments)
$customs_declaration = Shippo_CustomsDeclaration::create(array('contents_type' => 'MERCHANDISE', 'contents_explanation' => 'T-Shirt purchase', 'non_delivery_option' => 'RETURN', 'certify' => 'true', 'certify_signer' => 'Laura Behrens Wu', 'items' => array($customs_item)));
//Creating the shipment object. In this example, the objects are directly passed to the
//Shipment.create method, Alternatively, the Address and Parcel objects could be created
//using Address.create(..) and Parcel.create(..) functions respectively.
$shipment = Shippo_Shipment::create(array('object_purpose' => 'PURCHASE', 'address_from' => $fromAddress, 'address_to' => $toAddress, 'parcel' => $parcel, 'submission_type' => 'PICKUP', 'insurance_amount' => '30', 'insurance_currency' => 'USD', 'extra' => '{signature_confirmation: true}', 'customs_declaration' => $customs_declaration["object_id"]));
//Wait for rates to be generated
$attempts = 0;
while (($shipment["object_status"] == "QUEUED" || $shipment["object_status"] == "WAITING") && $attempts < 10) {
    $shipment = Shippo_Shipment::retrieve($shipment["object_id"]);
    $attempts += 1;
}
//Get all rates for shipment.
$rates = Shippo_Shipment::get_shipping_rates(array('id' => $shipment["object_id"]));
<?php

/* 
This example demonstrates how to purchase a label for a domestic US shipment.
*/
require_once 'lib/Shippo.php';
// Replace <API-KEY> with your credentials
Shippo::setApiKey("<API-KEY>");
// example fromAddress
$fromAddress = array('object_purpose' => 'PURCHASE', 'name' => 'Shippo Itle"', 'company' => 'Shippo', 'street1' => '215 Clayton St.', 'city' => 'San Francisco', 'state' => 'CA', 'zip' => '94117', 'country' => 'US', 'phone' => '+1 555 341 9393', 'email' => '*****@*****.**');
// example fromAddress
$toAddress = array('object_purpose' => 'PURCHASE', 'name' => 'Mr Hippo"', 'company' => 'San Diego Zoo"', 'street1' => '2920 Zoo Drive"', 'city' => 'San Diego', 'state' => 'CA', 'zip' => '92101', 'country' => 'US', 'phone' => '+1 555 341 9393', 'email' => '*****@*****.**');
// example parcel
$parcel = array('length' => '5', 'width' => '5', 'height' => '5', 'distance_unit' => 'in', 'weight' => '2', 'mass_unit' => 'lb');
// example Shipment object
$shipment = Shippo_Shipment::create(array('object_purpose' => 'PURCHASE', 'address_from' => $fromAddress, 'address_to' => $toAddress, 'parcel' => $parcel, 'submission_type' => 'PICKUP', 'insurance_amount' => '30', 'insurance_currency' => 'USD'));
// Wait for rates to be generated
$ratingStartTime = time();
while ($shipment["object_status"] == "QUEUED" || $shipment["object_status"] == "WAITING") {
    $shipment = Shippo_Shipment::retrieve($shipment["object_id"]);
    usleep(200000);
    //sleeping 200ms
    if (time() - $ratingStartTime > 25) {
        break;
    }
}
// Get all rates for shipment.
$rates = Shippo_Shipment::get_shipping_rates(array('id' => $shipment["object_id"]));
// Get the first rate from the rates results
$rate = $rates["results"][0];
// Purchase the desired rate
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     \Shippo::setApiKey(env('SHIPPO_API_KEY'));
 }
 function setUp()
 {
     Shippo::setApiKey('dW5pdHRlc3Q6dW5pdHRlc3Q=');
 }
 /**
  * @param string $apiVersion The API version to use for requests.
  */
 public static function setApiVersion($apiVersion)
 {
     self::$apiVersion = $apiVersion;
 }
 public function testSetApiKey()
 {
     Shippo::setApiKey('dW5pdHRlc3Q6dW5pdHRlc3Q=');
     $this->assertEqual(Shippo::getApiKey(), 'dW5pdHRlc3Q6dW5pdHRlc3Q=');
 }