2017 © Pedro Peláez
 

library php-fedex-api-wrapper

API Wrapper for Fedex web services

image

jeremy-dunn/php-fedex-api-wrapper

API Wrapper for Fedex web services

  • Wednesday, July 25, 2018
  • by JeremyDunn
  • Repository
  • 11 Watchers
  • 96 Stars
  • 48,622 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 92 Forks
  • 11 Open issues
  • 15 Versions
  • 17 % Grown

The README.md

PHP FedEx API Wrapper

Latest Stable Version Total Downloads, (*1)

This library provides a fluid interface for constructing requests to the FedEx web service API., (*2)

General Information

All of the code under the FedEx namespace is generated using the generate-classes-from-wsdls.php script. Each web service has it's own class namespace. See the official FedEx web service API documentation for a description of these services., (*3)

Installation

composer require jeremy-dunn/php-fedex-api-wrapper

Using the library

The easiest way to get started constructing a web service request is to create an new Request object for the particular service you wish to use and then work backward by injecting the objects necessary to complete the request., (*4)

For example if we wish to get shipping rates, we'll create a new instance of FedEx\RateService\Request and call the getGetRatesReply() method. This method requires an instance of FedEx\RateService\ComplexType\RateRequest which itself requires instances of FedEx\RateService\ComplexType\RequestedShipment, FedEx\RateService\ComplexType\TransactionDetail, FedEx\RateService\ComplexType\WebAuthenticationDetail, FedEx\RateService\ComplexType\ClientDetail, and so on. See below for an example., (*5)

Rate Service request example

This assumes the FEDEX_KEY, FEDEX_PASSWORD, FEDEX_ACCOUNT_NUMBER, and FEDEX_METER_NUMBER are previously defined in your application. Also note that by default, the library will use the beta/testing server (wsbeta.fedex.com). To use the production server (ws.fedex.com), set the location on the \SoapClient returned from the Request. See below for an example of how to do this., (*6)

use FedEx\RateService\Request;
use FedEx\RateService\ComplexType;
use FedEx\RateService\SimpleType;

$rateRequest = new ComplexType\RateRequest();

//authentication & client details
$rateRequest->WebAuthenticationDetail->UserCredential->Key = FEDEX_KEY;
$rateRequest->WebAuthenticationDetail->UserCredential->Password = FEDEX_PASSWORD;
$rateRequest->ClientDetail->AccountNumber = FEDEX_ACCOUNT_NUMBER;
$rateRequest->ClientDetail->MeterNumber = FEDEX_METER_NUMBER;

$rateRequest->TransactionDetail->CustomerTransactionId = 'testing rate service request';

//version
$rateRequest->Version->ServiceId = 'crs';
$rateRequest->Version->Major = 24;
$rateRequest->Version->Minor = 0;
$rateRequest->Version->Intermediate = 0;

$rateRequest->ReturnTransitAndCommit = true;

//shipper
$rateRequest->RequestedShipment->PreferredCurrency = 'USD';
$rateRequest->RequestedShipment->Shipper->Address->StreetLines = ['10 Fed Ex Pkwy'];
$rateRequest->RequestedShipment->Shipper->Address->City = 'Memphis';
$rateRequest->RequestedShipment->Shipper->Address->StateOrProvinceCode = 'TN';
$rateRequest->RequestedShipment->Shipper->Address->PostalCode = 38115;
$rateRequest->RequestedShipment->Shipper->Address->CountryCode = 'US';

//recipient
$rateRequest->RequestedShipment->Recipient->Address->StreetLines = ['13450 Farmcrest Ct'];
$rateRequest->RequestedShipment->Recipient->Address->City = 'Herndon';
$rateRequest->RequestedShipment->Recipient->Address->StateOrProvinceCode = 'VA';
$rateRequest->RequestedShipment->Recipient->Address->PostalCode = 20171;
$rateRequest->RequestedShipment->Recipient->Address->CountryCode = 'US';

//shipping charges payment
$rateRequest->RequestedShipment->ShippingChargesPayment->PaymentType = SimpleType\PaymentType::_SENDER;

//rate request types
$rateRequest->RequestedShipment->RateRequestTypes = [SimpleType\RateRequestType::_PREFERRED, SimpleType\RateRequestType::_LIST];

$rateRequest->RequestedShipment->PackageCount = 2;

//create package line items
$rateRequest->RequestedShipment->RequestedPackageLineItems = [new ComplexType\RequestedPackageLineItem(), new ComplexType\RequestedPackageLineItem()];

//package 1
$rateRequest->RequestedShipment->RequestedPackageLineItems[0]->Weight->Value = 2;
$rateRequest->RequestedShipment->RequestedPackageLineItems[0]->Weight->Units = SimpleType\WeightUnits::_LB;
$rateRequest->RequestedShipment->RequestedPackageLineItems[0]->Dimensions->Length = 10;
$rateRequest->RequestedShipment->RequestedPackageLineItems[0]->Dimensions->Width = 10;
$rateRequest->RequestedShipment->RequestedPackageLineItems[0]->Dimensions->Height = 3;
$rateRequest->RequestedShipment->RequestedPackageLineItems[0]->Dimensions->Units = SimpleType\LinearUnits::_IN;
$rateRequest->RequestedShipment->RequestedPackageLineItems[0]->GroupPackageCount = 1;

//package 2
$rateRequest->RequestedShipment->RequestedPackageLineItems[1]->Weight->Value = 5;
$rateRequest->RequestedShipment->RequestedPackageLineItems[1]->Weight->Units = SimpleType\WeightUnits::_LB;
$rateRequest->RequestedShipment->RequestedPackageLineItems[1]->Dimensions->Length = 20;
$rateRequest->RequestedShipment->RequestedPackageLineItems[1]->Dimensions->Width = 20;
$rateRequest->RequestedShipment->RequestedPackageLineItems[1]->Dimensions->Height = 10;
$rateRequest->RequestedShipment->RequestedPackageLineItems[1]->Dimensions->Units = SimpleType\LinearUnits::_IN;
$rateRequest->RequestedShipment->RequestedPackageLineItems[1]->GroupPackageCount = 1;

$rateServiceRequest = new Request();
//$rateServiceRequest->getSoapClient()->__setLocation(Request::PRODUCTION_URL); //use production URL

$rateReply = $rateServiceRequest->getGetRatesReply($rateRequest); // send true as the 2nd argument to return the SoapClient's stdClass response.


if (!empty($rateReply->RateReplyDetails)) {
    foreach ($rateReply->RateReplyDetails as $rateReplyDetail) {
        var_dump($rateReplyDetail->ServiceType);
        if (!empty($rateReplyDetail->RatedShipmentDetails)) {
            foreach ($rateReplyDetail->RatedShipmentDetails as $ratedShipmentDetail) {
                var_dump($ratedShipmentDetail->ShipmentRateDetail->RateType . ": " . $ratedShipmentDetail->ShipmentRateDetail->TotalNetCharge->Amount);
            }
        }
        echo "


"; } } var_dump($rateReply);

More examples can be found in the examples folder., (*7)

Change Log

The Versions

25/07 2018

dev-update-services

dev-update-services https://github.com/JeremyDunn/php-fedex-api-wrapper

API Wrapper for Fedex web services

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

shipping soap fedex

22/01 2018

dev-master

9999999-dev https://github.com/JeremyDunn/php-fedex-api-wrapper

API Wrapper for Fedex web services

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

shipping soap fedex

03/11 2017

2.6.2

2.6.2.0 https://github.com/JeremyDunn/php-fedex-api-wrapper

API Wrapper for Fedex web services

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

shipping soap fedex

03/11 2017

2.6.1

2.6.1.0 https://github.com/JeremyDunn/php-fedex-api-wrapper

API Wrapper for Fedex web services

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

shipping soap fedex

02/11 2017
02/11 2017
02/11 2017
02/11 2017
21/08 2017

dev-request-factory

dev-request-factory https://github.com/JeremyDunn/php-fedex-api-wrapper

API Wrapper for Fedex web services

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

shipping soap fedex

20/08 2017
19/08 2017
13/07 2017
18/06 2017

dev-response-parsing

dev-response-parsing https://github.com/JeremyDunn/php-fedex-api-wrapper

API Wrapper for Fedex web services

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

shipping soap fedex

05/04 2017

1.1

1.1.0.0 https://github.com/JeremyDunn/php-fedex-api-wrapper

API Wrapper for Fedex web services

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

shipping soap fedex

28/03 2017

1.0

1.0.0.0 https://github.com/JeremyDunn/php-fedex-api-wrapper

API Wrapper for Fedex web services

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

shipping soap fedex