1. Go to this page and download the library: Download jsamhall/shipengine library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jsamhall / shipengine example snippets
$addressFormatter = new Acme\AddressFormatter; // implements Address\FormatterInterface
$shipEngine = new jsamhall\ShipEngine\ShipEngine('your_shipengine_api_key', $addressFormatter);
$carriers = $shipEngine->listCarriers();
use jsamhall\ShipEngine\Address\ArrayFormatter;
use jsamhall\ShipEngine\ShipEngine;
use jsamhall\ShipEngine\Address\Address;
use jsamhall\ShipEngine\Address\ResidentialIndicator;
use jsamhall\ShipEngine\Shipment\Package;
use jsamhall\ShipEngine\Labels\Shipment;
use jsamhall\ShipEngine\Carriers\USPS\ServiceCode;
$to = new Address();
$to->setName('Mickey and Minnie Mouse');
$to->setPhone('+1 (714) 781-456');
$to->setCompanyName('The Walt Disney Company');
$to->setAddressLine1('address_line1');
$to->setCityLocality('Burbank');
$to->setStateProvince('CA');
$to->setPostalCode('91521');
$to->setCountryCode('US');
// Addresses default to residential; declare a commercial address explicitly:
$to->setAddressResidentialIndicator(ResidentialIndicator::No);
$from = new Address;
$from->setName('Mickey and Minnie Mouse');
$from->setPhone('+1 (714) 781-456');
$from->setCompanyName('The Walt Disney Company');
$from->setAddressLine1('address_line1');
$from->setCityLocality('Burbank');
$from->setStateProvince('CA');
$from->setPostalCode('91521');
$from->setCountryCode('US');
$from->setAddressResidentialIndicator(ResidentialIndicator::No);
$weight = new Package\Weight(1.0);
$dimensions = new Package\Dimensions(10.0, 15.0, 8.0);
$package = new Package($weight, $dimensions);
$shipment = new Shipment(ServiceCode::PriorityMail, $to, $from, [$package]);
$addressFormatter = new ArrayFormatter();
$shipEngine = new ShipEngine('your_shipengine_api_key', $addressFormatter);
$testMode = true;
$label = $shipEngine->createLabel($shipment, $testMode);
/** @var Acme\Domain\Address $domainAddress */
$domainAddress = $this->addressRepository->find(1234);
$shipEngineAddress = $shipEngine->formatAddress($domainAddress);
// now $shipEngineAddress can be used for building e.g. an instance of Labels\Shipment
use jsamhall\ShipEngine\ShipEngine;
use jsamhall\ShipEngine\Address\ArrayFormatter;
$shipEngine = new ShipEngine('your_shipengine_api_key', new ArrayFormatter());
$tracking = $shipEngine->trackPackage('usps', '9405511899223197428490');
$tracking->getStatusCode(); // e.g. "DE" (raw ShipEngine code)
$tracking->getStatus(); // ?Tracking\StatusCode enum, e.g. StatusCode::Delivered
$tracking->getStatusDescription(); // e.g. "Delivered"
$tracking->isDelivered(); // bool
$tracking->getActualDeliveryDate(); // ?\DateTime
foreach ($tracking->getEvents() as $event) {
printf("%s — %s (%s)\n",
$event->getOccurredAt() ? $event->getOccurredAt()->format('c') : 'n/a',
$event->getDescription(),
$event->getCityLocality()
);
}
use jsamhall\ShipEngine\ShipEngine;
use jsamhall\ShipEngine\Address\ArrayFormatter;
$shipEngine = new ShipEngine('your_shipengine_api_key', new ArrayFormatter());
$tracking = $shipEngine->trackLtlShipment('FXFE', '123456789');
$tracking->getProNumber(); // "123456789"
$tracking->isDelivered(); // bool
$tracking->getSignatureName(); // ?string, e.g. "MARK PITTS"
$tracking->getEstimatedDeliveryDate(); // ?\DateTime
$tracking->getActualDeliveryDate(); // ?\DateTime
foreach ($tracking->getEvents() as $event) {
printf("%s — %s (%s, %s)\n",
$event->getOccurredAt()?->format('c') ?? 'n/a',
$event->getStatus(),
$event->getCityLocality(),
$event->getStateProvince()
);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.