function testGetTimes()
 {
     $result = Postmaster_TransitTimes::get(array("from_zip" => "78701", "to_zip" => "78704", "weight" => 1.5, "carrier" => "fedex"));
     $this->assertTrue(is_array($result));
     $this->assertNotEmpty($result);
     $this->assertTrue($result[0] instanceof Postmaster_TransitTime);
     $resultArray = $result[0]->__toArray();
     $this->assertArrayHasKey('delivery_timestamp', $resultArray);
     $this->assertArrayHasKey('service', $resultArray);
     $this->assertTrue($result[0]->delivery_timestamp instanceof DateTime);
     $possibleValues = ['GROUND', '3DAY', '2DAY', '2DAY_EARLY', '1DAY', '1DAY_EARLY', '1DAY_MORNING'];
     $this->assertContains($result[0]->service, $possibleValues);
 }
Exemplo n.º 2
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 */