PHP: FedEx shipping rates calculator

FedEx Ship Manager (FSM) Direct was designed to allow customers to connect directly to the FedEx back end systems using their own communications protocol. Welcome to FSM Direct!
You can compose FedEx XML Transactions to interface between your e-commerce application and the FedEx server and vice versa.
This solution is applicable only to those customers that have the development resources and knowledge to develop their own FedEx interface.

Before you begin:
FSM Direct Site Registration: To register in the FSM Direct program, go to http://www.fedex.com/us/solutions/wis/. Register and complete the brief registration form.

Steps for developing your own communications protocol and integrating it into your application are listed below.

  • Read and accept the FedEx Ship Manager Direct license agreement.
  • Review the FedEx Direct Documentation: Determine if this alternative or FedEx API is appropriate for your application.
  • Develop your application.
  • Send an email to websupport@fedex.com. Request to be set up for testing. Attach FedEx Express and/or FedEx Ground account number(s).
  • Test your application.

All documentation can be found here:

http://www.fedex.com/us/solutions/wis/pdf/fsm_directmanual.pdf

http://www.fedex.com/us/solutions/wis/pdf/xml_transguide.pdf

Here’s more about this class

How to use this Fedex rates class:


    $fedex = new Fedex;
    $fedex->setServer("https://gatewaybeta.fedex.com/GatewayDC");
    $fedex->setAccountNumber(123123123);
    $fedex->setMeterNumber(12312312);
    $fedex->setCarrierCode("FDXE");
    $fedex->setDropoffType("REGULARPICKUP");
    $fedex->setService($service, $serviceName);
    $fedex->setPackaging("YOURPACKAGING");
    $fedex->setWeightUnits("LBS");
    $fedex->setWeight(17);
    $fedex->setOriginStateOrProvinceCode("OH");
    $fedex->setOriginPostalCode(44333);
    $fedex->setOriginCountryCode("US");
    $fedex->setDestStateOrProvinceCode("CA");
    $fedex->setDestPostalCode(90210);
    $fedex->setDestCountryCode("US");
    $fedex->setPayorType("SENDER");

    $price = $fedex->getPrice();

All available variables can be found here: http://www.fedex.com/us/solutions/wis/pdf/xml_transguide.pdf (FDXRateRequest)

Possible Fedex answer:


fedex Object
(
    [server] => https://gatewaybeta.fedex.com/GatewayDC
    [accountNumber] => 123123123
    [meterNumber] => 12312312
    [carrierCode] => FDXE
    [dropoffType] => REGULARPICKUP
    [service] => STANDARDOVERNIGHT
    [serviceName] => FedEx Standard Overnight
    [packaging] => YOURPACKAGING
    [weightUnits] => LBS
    [weight] => 17
    [originStateOrProvinceCode] => OH
    [originPostalCode] => 44333
    [originCountryCode] => US
    [destStateOrProvinceCode] => CA
    [destPostalCode] => 90210
    [destCountryCode] => US
    [payorType] => SENDER
    [price] => price Object
        (
            [service] => FedEx Standard Overnight
            [rate] => 86.37
            [response] => Array
                (
                  ...//Here is full xml response
                )
        )
)

Click here to download FedEx shipping rates calculator class

Please make a donation of 1$ if you find our software useful and want to support the continued development.


Thank you.

74 Comments

  1. Jen says:

    Hi,
    I’ve been scouring the web for something like this but for the new web services technology rather than the soon to be depracted ShipManager API. Is that something you might have in the works or could you recommend any resources?

    Thanks much. 2+ months banging my noggin on my PC and not getting anywhere :)

  2. Aman says:

    i want all the fedex shipping method and price on my website but it display only the last one which is in loop .. pls tell me how to do that.
    thanks

  3. Erban says:

    Hey,

    Thanks for this script, it was very helpful.

    I think I might have found an error in the script. If one of the shipping methods returns and error, it will be assigned the price of the shipping method returned prior to itself.

    Say you request quotes for two shipping methods, METHOD1 and METHOD2. You will get METHOD1′s quotes but METHOD2 will fail, but it will still have a price, and that price will be METHOD1′s price. This happens because $this->price is not unset in the getPrice() method.

  4. Erban says:

    Be aware that when setting the number of packages you divide the total weight by 150 (which is the weight limit for most fedex services), but home ground delivery for example has a weight limit of 70.

    150 and 70 are lbs.

  5. manup says:

    Hi,

    I need the similar (Project) interface for creating Fedex Shipment using APIs.

    Please suggest…

  6. Harsh says:

    Hello,
    Superb work Algirdas. I really appreciate you. Thanks for providing this code and most important free to all. Keep up good work.

  7. nang says:

    Hi,

    Pls help for my problem. I got this error:

    Fatal error: Call to undefined function curl_init() in C:\xampp\htdocs\fedex.php on line 134

    Really appreciate your help.

  8. Algirdas says:

    You must enable curl library in your PHP server configuration file. Please do a search in Google and you will find the solutions.

  9. PirateKG says:

    I load your script… But price is not print!.. Dump $data return me next:

    400 Bad Request

    Bad Request
    Your browser sent a request that this server could not understand.

    why? pls, help me!

  10. PirateKG says:

    All right! I’s don’t work on local server ))

  11. cHeLLe says:

    Hi,

    I did try your code but all I can see is like this:

    Fedex Object
    (
    [server] => https://gatewaybeta.fedex.com/GatewayDC
    [accountNumber] => 311909061
    [meterNumber] => 101792519
    [carrierCode] => FDXE
    [dropoffType] => REGULARPICKUP
    [service] => PRIORITYOVERNIGHT
    [serviceName] => FedEx Priority Overnight
    [packaging] => YOURPACKAGING
    [weightUnits] => LBS
    [weight] => 17
    [originStateOrProvinceCode] => OH
    [originPostalCode] => 44333
    [originCountryCode] => US
    [destStateOrProvinceCode] => CA
    [destPostalCode] => 90210
    [destCountryCode] => US
    [payorType] => SENDER
    )

    I can’t see the price

    Please advice. Thanks. God Bless

  12. Arun Varghese says:

    Even I got the same issue………………… Please help……….

  13. Algirdas says:

    I have just tested my script and it is working as it should (http://www.varnagiris.net/wp-content/examples/fedex/)
    try to look at xml returned by the fedex server, maybe there are other errors which I’m not catching…

  14. arun says:

    Hello ……..

    This is my link…
    http://182.72.141.134/waterionizer/Fedex/?id=Fedex

    Please check this and advise… You can see that I am not getting the privce and when i printed $data in fedex.php

    It gets error also…. The same code wroks better in localhost….

  15. Sankar says:

    Hi Algirdas, I have been struggling for resolving the problem. My link also is not working : http://gro-via.com/Fedex/. Please kindly check and advise me. The same code is not working in localhost too.

    If you send your working code, it would be great helpful to me.

  16. Algirdas says:

    My code is the same as you can download from this page. So I believe there are differences in your server configuration. What are these differences I can’t say you

  17. hr61283 says:

    hi…arun..same here
    and all friends
    fedex services now changed..so this code is not working for me either….
    and couldn,find any solution on net also;

  18. Vogo says:

    Hi, All!

    Help please.

    If I go to https://www.fedex.com/ratefinder/home?cc=US&language=en&locId=express

    and then fill field

    zip code from = 90232
    zip code to = 90025
    weight = 100
    Pickup/Dropoff = -Schedule a pickup
    Ship date = Wed (2011.06.29)

    Press “get quote” and on the next screen select “Your packaging” – press “continue” I have fedex ground = 65.79 (Base = 52.78)

    And if I go to http://www.fedex.com/ratetools/RateToolsMain.do?link=2
    and on right hand “Get Rates by FedEx Zone” select this zones and download pdf file then I find that for 100 lbs – rate is 39.32 and is another then 65.79 or 52.78

    What is the difference?

  19. Vogo says:

    It seems, I understand,

    There is “Standard list” of rate will be receive, not “Retail Rates”
    That is the difference

    But how it possible to get “Retail Rates” via web service(?)

  20. yash says:

    This code is not working for any other country regarding US. Can anyone suggess any help.

  21. BeiGe says:

    It outputs this,can you help me?
    Fedex Object
    (
    [server] => https://gatewaybeta.fedex.com/GatewayDC
    [accountNumber] => 311909061
    [meterNumber] => 101792519
    [carrierCode] => FDXE
    [dropoffType] => REGULARPICKUP
    [service] => PRIORITYOVERNIGHT
    [serviceName] => FedEx Priority Overnight
    [packaging] => YOURPACKAGING
    [weightUnits] => LBS
    [weight] => 17
    [originStateOrProvinceCode] => OH
    [originPostalCode] => 44333
    [originCountryCode] => US
    [destStateOrProvinceCode] => CA
    [destPostalCode] => 90210
    [destCountryCode] => US
    [payorType] => SENDER
    )

  22. [...] am trying to get shipping quotes from FedEx. I found this library where it seems to be doing exactly what i want, but it’s not working (in the comments [...]

  23. YOGENDRA says:

    Fedex is not matching my cost as on website….Can anyone help me
    ?

  24. [...] am trying to get shipping quotes from FedEx. I found this library where it seems to be doing exactly what i want, but it’s not working (in the comments [...]

Leave a Reply