Simple PHP Fedex & UPS shipping label form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jennysaur
    New Member
    • Sep 2007
    • 7

    Simple PHP Fedex & UPS shipping label form

    Hi Everyone,

    I'm new to PHP, and completely new to this website. I'm having a problem getting the PHP FedEx Web services software to work, and it seems overly complicated. I just need a simple form that will create a fedex shipping label, and hopefully UPS too. Any ideas of how I can accomplish this without losing my mind?
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    We don't write full codes for people here,Especially those who haven't written any codes themselves. What you have to do, first read the manuals that comes with the product. Then post any specific question that you getting. Thanks!

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, Jenny. Welcome to TSDN!

      What do you want your code to do? Give an example.
      What is your code doing that you don't want it to do? Give an example.
      What is your code *not* doing that it is supposed to? Give an example.

      Comment

      • Jennysaur
        New Member
        • Sep 2007
        • 7

        #4
        Hi Guys,

        I guess I'm not getting the php sample code that FedEx supplies. I talked to tech support, but they were stumped too. I'm basically trying to create a form that sends a request to FedEx that returns a shipping label, so my clients can ship their cellular devices to me for resale at no charge to them. FedEx and UPS tell me that this is possible, but so far I've had little luck getting it set up. Their code is lengthy and seemingly overcomplicated for what I would like to do. I would post it here, but it spans over several pages.

        Is anyone here familiar with FedEx integration, WSDL or the UPS API?

        Thanks for the help!

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, Jenny.

          Do you have a link to their API documentation?

          Comment

          • Jennysaur
            New Member
            • Sep 2007
            • 7

            #6
            Oddly enough the API doesn't come in php. Here is the site I got it from, however.


            The one I tried was Javascript.

            Comment

            • pbmods
              Recognized Expert Expert
              • Apr 2007
              • 5821

              #7
              Windows executables. Oh how nice. Why you would need to run an application to view sample code is beyond me.

              I had a LOT of fun with Avalara one time because their SDK is available to every flavor of Windows... and if you don't have PHP/Java Bridge installed on your Linux box, well, they were thinking about creating a PHP version of their SDK at some point in the future.

              In the end, I had to build my own custom SOAP client from the ground up, with certain... 'quirks' programmed into it that broke the standard but that Avalara's SOAP server was expecting.

              Yes, their SOAP server was built using Microsoft technologies; why do you ask? :P

              Over here in Mac land, I'm not able to open any of the files on the FedEx API code sample page, but you might find this document to be of some interest.

              Comment

              • Jennysaur
                New Member
                • Sep 2007
                • 7

                #8
                Thank you! I'll read through it all and see if I can't get this thang done.

                :)

                Comment

                • ak1dnar
                  Recognized Expert Top Contributor
                  • Jan 2007
                  • 1584

                  #9
                  Jenny,
                  The Original Poster of this thread is using such a application, but as I feel your one, not the same as he is using. anyway Its FedEx. try to PM him about your issue and find out weather he is having the sample codes. I think he Is familiar with the subject. Good luck.

                  Comment

                  • Jennysaur
                    New Member
                    • Sep 2007
                    • 7

                    #10
                    Thanks for the link. I tried fixing the same thing that was plaguing the other guy, but it didn't seem to have any effect. I've been still trying to get this figured out, and it's driving me batty! I spoke to tech services again, and they weren't php people, so they gave up after a few minutes. :(

                    Here's the line of code that's giving me trouble...

                    [PHP]<?php

                    // Copyright 2007, FedEx Corporation. All rights reserved.

                    chdir('..');

                    require_once('h ttp://photowitch.com/trade/library/fedex-common.php5');

                    $newline = "<br />";
                    ini_set("soap.w sdl_cache_enabl ed", "0");

                    $client = new soapClient("htt p://photowitch.com/trade/FDXEmailLabel.w sdl"); // replace with valid path to WSDL

                    $request['FDXEmailLabelR equest']['Authentication Detail'] = array('UserCred ential' => '2OqVvvsLDhZMSx nM'); // Replace 'XXX' with FedEx provided user credential
                    $request['FDXEmailLabelR equest']['ClientDetail'] = array('AccountN umber' => '510087585', 'MeterNumber' => '1194674'); // Replace 'XXX' with your account and meter number
                    $request['FDXEmailLabelR equest']['TransactionDet ail'] = array('Customer TransactionId' => '*** FDXEmailLabel Request using PHP ***');
                    $request['FDXEmailLabelR equest']['UrlDetail'] = array('Expirati onDate' => date('Y-m-d'),
                    'NotificationEM ailAddress' => '__MUNGED__',
                    'NotificationMe ssage' => 'notification message');
                    $request['FDXEmailLabelR equest']['MerchantPhoneN umber'] = '1234567890';
                    $request['FDXEmailLabelR equest']['DropoffType'] = 'REGULAR_PICKUP '; // valid values REGULAR_PICKUP, REQUEST_COURIER , ...
                    $request['FDXEmailLabelR equest']['ServiceType'] = 'FEDEX_GROUND'; // valid values STANDARD_OVERNI GHT, PRIORITY_OVERNI GHT, FEDEX_GROUND, ...
                    $request['FDXEmailLabelR equest']['PackagingType'] = 'YOUR_PACKAGING '; // valid values FEDEX_BOK, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ...
                    $request['FDXEmailLabelR equest']['Origin'] = array('Contact' => array('PersonNa me' => 'Sender Name',
                    'CompanyName' => 'Sender Company Name',
                    'PhoneNumber' => '1234567890'),
                    'Address' => array('StreetLi nes' => array('Address Line 1'),
                    'City' => 'Edenwold',
                    'StateOrProvinc eCode' => 'TN',
                    'PostalCode' => '37115',
                    'CountryCode' => 'US',
                    'Residential' => 1));
                    $request['FDXEmailLabelR equest']['Destination'] = array('Contact' => array('PersonNa me' => 'Recipient Name',
                    'CompanyName' => 'Recipient Company Name',
                    'PhoneNumber' => '1234567890'),
                    'Address' => array('StreetLi nes' => array('Address Line 1'),
                    'City' => 'Austin',
                    'StateOrProvinc eCode' => 'TX',
                    'PostalCode' => '73301',
                    'CountryCode' => 'US',
                    'Residential' => 1));
                    $request['FDXEmailLabelR equest']['Payment'] = array('PaymentT ype' => 'SENDER',
                    'Payor' => array('AccountN umber' => '394511420',
                    'CountryCode' => 'US'));
                    $request['FDXEmailLabelR equest']['Rma'] = '11_TC01_S80PT3 _POS';
                    $request['FDXEmailLabelR equest']['SpecialService Detail'] = array('EMailNot ification' => array('Personal Message' => 'Email Notification Personal Message',
                    'Recipients' => array('0' => array('EMailNot ificationRecipi entType' => 'RECIPIENT',
                    'EMailAddress' => '__MUNGED__'))) );
                    $request['FDXEmailLabelR equest']['Packages'] = array('0' => array('InsuredV alue' => array('Amount' => 999.0,
                    'Currency' => 'USD'),
                    'ItemDescriptio n' => 'Item Description',
                    'Weight' => array('Value' => 51.0,
                    'Units' => 'LB'),
                    'Dimensions' => array('Length' => 88,
                    'Width' => 5,
                    'Height' => 5,
                    'Units' => 'IN'),
                    'DryIceWeight' => array('Value' => 10.0,
                    'Units' => 'KG'),
                    'CustomerRefere nce' => 'Customer Reference'));
                    try
                    {
                    $response = $client ->__SoapCall("FD XEmailLabel", array('paramete rs' => $request));

                    if ($response -> FDXEmailLabelRe ply -> HighestSeverity != 'FAILURE' && $response -> FDXEmailLabelRe ply -> HighestSeverity != 'ERROR')
                    {
                    printRequestRes ponse($client);
                    }
                    else
                    {
                    echo 'Error in processing transaction.'. $newline. $newline;
                    foreach ($response -> FDXEmailLabelRe ply -> Notifications as $notification)
                    {
                    echo $notification . $newline;
                    }
                    }

                    writeToLog($cli ent); // Write to log file

                    } catch (SoapFault $exception) {
                    printFault($exc eption, $client);
                    }

                    ?>[/PHP]

                    and this is the error i'm getting:

                    Parse error: parse error, unexpected '{' in /home/content/P/h/o/Photowitch/html/trade/FDXEmailLabel.p hp on line 62

                    Thanks, everyone...I really appreciate the help.
                    Last edited by pbmods; Sep 28 '07, 02:35 AM. Reason: Removed email address.

                    Comment

                    • pbmods
                      Recognized Expert Expert
                      • Apr 2007
                      • 5821

                      #11
                      Heya, Jenny.

                      For your protection, I removed your email address from your post.

                      I downloaded and ran a syntax check on the code that you provided, and PHP reported no syntax errors.

                      Are you sure that the problem is with the code that you posted? What version of PHP are you running?

                      Comment

                      • Jennysaur
                        New Member
                        • Sep 2007
                        • 7

                        #12
                        Hey thanks, I didn't realize that the email addy was in there. :)

                        I just called GoDaddy, and I'm working on PHP5. So as far as I know, thats not the problem...

                        Thanks!

                        Comment

                        • pbmods
                          Recognized Expert Expert
                          • Apr 2007
                          • 5821

                          #13
                          Heya, Jenny.

                          Hm....

                          What if you put the curly brace on the same line as the try?

                          In other words, change this:
                          [code=php]
                          try
                          {
                          [/code]

                          to this:
                          [code=php]
                          try {
                          [/code]

                          I feel like I'm grasping at straws here, but I vaguely remember something similar happening before, and removing the newline did fix it. For some reason.

                          Comment

                          • Jennysaur
                            New Member
                            • Sep 2007
                            • 7

                            #14
                            Hello Again,

                            So i figured out part of the problem...i had to name the actual file with the .php5 extension. Now i'm getting a different error:

                            Fatal error: Call to undefined function printFault() in /home/content/P/h/o/Photowitch/html/trade/FDXEmailLabel.p hp5 on line 81

                            Any ideas?

                            Comment

                            Working...