PHP code example of krsman / fedex-laravel4

1. Go to this page and download the library: Download krsman/fedex-laravel4 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/ */

    

krsman / fedex-laravel4 example snippets




...
'providers' => array(

		'Illuminate\Foundation\Providers\ArtisanServiceProvider',
		'Illuminate\Auth\AuthServiceProvider',
		'Illuminate\Cache\CacheServiceProvider',
		'Illuminate\Session\CommandsServiceProvider',

...
		'Krsman\FedEx\Laravel\Providers\FedExServiceProvider',
    ),



...
    'aliases' => array(

        'FedEx'     => 'Krsman\FedEx\Laravel\Facades\FedEx'

    ),
 artisan config:publish krsman/fedex-laravel4


$rateRequest = FedEx::rateRequest();

$shipment = new \Arkitecht\FedEx\Structs\RequestedShipment();
$shipment->TotalWeight = new \Arkitecht\FedEx\Structs\Weight(\Arkitecht\FedEx\Enums\WeightUnits::VALUE_LB, $weight);

$shipment->Shipper = new \Arkitecht\FedEx\Structs\Party();
$shipment->Shipper->Address = new \Arkitecht\FedEx\Structs\Address(
    $shipper->address,
    $shipper->city,
    $shipper->state,
    $shipper->zip,
    null, 'US');

$shipment->Recipient = new \Arkitecht\FedEx\Structs\Party();
$shipment->Recipient->Address = new \Arkitecht\FedEx\Structs\Address(
    $recipient->address,
    $recipient->city,
    $recipient->state,
    $recipient->zip,
    null, 'US');

$lineItem = new \Arkitecht\FedEx\Structs\RequestedPackageLineItem();
$lineItem->Weight = new \Arkitecht\FedEx\Structs\Weight(\Arkitecht\FedEx\Enums\WeightUnits::VALUE_LB, $weight);
$lineItem->GroupPackageCount = 1;
$shipment->PackageCount = 1;

$shipment->RequestedPackageLineItems = [
    $lineItem
];

$rateRequest->Version = FedEx::rateService()->version;

$rateRequest->setRequestedShipment($shipment);

$rate = FedEx::rateService();

$response = $rate->getRates($rateRequest);

$rates = [];

if ($response->HighestSeverity == 'SUCCESS') {
    foreach ($response->RateReplyDetails as $rate) {
        $rates[$rate->ServiceType] = $rate->RatedShipmentDetails[0]->ShipmentRateDetail->TotalNetCharge->Amount;
    }