public static function getDefaultShipment()
 {
     parent::setTestApiKey();
     $addressFrom = Shippo_AddressTest::getDefaultAddress();
     $addressTo = Shippo_AddressTest::getDefaultAddress();
     $parcel = Shippo_ParcelTest::getDefaultParcel();
     return Shippo_Shipment::create(array('object_purpose' => 'QUOTE', 'address_from' => $addressFrom->object_id, 'address_to' => $addressTo->object_id, 'parcel' => $parcel->object_id, 'submission_type' => 'PICKUP', 'submission_date' => '2013-12-03T12:00:00.000Z', 'insurance_amount' => '30', 'insurance_currency' => 'USD', 'extra' => '{signature_confirmation: true}', 'customs_declaration' => '', 'reference_1' => '', 'reference_2' => '', 'metadata' => 'Customer ID 123456'));
 }
Ejemplo n.º 2
0
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"]));
//Get the first rate in the rates results.
$rate = $rates["results"][0];
//Purchase the desired rate. sync=True indicates that the function will wait until the
//carrier returns a shipping label before it returns
$transaction = Shippo_Transaction::create(array('rate' => $rate["object_id"]));
//Wait for transaction to be proccessed
$attempts = 0;
Ejemplo n.º 3
0
<?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