Exemplo n.º 1
0
if (!file_exists('../config.php')) {
    die("Prepare a config.php file. See: config.php.example");
}
include '../config.php';
use AntiMattr\ShipmentTracking\Client\AfterShip\TrackingClient;
use AntiMattr\ShipmentTracking\Model\CommonTracking;
use Buzz\Client\Curl;
// See config.php.example
$apiKey = AFTERSHIP_API_KEY;
$host = 'https://api.aftership.com';
$path = '/v4';
$buzz = new Curl();
$client = new TrackingClient($apiKey, $host, $path, $buzz);
$courier = 'usps';
$number = 'xxxxxx';
$tracking = new CommonTracking();
$tracking->setCourier($courier);
$tracking->setNumber($number);
$error = '';
$success = '';
if ($_POST) {
    try {
        if (!isset($_POST['courier'])) {
            throw new \Exception("The courier was not submitted");
        }
        if (!isset($_POST['number'])) {
            throw new \Exception("The tracking number was not submitted");
        }
        $courier = $_POST['courier'];
        $number = $_POST['number'];
        $tracking->setCourier($courier);
Exemplo n.º 2
0
require_once '../../vendor/autoload.php';
if (!file_exists('../config.php')) {
    die("Prepare a config.php file. See: config.php.example");
}
include '../config.php';
use AntiMattr\ShipmentTracking\Client\AfterShip\TrackingClient;
use AntiMattr\ShipmentTracking\Model\CommonTracking;
use Buzz\Client\Curl;
// See config.php.example
$apiKey = AFTERSHIP_API_KEY;
$host = 'https://api.aftership.com';
$path = '/v4';
$buzz = new Curl();
$client = new TrackingClient($apiKey, $host, $path, $buzz);
$number = 'xxxxxx';
$tracking = new CommonTracking();
$tracking->setNumber($number);
$error = '';
$success = '';
if ($_POST) {
    try {
        if (!isset($_POST['number'])) {
            throw new \Exception("The tracking number was not submitted");
        }
        $number = $_POST['number'];
        $tracking->setNumber($number);
        $client->create($tracking);
        $success = 'Tracking has been created for your shipment.';
    } catch (\Exception $e) {
        $error = sprintf('%s: %s', get_class($e), $e->getMessage());
    }