示例#1
0
 function testValidateInsufficientData()
 {
     try {
         $result = Postmaster_AddressValidation::validate(array("company" => "ASLS", "contact" => "Joe Smith", "line1" => "007 Nowhere Ave", "city" => "Austin", "state" => "TX", "zip_code" => "00001", "country" => "US"));
     } catch (InvalidData_Error $expected) {
         $msg = $expected->getMessage();
         $this->assertEquals('Wrong address', $msg);
         return;
     }
 }
示例#2
0
 function testNoAuthError()
 {
     Postmaster::setApiKey('');
     try {
         $result = Postmaster_AddressValidation::validate(array());
     } catch (Authentication_Error $expected) {
         $msg = $expected->getMessage();
         $this->assertStringStartsWith('You must authorize', $msg);
         return;
     }
     $this->fail('An expected exception has not been raised.');
 }
示例#3
0
<?php

/* at startup set API key */
require_once './lib/Postmaster.php';
Postmaster::setApiKey("example-api-key");
/* at first validate recipient address */
$result = Postmaster_AddressValidation::validate(array("company" => "Postmaster Inc.", "contact" => "Joe Smith", "line1" => "701 Brazos St. Suite 1616", "city" => "Austin", "state" => "TX", "zip_code" => "78701", "country" => "US"));
//var_dump($result);
/* if address is ok you can ask for time and rates for it */
$result = Postmaster_TransitTimes::get(array("from_zip" => "78701", "to_zip" => "78704", "weight" => 1.5, "carrier" => "fedex"));
//var_dump($result);
$result = Postmaster_Rates::get(array("from_zip" => "78701", "to_zip" => "78704", "weight" => 1.5, "carrier" => "fedex"));
//var_dump($result);
/* when user will choose delivery type you create shipment */
$result = Postmaster_Shipment::create(array("to" => array("company" => "Postmaster Inc.", "contact" => "Joe Smith", "line1" => "701 Brazos St. Suite 1616", "city" => "Austin", "state" => "TX", "zip_code" => "78701", "phone_no" => "512-693-4040"), "from" => array("company" => "Postmaster Inc.", "contact" => "Joe Smith", "line1" => "701 Brazos St. Suite 1616", "city" => "Austin", "state" => "TX", "zip_code" => "78701", "phone_no" => "512-693-4040"), "carrier" => "fedex", "service" => "2DAY", "package" => array("weight" => 1.5, "length" => 10, "width" => 6, "height" => 8)));
//var_dump($result);
/* store in your DB shipment ID for later use */
$shipment_id = $result->id;
/* anytime you can extract shipment data */
$sm = Postmaster_Shipment::retrieve($shipment_id);
//var_dump($sm);
/* or check delivery status */
$result = $sm->track();
//var_dump($result);
/* you can cancel shipment, but only before being picked up by the carrier */
$result = $sm->void();
//var_dump($result);
/* list all shipments */
$result = Postmaster_Shipment::all();
//var_dump($result);
/* list 3 newest shipments */