function testCreateTrack() { $shipment = Postmaster_Shipment::retrieve('2010'); $result = $shipment->track(); $this->assertTrue(is_array($result)); $this->assertNotEmpty($result); $this->assertTrue($result[0] instanceof Postmaster_Tracking); $resultArray = $result[0]->__toArray(); $this->assertArrayHasKey('status', $resultArray); $this->assertArrayHasKey('history', $resultArray); $this->assertNotEmpty($result[0]->history); $this->assertTrue($result[0]->history[0] instanceof Postmaster_TrackingHistory); }
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 */ $result = Postmaster_Shipment::all(array("limit" => 3)); //var_dump($result); /* monitor external package */ $result = Postmaster_Tracking::monitor_external(array("tracking_no" => "1ZW470V80310800043", "url" => "http://example.com/your-http-post-listener", "events" => ["Delivered", "Exception"]));