PHP code example of jsamhall / shipengine

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\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');
$to->setAddressResidentialIndicator('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('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