2017 © Pedro Peláez
 

library ups-api

PHP UPS API

image

gabrielbull/ups-api

PHP UPS API

  • Monday, April 9, 2018
  • by gabrielbull
  • Repository
  • 28 Watchers
  • 240 Stars
  • 233,046 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 135 Forks
  • 33 Open issues
  • 48 Versions
  • 8 % Grown

The README.md

PHP UPS API

CI StyleCI Scrutinizer Code Quality Code Coverage Code Climate Latest Stable Version Total Downloads License Join the chat at https://gitter.im/gabrielbull/php-ups-api, (*1)

This library wrap all the UPS API into a simple to use PHP Library. It currently covers the Quantum View®, Tracking API, Shipping API, Rating API and Time in Transit API. Feel free to contribute., (*2)

Table Of Content

  1. Requirements
  2. Installation
  3. Address Validation Class
  4. Simple Address Validation Class
  5. QuantumView Class
  6. Tracking Class
  7. Rate Class
  8. RateTimeInTransit Class
  9. TimeInTransit Class
  10. Locator Class
  11. Tradeability Class
  12. Shipping Class
  13. Shipment Service Options
  14. Logging
  15. License

, (*3)

Requirements

This library uses PHP 7.1+., (*4)

To use the UPS API, you have to request an access key from UPS. For every request, you will have to provide the Access Key, your UPS User ID and Password., (*5)

, (*6)

Installation

It is recommended that you install the PHP UPS API library through composer. To do so, run the Composer command to install the latest stable version of PHP UPS API:, (*7)

$ composer require gabrielbull/ups-api

If not using composer, you must also include these libraries: Guzzle, Guzzle Promises, [Guzzle PSR7] (https://github.com/guzzle/psr7), PHP-Fig PSR Log, and PHP-Fig HTTP Message., (*8)

, (*9)

Address Validation Class (Street Level)

The Address Validation Class allow you to validate an address at street level. Suggestions are given when address is invalid., (*10)

Note: UPS has two Address Validations. This is Street Level option, which includes all option of the normal Address Validation class and adds street level validation., (*11)

Currently, only US & Puerto Rico are supported., (*12)

, (*13)

Example

$address = new \Ups\Entity\Address();
$address->setAttentionName('Test Test');
$address->setBuildingName('Test');
$address->setAddressLine1('Address Line 1');
$address->setAddressLine2('Address Line 2');
$address->setAddressLine3('Address Line 3');
$address->setStateProvinceCode('NY');
$address->setCity('New York');
$address->setCountryCode('US');
$address->setPostalCode('10000');

$xav = new \Ups\AddressValidation($accessKey, $userId, $password);
$xav->activateReturnObjectOnValidate(); //This is optional
try {
    $response = $xav->validate($address, $requestOption = \Ups\AddressValidation::REQUEST_OPTION_ADDRESS_VALIDATION, $maxSuggestion = 15);
} catch (Exception $e) {
    var_dump($e);
}

AddressValidation::validateReturnAVObject()

In the code above $xav->activateReturnObjectOnValidate() is completely optional. Calling this method will cause AddressValidation::validate() to return an AddressValidationResponse object. If you do not call this method, validate continues to function as it has previously. If you do not call this method, a single object with either the matched validated address, or the first candidate address if the address is ambiguous, will be returned., (*14)

The AddressValidationResponse object provides a number of methods to allow you to more easily query the API response to determine the outcome. Continuing the example from above, returning an AddressValidationResponse object will allow you to be a bit more specific with how you handle the various outcomes:, (*15)

if ($response->noCandidates()) {
    //Do something clever and helpful to let the use know the address is invalid
}
if ($response->isAmbiguous()) {
    $candidateAddresses = $response->getCandidateAddressList();
    foreach($candidateAddresses as $address) {
        //Present user with list of candidate addresses so they can pick the correct one        
    }
}
if ($response->isValid()) {
    $validAddress = $response->getValidatedAddress();

    //Show user validated address or update their address with the 'official' address
    //Or do something else helpful...
}

, (*16)

Parameters

Address Validation parameters are:, (*17)

  • address Address object as constructed in example
  • requestOption One of the three request options. See documentation. Default = Address Validation.
  • maxSuggestion Maximum number of suggestions to be returned. Max = 50

, (*18)

Simple Address Validation Class

The Simple Address Validation Class allow you to validate less extensive as the previous class. It returns a quality score of the supplied address and provides alternatives., (*19)

Note: UPS has two Address Validations. This is the Simple option., (*20)

Currently, only US & Puerto Rico are supported., (*21)

, (*22)

Example

$address = new \Ups\Entity\Address();
$address->setStateProvinceCode('NY');
$address->setCity('New York');
$address->setCountryCode('US');
$address->setPostalCode('10000');

$av = new \Ups\SimpleAddressValidation($accessKey, $userId, $password);
try {
    $response = $av->validate($address);
    var_dump($response);
} catch (Exception $e) {
    var_dump($e);
}

, (*23)

Parameters

Simple Address Validation parameters are:, (*24)

  • address Address object as constructed in example

, (*25)

QuantumView Class

The QuantumView Class allow you to request a Quantum View Data subscription., (*26)

, (*27)

Example

$quantumView = new Ups\QuantumView($accessKey, $userId, $password);

try {
    // Get the subscription for all events for the last hour
    $events = $quantumView->getSubscription(null, (time() - 3600));

    foreach($events as $event) {
        // Your code here
        echo $event->Type;
    }

} catch (Exception $e) {
    var_dump($e);
}

, (*28)

Parameters

QuantumView parameters are:, (*29)

  • name Name of subscription requested by user. If null, all events will be returned.
  • beginDateTime Beginning date time for the retrieval criteria of the subscriptions. Format: Y-m-d H:i:s or Unix timestamp.
  • endDateTime Ending date time for the retrieval criteria of the subscriptions. Format: Y-m-d H:i:s or Unix timestamp.
  • fileName File name of specific subscription requested by user.
  • bookmark Bookmarks the file for next retrieval.

If you provide a beginDateTime, but no endDateTime, the endDateTime will default to the current date time., (*30)

To use the fileName parameter, do not provide a beginDateTime., (*31)

, (*32)

Tracking Class

The Tracking Class allow you to track a shipment using the UPS Tracking API., (*33)

, (*34)

Example using Tracking Number / Mail Innovations tracking number

$tracking = new Ups\Tracking($accessKey, $userId, $password);

try {
    $shipment = $tracking->track('TRACKING NUMBER');

    foreach($shipment->Package->Activity as $activity) {
        var_dump($activity);
    }

} catch (Exception $e) {
    var_dump($e);
}

, (*35)

Parameters

Tracking parameters are:, (*36)

  • trackingNumber The package’s tracking number.
  • requestOption Optional processing. For Mail Innovations the only valid options are Last Activity and All activity.

, (*37)

Example using Reference Number

$tracking = new Ups\Tracking($accessKey, $userId, $password);

try {
    $shipment = $tracking->trackByReference('REFERENCE NUMBER');

    foreach($shipment->Package->Activity as $activity) {
        var_dump($activity);
    }

} catch (Exception $e) {
    var_dump($e);
}

, (*38)

Parameters

Tracking parameters are:, (*39)

  • referenceNumber The ability to track any UPS package or shipment by reference number. Reference numbers can be a purchase order number, job number, etc. Reference Number is supplied when generating a shipment.
  • requestOption Optional processing. For Mail Innovations the only valid options are Last Activity and All activity.

, (*40)

Example using Reference Number with additional parameters

$tracking = new Ups\Tracking($accessKey, $userId, $password);

$tracking->setShipperNumber('SHIPPER NUMBER');

$beginDate = new \DateTime('2016-01-01');
$endDate = new \DateTime('2016-01-31');

$tracking->setBeginDate($beginDate);
$tracking->setEndDate($endDate);

try {
    $shipment = $tracking->trackByReference('REFERENCE NUMBER');

    foreach($shipment->Package->Activity as $activity) {
        var_dump($activity);
    }

} catch (Exception $e) {
    var_dump($e);
}

The parameters shipperNumber, beginDate and endDate are optional. Either of the parameters can be set individually. These parameters can help to narrow the search field when tracking by reference, since it might happen that the reference number used is not unique. When using tracking by tracking number these parameters are not needed since the tracking number is unique., (*41)

, (*42)

Rate Class

The Rate Class allow you to get shipment rates using the UPS Rate API., (*43)

, (*44)

Example

$rate = new Ups\Rate(
    $accessKey,
    $userId,
    $password
);

try {
    $shipment = new \Ups\Entity\Shipment();

    $shipperAddress = $shipment->getShipper()->getAddress();
    $shipperAddress->setPostalCode('99205');

    $address = new \Ups\Entity\Address();
    $address->setPostalCode('99205');
    $shipFrom = new \Ups\Entity\ShipFrom();
    $shipFrom->setAddress($address);

    $shipment->setShipFrom($shipFrom);

    $shipTo = $shipment->getShipTo();
    $shipTo->setCompanyName('Test Ship To');
    $shipToAddress = $shipTo->getAddress();
    $shipToAddress->setPostalCode('99205');

    $package = new \Ups\Entity\Package();
    $package->getPackagingType()->setCode(\Ups\Entity\PackagingType::PT_PACKAGE);
    $package->getPackageWeight()->setWeight(10);

    // if you need this (depends of the shipper country)
    $weightUnit = new \Ups\Entity\UnitOfMeasurement;
    $weightUnit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_KGS);
    $package->getPackageWeight()->setUnitOfMeasurement($weightUnit);

    $dimensions = new \Ups\Entity\Dimensions();
    $dimensions->setHeight(10);
    $dimensions->setWidth(10);
    $dimensions->setLength(10);

    $unit = new \Ups\Entity\UnitOfMeasurement;
    $unit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_IN);

    $dimensions->setUnitOfMeasurement($unit);
    $package->setDimensions($dimensions);

    $shipment->addPackage($package);

    var_dump($rate->getRate($shipment));
} catch (Exception $e) {
    var_dump($e);
}

, (*45)

Parameters

  • rateRequest Mandatory. rateRequest Object with shipment details

This Rate class is not finished yet! Parameter should be added when it will be finished., (*46)

, (*47)

RateTimeInTransit Class

The RateTimeInTransit Class allow you to get shipment rates like the Rate Class, but the response will also include TimeInTransit data., (*48)

, (*49)

Example

$rate = new Ups\RateTimeInTransit(
    $accessKey,
    $userId,
    $password
);

try {
    $shipment = new \Ups\Entity\Shipment();

    $shipperAddress = $shipment->getShipper()->getAddress();
    $shipperAddress->setPostalCode('99205');

    $address = new \Ups\Entity\Address();
    $address->setPostalCode('99205');
    $shipFrom = new \Ups\Entity\ShipFrom();
    $shipFrom->setAddress($address);

    $shipment->setShipFrom($shipFrom);

    $shipTo = $shipment->getShipTo();
    $shipTo->setCompanyName('Test Ship To');
    $shipToAddress = $shipTo->getAddress();
    $shipToAddress->setPostalCode('99205');

    $package = new \Ups\Entity\Package();
    $package->getPackagingType()->setCode(\Ups\Entity\PackagingType::PT_PACKAGE);
    $package->getPackageWeight()->setWeight(10);

    // if you need this (depends of the shipper country)
    $weightUnit = new \Ups\Entity\UnitOfMeasurement;
    $weightUnit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_KGS);
    $package->getPackageWeight()->setUnitOfMeasurement($weightUnit);

    $dimensions = new \Ups\Entity\Dimensions();
    $dimensions->setHeight(10);
    $dimensions->setWidth(10);
    $dimensions->setLength(10);

    $unit = new \Ups\Entity\UnitOfMeasurement;
    $unit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_IN);

    $dimensions->setUnitOfMeasurement($unit);
    $package->setDimensions($dimensions);

    $shipment->addPackage($package);

    $deliveryTimeInformation = new \Ups\Entity\DeliveryTimeInformation();
    $deliveryTimeInformation->setPackageBillType(\Ups\Entity\DeliveryTimeInformation::PBT_NON_DOCUMENT);

    $pickup = new \Ups\Entity\Pickup();
    $pickup->setDate("20170520");
    $pickup->setTime("160000");
    $shipment->setDeliveryTimeInformation($deliveryTimeInformation);

    var_dump($rate->shopRatesTimeInTransit($shipment));
} catch (Exception $e) {
    var_dump($e);
}

, (*50)

Parameters

  • rateRequest Mandatory. rateRequest Object with shipment details

This RateTimeInTransit extends the Rate class which is not finished yet! Parameter should be added when it will be finished., (*51)

, (*52)

TimeInTransit Class

The TimeInTransit Class allow you to get all transit times using the UPS TimeInTransit API., (*53)

, (*54)

Example

$timeInTransit = new Ups\TimeInTransit($access, $userid, $passwd);

try {
    $request = new \Ups\Entity\TimeInTransitRequest;

    // Addresses
    $from = new \Ups\Entity\AddressArtifactFormat;
    $from->setPoliticalDivision3('Amsterdam');
    $from->setPostcodePrimaryLow('1000AA');
    $from->setCountryCode('NL');
    $request->setTransitFrom($from);

    $to = new \Ups\Entity\AddressArtifactFormat;
    $to->setPoliticalDivision3('Amsterdam');
    $to->setPostcodePrimaryLow('1000AA');
    $to->setCountryCode('NL');
    $request->setTransitTo($to);

    // Weight
    $shipmentWeight = new \Ups\Entity\ShipmentWeight;
    $shipmentWeight->setWeight($totalWeight);
    $unit = new \Ups\Entity\UnitOfMeasurement;
    $unit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_KGS);
    $shipmentWeight->setUnitOfMeasurement($unit);
    $request->setShipmentWeight($shipmentWeight);

    // Packages
    $request->setTotalPackagesInShipment(2);

    // InvoiceLines
    $invoiceLineTotal = new \Ups\Entity\InvoiceLineTotal;
    $invoiceLineTotal->setMonetaryValue(100.00);
    $invoiceLineTotal->setCurrencyCode('EUR');
    $request->setInvoiceLineTotal($invoiceLineTotal);

    // Pickup date
    $request->setPickupDate(new DateTime);

    // Get data
    $times = $timeInTransit->getTimeInTransit($request);

    foreach($times->ServiceSummary as $serviceSummary) {
        var_dump($serviceSummary);
    }

} catch (Exception $e) {
    var_dump($e);
}

, (*55)

Parameters

  • timeInTransitRequest Mandatory. timeInTransitRequest Object with shipment details, see example above.

, (*56)

Locator Class

The Locator class allows you to search for UPS Access Point locations., (*57)

, (*58)

Example

$locatorRequest = new \Ups\Entity\LocatorRequest;

$originAddress = new \Ups\Entity\OriginAddress;
$address = new \Ups\Entity\AddressKeyFormat;
$address->setCountryCode('NL');
$originAddress->setAddressKeyFormat($address);

$geocode = new \Ups\Entity\GeoCode;
$geocode->setLatitude(52.0000);
$geocode->setLongitude(4.0000);
$originAddress->setGeoCode($geocode);
$locatorRequest->setOriginAddress($originAddress);

$translate = new \Ups\Entity\Translate;
$translate->setLanguageCode('ENG');
$locatorRequest->setTranslate($translate);

$acccessPointSearch = new \Ups\Entity\AccessPointSearch;
$acccessPointSearch->setAccessPointStatus(\Ups\Entity\AccessPointSearch::STATUS_ACTIVE_AVAILABLE);

$locationSearch = new \Ups\Entity\LocationSearchCriteria;
$locationSearch->setAccessPointSearch($acccessPointSearch);
$locationSearch->setMaximumListSize(25);

$locatorRequest->setLocationSearchCriteria($locationSearch);

$unitOfMeasurement = new \Ups\Entity\UnitOfMeasurement;
$unitOfMeasurement->setCode(\Ups\Entity\UnitOfMeasurement::UOM_KM);
$unitOfMeasurement->setDescription('Kilometers');
$locatorRequest->setUnitOfMeasurement($unitOfMeasurement);

try {
    // Get the locations
    $locator = new Ups\Locator($accessKey, $userId, $password);
    $locations = $locator->getLocations($locatorRequest, \Ups\Locator::OPTION_UPS_ACCESS_POINT_LOCATIONS);

    foreach($locations->SearchResults->DropLocation as $location) {
        // Your code here
        var_dump($location);
    }

} catch (Exception $e) {
    var_dump($e);
}

, (*59)

Parameters

Locator class parameters are:, (*60)

  • locatorRequest Mandatory. locatorRequest object with request details, see example
  • requestOption Optional. Type of locations you are searching for.

, (*61)

Tradeability Class

The Tradeability class allows you to get data for international shipments: * Landed Costs (e.g. duties) * Denied Party Screener * Import Compliance * Export License Detection, (*62)

Note: only the Landed Costs API is currently implemented., (*63)

⚠️ Tradeability is only available through a SOAP API. Therefore you are required to have the SOAP extension installed on your system., (*64)

, (*65)

Example

// Build request
$landedCostRequest = new \Ups\Entity\Tradeability\LandedCostRequest;

// Build shipment
$shipment = new \Ups\Entity\Tradeability\Shipment;
$shipment->setOriginCountryCode('NL');
$shipment->setDestinationCountryCode('US');
$shipment->setDestinationStateProvinceCode('TX');
$shipment->setResultCurrencyCode('EUR');
$shipment->setTariffCodeAlert(1);
$shipment->setTransportationMode(\Ups\Entity\Tradeability\Shipment::TRANSPORT_MODE_AIR);
$shipment->setTransactionReferenceId('1');

// Build product
$product = new \Ups\Entity\Tradeability\Product;
$product->setProductName('Test');
$tariffInfo = new \Ups\Entity\Tradeability\TariffInfo;
$tariffInfo->setTariffCode('5109.90.80.00');
$product->setTariffInfo($tariffInfo);
$product->setProductCountryCodeOfOrigin('BD');
$unitPrice = new \Ups\Entity\Tradeability\UnitPrice;
$unitPrice->setMonetaryValue(250);
$unitPrice->setCurrencyCode('EUR');
$product->setUnitPrice($unitPrice);
$weight = new Ups\Entity\Tradeability\Weight;
$weight->setValue(0.83);
$unitOfMeasurement = new \Ups\Entity\Tradeability\UnitOfMeasurement;
$unitOfMeasurement->setCode('kg');
$weight->setUnitOfMeasurement($unitOfMeasurement);
$product->setWeight($weight);
$quantity = new \Ups\Entity\Tradeability\Quantity;
$quantity->setValue(5);
$unitOfMeasurement = new \Ups\Entity\Tradeability\UnitOfMeasurement;
$unitOfMeasurement->setCode(\Ups\Entity\Tradeability\UnitOfMeasurement::PROD_PIECES);
$quantity->setUnitOfMeasurement($unitOfMeasurement);
$product->setQuantity($quantity);
$product->setTariffCodeAlert(1);

// Add product to shipment
$shipment->addProduct($product);

// Query request
$queryRequest = new \Ups\Entity\Tradeability\QueryRequest;
$queryRequest->setShipment($shipment);
$queryRequest->setSuppressQuestionIndicator(true);

// Build
$landedCostRequest->setQueryRequest($queryRequest);

try {
    // Get the data
    $api = new Ups\Tradeability($accessKey, $userId, $password);
    $result = $api->getLandedCosts($landedCostRequest);

    var_dump($result);
} catch (Exception $e) {
    var_dump($e);
}

, (*66)

Parameters

For the Landed Cost call, parameters are:, (*67)

  • landedCostRequest Mandatory. landedCostRequest object with request details, see example.

, (*68)

Shipping Class

The Shipping class allows you to register shipments. This also includes return shipments., (*69)

The shipping flow consists of 2 steps:, (*70)

  • Confirm: Send information to UPS to get it validated and get a digest you can use to accept the shipment.
  • Accept: Finalise the shipment, mark it as it will be shipped. Get label and additional information.

Please note this is just an example. Your use case might demand more or less information to be sent to UPS., (*71)

In the example $return is used to show how a return could be handled., (*72)

, (*73)

Example

// Start shipment
$shipment = new Ups\Entity\Shipment;

// Set shipper
$shipper = $shipment->getShipper();
$shipper->setShipperNumber('XX');
$shipper->setName('XX');
$shipper->setAttentionName('XX');
$shipperAddress = $shipper->getAddress();
$shipperAddress->setAddressLine1('XX');
$shipperAddress->setPostalCode('XX');
$shipperAddress->setCity('XX');
$shipperAddress->setStateProvinceCode('XX'); // required in US
$shipperAddress->setCountryCode('XX');
$shipper->setAddress($shipperAddress);
$shipper->setEmailAddress('XX'); 
$shipper->setPhoneNumber('XX');
$shipment->setShipper($shipper);

// To address
$address = new \Ups\Entity\Address();
$address->setAddressLine1('XX');
$address->setPostalCode('XX');
$address->setCity('XX');
$address->setStateProvinceCode('XX');  // Required in US
$address->setCountryCode('XX');
$shipTo = new \Ups\Entity\ShipTo();
$shipTo->setAddress($address);
$shipTo->setCompanyName('XX');
$shipTo->setAttentionName('XX');
$shipTo->setEmailAddress('XX'); 
$shipTo->setPhoneNumber('XX');
$shipment->setShipTo($shipTo);

// From address
$address = new \Ups\Entity\Address();
$address->setAddressLine1('XX');
$address->setPostalCode('XX');
$address->setCity('XX');
$address->setStateProvinceCode('XX');  
$address->setCountryCode('XX');
$shipFrom = new \Ups\Entity\ShipFrom();
$shipFrom->setAddress($address);
$shipFrom->setName('XX');
$shipFrom->setAttentionName($shipFrom->getName());
$shipFrom->setCompanyName($shipFrom->getName());
$shipFrom->setEmailAddress('XX');
$shipFrom->setPhoneNumber('XX');
$shipment->setShipFrom($shipFrom);

// Sold to
$address = new \Ups\Entity\Address();
$address->setAddressLine1('XX');
$address->setPostalCode('XX');
$address->setCity('XX');
$address->setCountryCode('XX');
$address->setStateProvinceCode('XX');
$soldTo = new \Ups\Entity\SoldTo;
$soldTo->setAddress($address);
$soldTo->setAttentionName('XX');
$soldTo->setCompanyName($soldTo->getAttentionName());
$soldTo->setEmailAddress('XX');
$soldTo->setPhoneNumber('XX');
$shipment->setSoldTo($soldTo);

// Set service
$service = new \Ups\Entity\Service;
$service->setCode(\Ups\Entity\Service::S_STANDARD);
$service->setDescription($service->getName());
$shipment->setService($service);

// Mark as a return (if return)
if ($return) {
    $returnService = new \Ups\Entity\ReturnService;
    $returnService->setCode(\Ups\Entity\ReturnService::PRINT_RETURN_LABEL_PRL);
    $shipment->setReturnService($returnService);
}

// Set description
$shipment->setDescription('XX');

// Add Package
$package = new \Ups\Entity\Package();
$package->getPackagingType()->setCode(\Ups\Entity\PackagingType::PT_PACKAGE);
$package->getPackageWeight()->setWeight(10);
$unit = new \Ups\Entity\UnitOfMeasurement;
$unit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_KGS);
$package->getPackageWeight()->setUnitOfMeasurement($unit);

// Set Package Service Options
$packageServiceOptions = new \Ups\Entity\PackageServiceOptions();
$packageServiceOptions->setShipperReleaseIndicator(true);
$package->setPackageServiceOptions($packageServiceOptions);

// Set dimensions
$dimensions = new \Ups\Entity\Dimensions();
$dimensions->setHeight(50);
$dimensions->setWidth(50);
$dimensions->setLength(50);
$unit = new \Ups\Entity\UnitOfMeasurement;
$unit->setCode(\Ups\Entity\UnitOfMeasurement::UOM_CM);
$dimensions->setUnitOfMeasurement($unit);
$package->setDimensions($dimensions);

// Add descriptions because it is a package
$package->setDescription('XX');

// Add this package
$shipment->addPackage($package);

// Set Reference Number
$referenceNumber = new \Ups\Entity\ReferenceNumber;
if ($return) {
    $referenceNumber->setCode(\Ups\Entity\ReferenceNumber::CODE_RETURN_AUTHORIZATION_NUMBER);
    $referenceNumber->setValue($return_id);
} else {
    $referenceNumber->setCode(\Ups\Entity\ReferenceNumber::CODE_INVOICE_NUMBER);
    $referenceNumber->setValue($order_id);
}
$shipment->setReferenceNumber($referenceNumber);

// Set payment information
$shipment->setPaymentInformation(new \Ups\Entity\PaymentInformation('prepaid', (object) ['AccountNumber' => $shipper->getShipperNumber()]));

// Ask for negotiated rates (optional)
$rateInformation = new \Ups\Entity\RateInformation;
$rateInformation->setNegotiatedRatesIndicator(1);
$shipment->setRateInformation($rateInformation);

// Get shipment info
try {
    $api = new Ups\Shipping($accessKey, $userId, $password); 

    $confirm = $api->confirm(\Ups\Shipping::REQ_VALIDATE, $shipment);
    var_dump($confirm); // Confirm holds the digest you need to accept the result

    if ($confirm) {
        $accept = $api->accept($confirm->ShipmentDigest);
        var_dump($accept); // Accept holds the label and additional information
    }
} catch (\Exception $e) {
    var_dump($e);
}

If you wanted to create a printable file from the UPS Shipping label image data that came back with $accept, you would use something like the following:, (*74)

$label_file = $order_id . ".gif"; 
$base64_string = $accept->PackageResults->LabelImage->GraphicImage;
$ifp = fopen($label_file, 'wb');
fwrite($ifp, base64_decode($base64_string));
fclose($ifp);

, (*75)

Parameters

For the Shipping confirm call, the parameters are:, (*76)

  • $validation A UPS_Shipping::REQ_* constant (or null). Required
  • $shipment Shipment data container. Required
  • $labelSpec LabelSpecification data. Optional
  • $receiptSpec ShipmentRequestReceiptSpecification data. Optional

For the Shipping accept call, the parameters are:, (*77)

  • $shipmentDigest The UPS Shipment Digest received from a ShipConfirm request. Required

, (*78)

Shipment Service Options

The Shipment Service Options class allows you to register shipments additional options. This also includes., (*79)

  • Add or Modify email notifications: Manage updates for this shipment.
  • Saturday Commericial: Get weekend delivery of your shipment.
  • Deliver only to receiver's address: Do not reroute for customer pickup at a UPS location.
  • UPS Carbon Neutral Shipments Thanks for offsetting the environmental impact of your shipment! : at a nominal fee for domestic and international shipments.

In the example ShipmentServiceOptions class is used to show how a Shipment Additional Option can be added to Shipment. , (*80)

Shipment Service Options Example

// Start shipment
$shipment = new Ups\Entity\Shipment;

// Create Shipment Service Options Class
    $shipmentOptions = new Ups\Entity\ShipmentServiceOptions;
    // Setting the Carbon Neutral Additional Option, you can set your desired one.
    $shipmentOptions->setUPScarbonneutralIndicator();
// Set Shipment Service Options Class
    $shipment->setShipmentServiceOptions($shipmentOptions);

, (*81)

Logging

All constructors take a PSR-3 compatible logger., (*82)

Besides that, the main UPS class has a public method setLogger to set it after the constructor ran., (*83)

Requests & responses (including XML, no access keys) are logged at DEBUG level. At INFO level only the event is reported, not the XML content. More severe problems (e.g. no connection) are logged with higher severity., (*84)

Example using Monolog

// Create logger
$log = new \Monolog\Logger('ups');
$log->pushHandler(new \Monolog\Handler\StreamHandler('logs/ups.log', \Monolog\Logger::DEBUG));

// Create Rate object + insert logger
$rate = new Ups\Rate($key, $username, $password, $useIntegration, $log);

, (*85)

License

PHP UPS API is licensed under The MIT License (MIT)., (*86)

The Versions

09/04 2018

dev-master

9999999-dev

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

09/04 2018

dev-rynner-master

dev-rynner-master

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

11/11 2017

0.8.0

0.8.0.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

11/11 2017

dev-mazzarito-master

dev-mazzarito-master

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

25/10 2017

0.7.14

0.7.14.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

16/10 2017

0.7.13

0.7.13.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

19/03 2017

0.7.12

0.7.12.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

15/09 2016

0.7.11

0.7.11.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

15/09 2016

dev-feature/simple-address-validation

dev-feature/simple-address-validation

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

12/07 2016

0.7.10

0.7.10.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

11/07 2016

dev-quickfix/encoding-issue

dev-quickfix/encoding-issue

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

04/07 2016

0.7.9

0.7.9.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

23/06 2016

0.7.8

0.7.8.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

31/05 2016

0.7.7

0.7.7.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

26/04 2016

dev-develop

dev-develop

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

04/03 2016

0.7.6

0.7.6.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

01/03 2016

0.7.5

0.7.5.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

21/02 2016

0.7.4

0.7.4.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

17/02 2016

0.7.3

0.7.3.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

09/01 2016

0.7.2

0.7.2.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

23/11 2015

0.7.1

0.7.1.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

16/11 2015

0.7.0

0.7.0.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

10/11 2015

0.6.3

0.6.3.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

10/11 2015

0.6.2

0.6.2.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit tradeability

30/10 2015

0.6.1

0.6.1.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit

25/09 2015

0.6.0

0.6.0.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Eduard Sukharev
by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit

16/09 2015

0.5.2

0.5.2.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit

28/08 2015

0.5.1

0.5.1.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit

26/08 2015

0.5.0

0.5.0.0

PHP UPS API

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit

21/08 2015

0.4.0

0.4.0.0 https://github.com/gabrielbull/php-ups-api

UPS API PHP Wrapper

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit

20/06 2015

0.3.3

0.3.3.0 https://github.com/gabrielbull/php-ups-api

UPS API PHP Wrapper

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit

19/06 2015

0.3.2

0.3.2.0 https://github.com/gabrielbull/php-ups-api

UPS API PHP Wrapper

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit

02/06 2015

0.3.1

0.3.1.0 https://github.com/gabrielbull/php-ups-api

UPS API PHP Wrapper

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit

21/05 2015

0.3.0

0.3.0.0 https://github.com/gabrielbull/php-ups-api

UPS API PHP Wrapper

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit

29/04 2015

0.2.5

0.2.5.0 https://github.com/gabrielbull/php-ups-api

UPS API PHP Wrapper

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit

22/04 2015

0.2.4

0.2.4.0 https://github.com/gabrielbull/php-ups-api

UPS API PHP Wrapper

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit

20/04 2015

0.2.3

0.2.3.0 https://github.com/gabrielbull/php-ups-api

UPS API PHP Wrapper

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit

27/01 2015

0.2.2

0.2.2.0 https://github.com/gabrielbull/php-ups-api

UPS API PHP Wrapper

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit

10/06 2014

0.2.1

0.2.1.0 https://github.com/gabrielbull/php-ups-api

UPS API PHP Wrapper

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit

11/05 2014

0.2.0

0.2.0.0 https://github.com/gabrielbull/php-ups-api

UPS API PHP Wrapper

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sebastien Vergnes
by Michael Williams

api wrapper shipping tracking ups rating rate quantum view time in transit

13/03 2013

v0.1.9

0.1.9.0 https://github.com/gavroche/ups-api-php

UPS API PHP Wrapper

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3

 

api wrapper tracking ups quantum view

13/03 2013

v0.1.8

0.1.8.0 https://github.com/gavroche/ups-api-php

UPS API PHP Wrapper

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3

 

api wrapper tracking ups quantum view

17/02 2013

v0.1.7

0.1.7.0 https://github.com/gavroche/ups-api-php

UPS API PHP Wrapper

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3

 

api wrapper tracking ups quantum view

01/02 2013

v0.1.6

0.1.6.0 https://github.com/gavroche/ups-api-php

UPS API PHP Wrapper

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3

 

api wrapper tracking ups quantum view

30/01 2013

v0.1.5

0.1.5.0 https://github.com/gavroche/ups-api-php

UPS API PHP Wrapper

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3

 

api wrapper tracking ups quantum view

28/01 2013

v0.1.4

0.1.4.0 https://github.com/gavroche/ups-api-php

UPS API PHP Wrapper

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3

 

api wrapper tracking ups quantum view

25/01 2013

v0.1.3

0.1.3.0 https://github.com/gavroche/ups-api-php

UPS API PHP Wrapper

  Sources   Download

GPL-2.0

The Requires

  • php >=5.3

 

api wrapper tracking ups quantum view

23/01 2013

v0.1

0.1.0.0 https://github.com/gavroche/ups

UPS Api PHP Wrapper

  Sources   Download

GPL-2.0

The Requires

  • php >=5.4.0

 

api wrapper ups