Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Automated FedEx Labels


spoot

Recommended Posts

Some time in the next few days I'm going to look at getting a thermal printer working.

 

From the FEDEX API Manual:

 

Received from FedEx: 0,"121"33,"AA"1136,"XY"30,"XY AYZA"29,"470001338040"526,"0201"1402,"2.0"1419,"25.22"1416,"24.25"1417,".97"1090,"USD"1 089,"01552"1092,"5"65,"40048946120000014700013380402018"194,"THU"195,"EWR"409,"01JUN00" 431,"N"188,?
<Label Binary Data Stored Here>
?99,"" 
NOTE: Field 188 will contain the label data. In the next section we cover how to use this data buffer to print the FedEx shipping label. 

When a Ship a Package transaction is performed, the data necessary for producing a shipping label (and possibly a COD return label) is returned in one or more fields. The kind of label data returned depends on the printer type and format specified in your Ship request. Using buffer data to print PNG or Thermal labels The rule for encoding the PNG or thermal image in the returned label buffer was designed to eliminate certain illegal characters (byte values) by replacing them with an escape sequence. Those values that are not allowed include: NULL (0x00 hex) Double Quote (0x22 hex)

The percent character ?%? (0x25 hex) is used as the escape character, and therefore it must be replaced where it occurs naturally. Whenever a disallowed character or the escape character '%' is encountered, it is replaced by the escape character ?%? (0x25 hex) followed by two characters comprising the hexadecimal numeral representing the value of the character. 

For example, the NULL character (0x00 hex) is replaced by three characters: 
'%' (0x25) 
'0' (0x30) 
'0' (0x30) 

The percent character 0x25 is replaced by three characters: 
'%' (0x25) 
'2? (0x32) 
'5' (0x35) 

The algorithm for decoding the PNG image in the returned label buffer is as follows. Read bytes from the label field one at a time. When a byte read is not equal to the ?%? character (0x25 hex), pass it through unchanged. When a byte is read that is equal to the ?%? character (0x25 hex), read an additional two bytes, which will each take a value from ?0? (0x30 hex) through ?9? (0x39 hex) or ?A? (0x41 hex) through ?F? (0x46 hex). These two bytes are interpreted as a character representation of a two-digit hexadecimal numeral ranging from 0x00 through 0xFF. The single byte having the integral value represented by that numeral is appended to your output. For example, when the 3-byte string '%22' is encountered, ? ? ? (0x22) - the double quote character - is passed out. When the 3 bytes '%00' are read, the null character is written. In essence, the developer will need to take the data received from FedEx and store it in a buffer that has sufficient memory to hold the entire data stream. Once the data has been stored, the program might use a function similar to the one described below in order to parse the data in the buffer and extract only the PNG image data. From that point, the developers program must be able to call a print function to send the image to the laser printer. The following sample ?C? function illustrates how this is accomplished.



int create_fedex_ship_label(char *receive_buffer) { FILE *fedex_label; int c; int data_decoded = 0; int temp_label_counter; int label_data_found = 0; int result = 1; int load_label_data = 0; char data; char temp_label_buffer[20]; char label_file_name[20]= {?FedEx Label.png?}; char data_field_buffer[6]= {?188,?}; if((fedex_label = fopen(label_file_name, "wb")) == NULL) { return(1); } c = 0; while(data_decoded != 1) { data = receive_buffer[c]; if(data == '1') { temp_label_buffer[temp_label_counter] = data; temp_label_counter++; c++; data = receive_buffer[c]; if((data == '8') && (temp_label_buffer[0] == '1')) { temp_label_buffer[temp_label_counter] = data; temp_label_counter++; c++; data = receive_buffer[c]; } else { temp_label_counter = 0; } if((data == '8') && (temp_label_buffer[1] == '8')) { temp_label_buffer[temp_label_counter] = data; temp_label_counter++; c++; data = receive_buffer[c]; } else {
temp_label_counter = 0; } if((data == ',') && (temp_label_buffer[2] == '8')) { temp_label_buffer[temp_label_counter] = data; temp_label_counter++; c++; temp_label_buffer[temp_label_counter] = 0x00; label_data_found = 1; } else { temp_label_counter = 0; } } else c++; if(label_data_found) { result = strcmp(temp_label_buffer, data_field_buffer); if(result == 0) load_label_data = 1; data = receive_buffer[c]; } if(load_label_data) { data = '0'; c++; while(data != 0x22) { data = receive_buffer[c]; c++; if(data != '%') fprintf(fedex_label, "%c", data); if(data == '%') { for(e=0; e<2; e++) { data = receive_buffer[c]; c++; if(((data >= 0x30) && (data <= 0x39)) || ((data >= 0x41) && (data <= 0x46))) { if(e == 1) { d = data; d = d & 0x0f;
if((data >= 0x41) && (data <= 0x46)) d += 9; store = store | d; } else { d = data; d = d & 0x0f; if((data >= 0x41) && (data <= 0x46)) d += 9; store = d << 4; } } } fprintf(fedex_label, "%c", store); } } data_decoded = 1; } } fclose(fedex_label); return(0);

 

English? The data return needs to be sanitized for % and Null. I don't have a thermal printer handy but I'll try and convert this C code to PHP.

 

-Jason Potkanski

Electrawn GameVerse

Link to comment
Share on other sites

  • Replies 713
  • Created
  • Last Reply

Top Posters In This Topic

Hello. I was searching the internet when i ran into this forum. I am interested in integrating fedex shipping and tracking to my application. My question is where do I have to go to get this fedex shipping module. Thank. :)

Link to comment
Share on other sites

Okay so I'm getting the same error as mentioned in an earlier post but I can't figure out how to fix it. Here's the error:

This transaction could not be completed. Please note the error message

below.

 

ERROR: cURL ERROR: 60: error setting certificate verify locations

unable to process ship_ground

 

I know this relates to fedexdc.php file specifically to the variables at the top.

 

Here's what I've tried:

 

$server = 'production';

 

$request_referer = 'www.blackswanhome.com';

$request_referer = 'blackswanhome.com';

$request_referer = 'http://www.blackswanhome.com';

$request_referer = 'localhost';

 

I've tried all of these and still get the same error when I click on submit at the weight entry screen. Please help.

Link to comment
Share on other sites

If you're confused as to where to go after you've got the test labels working, here's some useful information from Federal Express:

 

Once you have finished developing your custom application, call FedEx Technical Support at 1-800-810-9073 from 7:00 am to 12:00 am Central Standard Time to initiate the testing and certification process. Within 5 to 10 minutes after speaking with FedEx Technical Support, you will receive, via e-mail, a set of test scripts. These are hypothetical shipping and tracking scenarios for FedEx Express and FedEx Ground services designed to make sure your application is fully compatible with FedEx systems before you go to the production environment. You must verify that your custom application can process these scripts appropriately.

 

To confirm the ability of your application to process the test scripts, you will need to send shipping labels to FedEx for certification. The test will ensure that the barcode on your labels can be processed and scanned by FedEx Operations. FedEx will evaluate the results of the test, a process that takes approximately 48 hours, and will then notify you of your application?s success or failure. If the test is successful, you will be considered certified to ship with WIS. When you are ready to go into production, call FedEx Technical Support and request to be setup in our production server environment. You can then begin to enjoy the rewards of seamlessly integrated FedEx Express shipping, tracking, and rating.

Link to comment
Share on other sites

I know this relates to fedexdc.php  file specifically to the variables at the top.

 

Are you sure? It's a cURL error, & the certificate location isn't related to those variables - I don't think it is, anyway... does the error change when you change those variables? Were you ever able to get labels from the FedEx test server?

 

At any rate -

 

$server variable should say 'test' or 'production', whichever is appropriate

 

$request_referer variable should say 'blackswanhome.com'

Link to comment
Share on other sites

I don't have a thermal printer handy but I'll try and convert this C code to PHP.

 

I've been trying to come up with a solution for this, & I've basically given up. My understanding is that we're trying to call a local printer with no user interaction - that is, we don't get a "print" dialog, we're just going to stream the print data from FedEx, across the server, to the thermal printer.

 

I asked the guy who wrote fedexdc.php how to do it, and he said, as if it were a walk in the park, "just open a pipe to the printer." I looked into this - but I don't see how it's done without significant client-side activity. My impression is that there would need to be a plug-in or applet or huge javascript that holds the printer data, calls the printer, & sends the data along.

 

Hopefully you aren't seeing the same stumbling blocks that I am, or you see them as much smaller than I do.

 

It's also possible to print the .png label to a thermal printer. My workaround solution is going to be to make a new label display template specifically for thermal printers, something that's easy to adjust & correct.

Link to comment
Share on other sites

Tracking Error:

 

I have successfully shipped a package and get the tracking info correctly if I go to fedex.com to track it or if I hit the track button from the OSC order page.

 

However, if I click on "track this shipment" as a customer on the order history page, "account_history_info.php",  (after logging in as a customer) I get the following error:

 

PACKAGE_ERRORFedEx Return Error 9982 : Invalid or missing Search Value.

 

Looks like it is using "track_fedex.php". What is wrong that I am getting this error?  Should I post my code for track_fedex.php?

 

Thanks,  Charlie

 

Charlie -

 

Rather than post track_fedex.php, could you post the URL you're at when you get the error 9982?

 

Thanks -

 

Michael

Link to comment
Share on other sites

1.  Fixing the cancel shipment so that it actually DOES cancel the shipment with Fedex?  Also there was a problem with the date format for cancelling shipments.  Anyone get that fixed?

 

I'll talk to FedEx sometime in the next few weeks & see what the story is with cancel not cancelling w/them. It should be working - if we don't get a "success" signal from their servers, we get an error, too.

 

Regarding the date format - I saw it, and was annoyed by it. But I just did a fresh install on a new site, and the date format error is gone. I'm really not sure what the story is, but with a clean install, it works.

 

 

2.  Automatically emailing the customer the tracking number when a label is generated.  I just generated a label to myself as the customer and the module didn't send me the tracking number via email.  It is in the comments section of the order, but no email.

 

This'll take a little bit of work, but it's on the list. Probably in the admin section there'll be the option to email or not email the customer.

Link to comment
Share on other sites

With regards to calling the 1-800 number for Fedex. I called them and had talked to a couple of people who had no idea what I was talking about in terms of the test/production server. Is there some sort of e-mail address that I can use so that I can get this automated fedex label contrib. up and running?

Link to comment
Share on other sites

Spoot, I was just wondering if you gave any more thought to the test label script. I mentioned it in the other thread before it got deleted. Any chance you are working on that? I ask only because my store is now live so hainvg to sit and make new customers for each transaction gets to be quite tedious.

 

Billy -

 

You're probably not around here anymore, but just so you know, I've started working on a test label script. It's way too involved - all those test scenarios, you know - but it'll make implementation much easier, I'm glad you brought it up.

 

Michael

Link to comment
Share on other sites

Hello there!

I got Certification Test Scenarions and heres an example:

So how can I put "Special Services" and "Other Info" to the system?

Im little bit confused

 

 

Did you ever figure out how to add the dry ice field? It is something I need to be able to do as well.

Link to comment
Share on other sites

Did you ever figure out how to add the dry ice field? It is something I need to be able to do as well.

 

There are so many fields that need to be available: dry ice, corrosives, a hold-at-address option, etc. I'm working on a test scenario script, & will use the opportunity to figure out how to get all these variables into the request & on the label. Please don't expect it terribly soon, but know I'm working on it.

 

Michael

Link to comment
Share on other sites

Does your program pass such information to the FedEx Label such as Reference #, Invoice #, etc.?

 

It doesn't currently pass this info, but there's room for it to do so. I believe the only way to add this to the application is to provide a field where you could add an invoice or reference number when requesting the shipment. It can't easily be automated, as different users will want to include different reference numbers; but it'd be easy to add a form field that allows user input of any pertinent number.

 

Michael

Link to comment
Share on other sites

Can someone send me a few screen shots of this?

Also, I have the FedEx module #1462 (Fedex1.php )

 

Why do I need another FedEx Meter # if I've obtained one for use with the above module?

 

 

You don't need another meter ID - this module uses the meter ID obtained by fedex realtime quotes (fedex1.php).

Link to comment
Share on other sites

Regarding certification.  FYI, If you already have a Fedex Shipping manager account where you can print labels by logging into Fedex.com, you don't need to go through the certification process for fedexdc.php because your account is already on the production server!  I just did it and sucessfully sent a package.

 

I'm currently working on an install for a client, and checked to see if this were true. According to FedEx, my client (who uses the online Ship Manager) is not on the production server:

 

your customer is currently using Fedex Ship Manager at FedEx.com which is a completely different shipping solution from FedEx Ship Manager API\Direct

 

But you're saying you just changed your settings to "production" & you could ship packages right away? It's worth a try...

Link to comment
Share on other sites

I'm currently working on an install for a client, and checked to see if this were true. According to FedEx, my client (who uses the online Ship Manager) is not on the production server:

 

your customer is currently using Fedex Ship Manager at FedEx.com which is a completely different shipping solution from FedEx Ship Manager API\Direct

 

But you're saying you just changed your settings to "production" & you could ship packages right away? It's worth a try...

 

It's true that if you have a meter id and use FedEx.com to make labels that you can use the same meter id and set to production for this contribution.

 

What happens is you generate a valid label complete with a real and unique tracking number *BUT* you aren't really on the production server and it won't schedule the pick-up.

Everything else seems to work fine, though. The tracking number works and the package is delivered properly.

Link to comment
Share on other sites

Does anyone know how to add "Signature Confirmation" as an option? I think it's something we can add to the ship_fedex.php file around line 490 or so where it builds the arrays for shipping options. If not, where does it go? Thanks in advance.

Link to comment
Share on other sites

There is one thing that we can see in all the time we have used this module.

By the Way thank you for writing it, The time saved in going back and forth with fed ex online is un believeable.

 

WE us both ground and express. I have looked at it several times and I thought I had almost got it once. I need a way to stop the program from writing anything other than home and ground shipments to the manifest.

 

As Fed Ex express does not require a paper manifest with shipment pickup.

 

Any thoughts on the subject would be welcome

If you choose not to decide you still have made a choice, I will choose a purpose clear, I will choose Free Will. --Neal Peart - Rush

Link to comment
Share on other sites

Hello everyone. I looked through the posts but didn't see an error message exactly like this one I'm getting.

 

Funny, it works great on my test server (home) but not on my real server (host).

 

When I click "ship" enter the weight I got an error message:

 

This transaction could not be completed. Please note the error message below.

 

ERROR: cURL ERROR: 60: error setting certificate verify locations: CAfile: /usr/share/curl/curl-ca-bundle.crt CApath: none

unable to process ship_ground

 

Everything else seems to be working fin and funny that it works on my home test server with my fake SSL.

 

Otherwise, WOW this mod is a great addition!

 

Thank you all for any support!

Link to comment
Share on other sites

Hello everyone.  I looked through the posts but didn't see an error message exactly like this one I'm getting.

 

Funny, it works great on my test server (home) but not on my real server (host).

 

When I click "ship" enter the weight I got an error message:

 

This transaction could not be completed. Please note the error message below.

 

ERROR: cURL ERROR: 60: error setting certificate verify locations: CAfile: /usr/share/curl/curl-ca-bundle.crt CApath: none

unable to process ship_ground

 

Everything else seems to be working fin and funny that it works on my home test server with my fake SSL.

 

Otherwise, WOW this mod is a great addition!

 

Thank you all for any support!

 

I could be mistaken about this but:

 

Look in Admin/Includes/fedexdc.php

 

Find these lines:

 

function _sendCurl() {

$ch = curl_init();

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_URL, $this->fedex_uri);

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

 

 

The Line:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

 

In the above group is probably still set to TRUE.

If it is change it to false.

 

Alot of systems seem not to be able to do a Curl Peer Verify.

 

Ususally Windows boxes with cUrl enabled PHP.

 

Try that fix and see what happens. Then keep it in mind for other contribs that use curl.

If you choose not to decide you still have made a choice, I will choose a purpose clear, I will choose Free Will. --Neal Peart - Rush

Link to comment
Share on other sites

I could be mistaken about this but:

 

Look in Admin/Includes/fedexdc.php

 

Find these lines:

 

        function _sendCurl() {

                $ch = curl_init();

                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

                curl_setopt($ch, CURLOPT_URL, $this->fedex_uri);

                curl_setopt($ch, CURLOPT_HEADER, 1);

                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

The Line:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

 

In the above group is probably still set to TRUE.

If it is change it to false.

 

Alot of systems seem not to be able to do a Curl Peer Verify.

 

Ususally Windows boxes with cUrl enabled PHP.

 

Try that fix and see what happens.  Then keep it in mind for other contribs that use curl.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...