Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

PayPal Automated Labels, Support Thread


natrium42

Recommended Posts

Support thread for PayPal Automated Labels Mod

 

PayPal Automated Labels Canada 1.0

==================================

 

Original Author: Alexei Karpenko

Initial Release: 2009-08-13

 

Features

========

 

- Ships Light Packets Air electronically via Canada Post using PayPal shipping

- Also ships via other methods available with Canada Post through PayPal

- Returns GIF file from PayPal server with the label to print

- Adds description for customs for each product

- Adds Harmonization/Tariff code for each product

- Adds country of manufacture to each manufacturer

- Proper invoice for customs

 

Change Log

====================

 

Version 1.0 (2009-08-13)

- initial release with Canada Post support

 

Introduction by the original author

===================================

 

This modification allows to ship an order electronically by submitting data to

PayPal server which then returns a GIF file with a label that should be placed

onto the package. Most of the information is automatically filled out given the

order data.

 

This is especially useful to Canadians as Canada Post does not provide any API

to electronically ship Light Packets Air. It's very time consuming to ship them

in person at the local postal outlet. Luckily, PayPal allows to ship those via

Canada Post electronically.

 

What this modification does is pretend to be a human. It goes to the PayPal site

and traverses it filling in all the fields like a human would. That's all done

with PHP and Curl magic.

 

Screenshot included in the package.

 

Requirements

============

 

- Canadian PayPal account

- Mod tested with PHP5, Curl

Edited by natrium42
Link to comment
Share on other sites

Hey Alexei,

I'm getting a failed sanity check at step two in the second part of the process from what I can see.

 

https://www.paypal.com/ca/cgi-bin/webscr?cm...15521baa3d60b80

 

HTTP/1.1 200 OK

Date: Fri, 21 Aug 2009 20:46:51 GMT

Server: Apache

Set-Cookie: login_email=%3cMYSITE%40MYHOST.ca%3e; expires=Wed, 17-Feb-2010 20:46:52 GMT; domain=.paypal.com; path=/

Set-Cookie: navlns=0; expires=Thu, 16-Aug-2029 20:46:52 GMT; domain=.paypal.com; path=/

Set-Cookie: pNTcMTtQfrJuaJiwEnWXQ6yNxfq=2CCIyH2m2cCfJBaHr-NwfoVbYkic4ktOphW86LvV3RCLej8eaGLa9_0ou55uo6Are9h8q6fReYWb2EByD8hwGCjjZGZygjVlng

1Re-b5C0rTVpBiiuSnlcsB_wLjPftHpqpH-PS7BSiKGSd7IZU2Xd2krhy5wSjYg05uu2iC-db5FdAoTySfDC33vB6FG7FotSwBMq4Km6QbFNBpBniK5UPXwp8ax8UlE6e5NkX4tywi86iVfow0JRpwB

dvXmgHJHY3K4iyM-PLZT5azDrMjNjZLSFY_D6GTo7JXZyuEDaohhuKG4jbivk7hwATL-GX37cqAe-00KCuK2rN7k5wAfXy5I82JZ6xoP0lSUiNIdo4h2ani; domain=.paypal.com; path=/

Set-Cookie: feel_cookie=a%205%20_flow%20b%209%20_ship-now%20c%206%20webscr%20d%206%20webscr%20e%2026%20Customer%2fgeneral%2fAbort.xsl%20f%2026%20Customer%2fgeneral%2fLogin.xsl%20g%205%20en_US%20h%205%20en_US%20i%2026%20xpt%2fCustomer%2fgeneral%2fAbort%20j%2011%20p%2fgen%2flogin%20k%2023%20Page%20Not%20Found%20-%20PayPal%20l%2023%20Page%20Not%20Found%20-%20PayPal%20; expires=Wed, 31-Dec-1969 23:59:59 GMT; domain=.paypal.com; path=/

Set-Cookie: Apache=10.191.114.16.1250887611890216; path=/; expires=Thu, 09-Jul-03 14:18:35 GMT

Vary: Accept-Encoding

Transfer-Encoding: chunked

Content-Type: text/html; charset=UTF-8

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<!--

Script info: script: webscr, cmd: _flow, template: xpt/Customer/general/Abort, date: Aug. 20, 2009 02:43:39 PDT; country: CA, language: en_US, xslt server:

web version: 59.0-1026427 branch: AHOD_590_0820_int

content version: -

pexml version: 59.0-1023115

page XSL: Customer/default/en_US/general/Abort.xsl

hostname : FwD-B3L0GIZo-EM8MGmhQ3jm8UgvvrkfKj9eQU6FoMo

rlogid : FwD%2bB3L0GIZo%2bEM8MGmhQ%2bsarfx02bgP%2fn2cDmT7iCXWCwDqIIrE8g%3d%3d_1233eb63674

-->

<title>Online Payment, Merchant Account - PayPal</title>

<!--googleoff: all-->

<meta name="description" content="PayPal is the safer, easier way to pay online without revealing your credit card number.">

<!--googleon: all-->

<link media="screen" rel="stylesheet" type="text/css" href="https://www.paypalobjects.com/WEBSCR-590-20090814-1/css/core/global.css">

<!--[if IE 7]><link media="screen" rel="stylesheet" type="text/css" href="https://www.paypalobjects.com/WEBSCR-590-20090814-1/css/browsers/ie7.css"><![endif]-->

 

<!--[if lte IE 6]><link media="screen" rel="stylesheet" type="text/css" href="https://www.paypalobjects.com/WEBSCR-590-20090814-1/css/browsers/ie6.css"><![endif]-->

<link media="print" rel="stylesheet" type="text/css" href="https://www.paypalobjects.com/WEBSCR-590-20090814-1/css/core/print.css">

<style type="text/css">

div.abort div.layout1 {margin:0; background:#fff url(/en_US/i/scr/blue_white_gray_gradient.jpg) bottom center repeat-x}

div.abort div.layout1 .messageBox.notification {margin-bottom:0; padding:5px 40px 15px 70px; border:1px solid #ccc; background-position:20px 20px; background-color:transparent}</style>

<script type="text/javascript">

if (parent.frames.length > 0){

top.location.replace(document.location);

}</script><script type="text/javascript" src="https://www.paypalobjects.com/WEBSCR-590-20090814-1/js/lib/min/global.js"></script><link rel="shortcut icon" href="https://www.paypalobjects.com/WEBSCR-590-20090814-1/en_US/i/icon/pp_favicon_x.ico">

<link rel="apple-touch-icon" href="https://www.paypalobjects.com/WEBSCR-590-20090814-1/en_US/i/pui/apple-touch-icon.png">

</head>

<body>

<noscript><p class="nonjsAlert">NOTE: Many features on the PayPal Web site require Javascript and cookies. You can enable both via your browser's preference settings.</p></noscript>

<div class="abort" id="page">

<div id="header" class="std"> .....<h1>Sorry — your last action could not be completed</h1>....

 

 

I've tried changing the <title> to the french title of the paypal site without success.

 

I believe that I am getting pass the first sanity check

 

Any idea???

Link to comment
Share on other sites

I seem to be encountering an error upon completion of the form:

 

Step 1. Initializing

Step 2. Logging in

Step 3. Changing country

Step 4. Entering address

Step 5. Filling out form for customs

2006 - MySQL server has gone away

 

SELECT op.orders_products_id, op.products_name, op.products_model, op.products_price, op.products_tax, op.products_quantity, op.final_price, op.products_id, p.products_tax_class_id, p.products_weight, p.products_description_short, p.products_tariff, p.manufacturers_id FROM orders_products op LEFT JOIN products p ON op.products_id = p.products_id WHERE orders_id = '106975'

 

[TEP STOP]

 

 

I'm on a dedicated server, this happens even when there's hardly any traffic. Any ideas what could be causing this?

Link to comment
Share on other sites

I seem to be encountering an error upon completion of the form:

I'm on a dedicated server, this happens even when there's hardly any traffic. Any ideas what could be causing this?

Sounds like the database connection is timing out while the script communicates with PayPal. Try adding tep_db_connect(); like so:

  tep_db_connect();

 ////
 // 5. ENTER CUSTOMS INFORMATION

Link to comment
Share on other sites

That seemed to have worked, thanks!

 

Is there any underlying problem I should look for that would have initially caused my problem, or is this typical for communicating with PayPal in this fashion?

 

 

Is it possible to have the label print in .pdf instead of gif?

I seem to have to open it up in photoshop to scale to 8x10 size. The gif is scaled at 1426x2004 pixels

Link to comment
Share on other sites

Is there any underlying problem I should look for that would have initially caused my problem, or is this typical for communicating with PayPal in this fashion?

Nah, it's just that the transactions with PayPal seem to take longer than your wait_timeout variable in MySQL settings.

Is it possible to have the label print in .pdf instead of gif?

I seem to have to open it up in photoshop to scale to 8x10 size. The gif is scaled at 1426x2004 pixels

PayPal returns the labels in GIF format, however it's possible to turn it into PDF. I can add this to the next version. Right now I am using Firefox with a 1200 pixel high screen which results in 50% scaling of the GIF image. It's just the right size when printed on Letter format. I have also disabled headers and footers in page setup. But you're right, PDF would be easier.

Link to comment
Share on other sites

Thanks for the links. I'm not certain I could switch the coding from gif to pdf, as I'm not quite that experienced in php yet so I look forward to the future version.

 

 

Have you been shipping with Canada Post via PayPal for a while? The shipping labels look a bit different from the ones I print off through the Online business Center at CP's website. Those have my Venture One ID in the "Postage Paid" field (normally where a stamp would go), but these just say "PREPAID".

 

How does Canada Post verify these are actually paid for? I asked the guy at the post office and he says these forms he's seen before, but they make no sense - it's easy for anyone to fabricate.

 

I tried to ask PayPal about this but they won't respond to that particular inquiry for some reason. I have no intent on defrauding Canada Post (my online business is dead without their service), I just don't want them sending any of these back for any reason is all. :)

 

 

I will try resizing my screen to 1200, thanks for that tip.

Link to comment
Share on other sites

Well, it has eBay and some number on it. I think it's mostly based on a trust system anyway, as there are no bar codes for regular airmail (a choice Canada Post could easily change if they wanted). Many eBay sellers ship via eBay/PayPal, so I don't think there should be any problems.

 

I myself use this mod only for Light Packets, as you cannot ship them electronically any other way -- the only option is going to a postal outlet in person. eShipper gives me better rates on Expedited and Xpresspost than my Canada Post business account (which is better than VentureOne), so I use it for those methods. My Canada Post business account is only used for Small Packets Air these days (as eShipper doesn't offer that method)....

Link to comment
Share on other sites

I noticed that number beneath the "eBay" logo in the bottom too, I suppose that could probably some internal verification #.

 

 

Speaking of light packets, are they not available in Canada through PayPal?

For -any- Canadian order, it doesn't show up in the pull-down menu for this script, and neither on PayPal's site.

For any US order though, that pull down is present.

 

 

eshipper is definitely better for the bigger packages, but watch out for Purolator. A few of my packages got hit with a $4.00 "surcharge" because Purolator didn't like how I packed. (A large manilla envelope re-enforced with tape, the contents were not big enough to put in a box, but too valuable to ship Canada Post) I ship the same type of parcels through UPS and never got hit with any surcharge for this reason.

Link to comment
Share on other sites

Canada Post is a joke and a half. I was hoping that was some sort of overlook by Paypal. :)

 

 

I notice they now have the "if it fits it ships" boxes similar to USPS, but they start at $9.99 postage. In the US, last I checked, those boxes started at $4.95 for 3-5 day domestic delivery.

 

 

 

I'll try this script out a bit and I will definitely be making a donation. I would have paid for a script like this. It's going to save so much time at Christmas!

Hopefully Paypal releases an API for the shipping area though, I imagine doing updates for this will be a nightmare if they change the pages around.

Link to comment
Share on other sites

Doing some testing:

 

I still get the occasional "Mysql has gone away" error, but when I try again on a different purchase it usually doesn't happen 2 times in a row. Is there anything else I can do to circumvent this 100% of the time? Would it make sense to edit any server minimums, and if so, which do you recommend?

 

To try and lessen the queries, I removed the JOIN and made the product_weight field come directly from the orders table, instead of querying the part of the database that holds every product. Didn't seem to lessen the speed.

 

 

 

Also, what does the "Failed sanity check" mean?

For most orders, the label either prints or I get an Mysql Gone away error. For a particular order (over 6 items) I keep getting this error.

 

 

 

Final question.

Not sure if I am correct or not (there's a lot of code in this contribution), but my understanding is: the input forms are not used to generate the label?

Since ship_paypal.php loads lightning fast.. could I gain speed and thwart the Mysql gone away error by passing that form data from ship_paypal.php to PayPal, instead of doing another query for the same info?

 

I tried to tick the "Customize Shipment" option.

When I do that, I get:

Step 1. Initializing

Step 2. Logging in

Step 3. Changing country

Step 4. Entering address

Step 5. Filling out form for customs

Error: There are no Item details given. There must be atleast one valid entry.

Link to comment
Share on other sites

I still get the occasional "Mysql has gone away" error

The new version should fix this... there was another spot to put tep_db_connect()...

Also, what does the "Failed sanity check" mean?

That's when the response from PayPal is unexpected. For example if something went wrong or if PayPal changed their site.

Not sure if I am correct or not (there's a lot of code in this contribution), but my understanding is: the input forms are not used to generate the label?

Since ship_paypal.php loads lightning fast.. could I gain speed and thwart the Mysql gone away error by passing that form data from ship_paypal.php to PayPal, instead of doing another query for the same info?

 

I tried to tick the "Customize Shipment" option.

When I do that, I get:

Step 1. Initializing

Step 2. Logging in

Step 3. Changing country

Step 4. Entering address

Step 5. Filling out form for customs

Error: There are no Item details given. There must be atleast one valid entry.

You are correct: the input form is only used if you check the "Customize Shipment" button -- otherwise the order info is taken from the database. This error should only happen if the entire form is empty. Is this the case? If it's not empty and you still get this error, then there is some bug in the code... So let me know and I will look into it. It seems to work over here (Firefox browser).

Link to comment
Share on other sites

Just tried out the latest version.

 

This time around, I only got Mysql went away once out of 3 packages I tried. I was clicking around in hotmail when that error occured. Once I sat and waited for the label to show, I did not get that error a 2nd time.

 

 

 

Still, when I click "Customize shipment" I get the error that the fields are blank. I added a bit of code in so I didn't have to use the products_short_desc field (It would be a pain to go through all of my products to add a shortened field). Can you take a look at my code and see if this is why I keep getthing the error?

in admin/ship_products.php:

FIND:

$products_weight = sprintf("%01.3f", $products_weight);

 

 

ADD BELOW:

$str = $orders_products['products_name'];

$str_Pattern = '/[^ ]*$/';

preg_match($str_Pattern, $str, $results);

if ($results[0] =='Widget'){

$item_country = 'MX';

}elseif($results[0] =='Widget1'){

$item_country = 'UK';

}elseif($results[0] =='Widget2'){

$item_country = 'IT';

}elseif($results[0] =='Widget3'){

$item_country = 'US';

}else{

$item_country = 'CN';

}

 

 

 

FIND:

 

$query_string .='&item_desc'.$index.'=' . urlencode(utf8_encode(substr($orders_products['products_description_short'], 0, 30)))

. '&item_origin'.$index.'=' . urlencode($countries['countries_iso_code_2'])

 

 

CHANGE TO:

 

$query_string .='&item_desc'.$index.'=' . urlencode(utf8_encode($results[0]))

. '&item_origin'.$index.'=' . urlencode($item_country)

 

 

 

And for 1 shipment, I tried to change the pull-down (Reason for Export:) to "Other" and I got this:

Step 1. Initializing

Step 2. Logging in

Step 3. Changing country

Step 4. Entering address

Step 5. Filling out form for customs

Error in field category_item_text: When selecting

When I tried again and left it at default, the label printed.

 

 

And lastly, I cannot get the Optional Fields to pass onto my label. It would be ideal for them to show up on Canada Post's site, so when the Parcel ID is searched via the tracking # field, the person's order #, last name & zipcode show (to comply with PayPal's seller protection policy) ... right now, the default showing is this:

Track Status

 

Product Type: USA Letterpost

2009/08/25 06:54 MISSISSAUGA An order has been electronically submitted

via OBC i can get their order #, name & postal code to show beneath the "Product Type" field by entering those in the reference # boxes.

 

Forgot to mention, I Have register_globals disabled on my server. Could this be the reason no info is passing from the "Customize" from?

Edited by eww
Link to comment
Share on other sites

Try replacing "$HTTP_POST_VARS[$var];" with "$_POST[$var];" in admin/includes/functions/ship_paypal.php

This might fix the variables not transmitted to the next step issue with register_globals off.

 

I am not sure why your MySQL server goes away so quickly... You might want to sprinkle in more of the connect calls, for example before each single MySQL query... Or you could look into increasing the timeout.

 

For Optional Fields, I don't seem to find them on the PayPal ship site. Could you describe where they are? Or you could even copy them out of the source code and then I can take a look.

 

Perhaps sellers insurance only works if you ship a particular order made via PayPal. This mod doesn't actually care how the customer paid, so there is this disconnection between payment and shipment.

Link to comment
Share on other sites

the register_globals patch I have already translates HTTP_POST_VARS to _POST so that shouldn't be any issue. Is there any other reason my form data wouldn't be passed?

 

Or you could look into increasing the timeout.

What would be reasonable for this mod? (what do you use?)

Presently, mine is:

 

wait_timeout=30

connect_timeout=10

 

 

For Optional Fields, I don't seem to find them on the PayPal ship site.

I just checked and I cannot find them, that's bizarre. On Canada Post's OBC site, they're labled:

referenceNumber

costCentreRef

 

I've never actually shipped anything through PayPal directly (just through your add-on). Do they even use these fields?

... these fields are on the pdf printout from your contribution, though. (They're blank, even if I enter data into these sections on ship_paypal.php)

 

Perhaps sellers insurance only works if you ship a particular order made via PayPal. This mod doesn't actually care how the customer paid, so there is this disconnection between payment and shipment.

No, I mean when there is a chargeback for an item, PayPal insists a tracking number that showcases a postal code and signatory name could greatly help your recourse.

Anytime I've had a chargeback for merch shipped via Canada Post Expedited, I always won the chargeback because I push the customer's order # (which is also on the PayPal order page), their first initial, last name & delivery postal code to the tracking details.

I also do the same for purchases via money order and Alertpay, so for that section it doesn't really matter how it was paid for, because it's a field Canada Post offers by default through the obc.canadapost.ca website.

 

 

I've searched around Paypal and haven't found any API to make this mod easier to configure for fields like this. Is this strictly pushed at ebay stores or something? They've got API's for everything else, I wonder why they wouldn't offer one for shipping, too.

Edited by eww
Link to comment
Share on other sites

Wow, that's quite the difference. I'll up it to 28800 and see how that goes.

 

Will these connections terminate after the script finishes, or after they age 8 hours?

I notice for the labels that do pass without any qualms, if server load is high I can get some heavy swap usage and I've got extra ram on my server.

Link to comment
Share on other sites

  • 2 weeks later...

after some testing and modifying my server bits, the sql error seems to have disappeared.

 

i have a few more questions:

Step 1. Initializing

Step 2. Logging in

Step 3. Changing country

Step 4. Entering address

Step 5. Filling out form for customs

Step 6. Paying

Step 7. Getting shipping label

Step 8. Notifying customer

Step 9. Success!

 

Shipping Price: $8.90 CAD

Tracking Number:

Label: Open GIF Open PDF

 

where can i modify the contents of this email?

 

 

 

also, is it possible to pass the parcel id into the order comments? right now i'm doing that manually and it's a bit tedious for a large number of parcels.

 

and lastly, when i review the customer's order page in admin after shipping a parcel this way, the order comments are as follows;

Date Added Customer Notified Status Comments

09/14/2009 22:41:37 True Processing Order shipped.

 

 

"Processing" is status #4, in ship_paypal.php my setting is as follows:

// Order status to set when order shipped

define('PAYPAL_ORDER_STATUS_SHIPPED', 3);

 

 

now, oddly enough, when i search the customer's order history, the status says "shipped" ... do i also have to edit something in the order_status_history table for the correct status name to show?

Link to comment
Share on other sites

where can i modify the contents of this email?

See the variable $email_txt in admin/ship_paypal.php

 

 

also, is it possible to pass the parcel id into the order comments? right now i'm doing that manually and it's a bit tedious for a large number of parcels.

The tracking number isn't actually returned by PayPal. You could route PayPal emails to a script that would parse out the tracking number and add into osC. Another way would be to add functions to check the shipping history in PayPal and parse out the tracking numbers. Both ways aren't really smooth, so I decided against including them, as I only use the module for light packets myself.

 

now, oddly enough, when i search the customer's order history, the status says "shipped" ... do i also have to edit something in the order_status_history table for the correct status name to show?

Whoops, it's a bug. Here is the fix:

 

// change the following line in admin/ship_paypal.php
 tep_db_query("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (orders_id, orders_status_id, date_added, customer_notified, comments) values ('" . $order_id . "', '4', now(), '" . $customer_notified . "', '" . $status_comments  . "')");
// to
 tep_db_query("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (orders_id, orders_status_id, date_added, customer_notified, comments) values ('" . $order_id . "', '" . tep_db_input(PAYPAL_ORDER_STATUS_SHIPPED) . "', now(), '" . $customer_notified . "', '" . $status_comments  . "')");

Link to comment
Share on other sites

  • 1 month later...

thanks for that!

 

do you still run your website? i went to go donate (would have done it sooner, but it actually slipped my mind as i came upon personal issues) .. and your website simply read "under construction" (just making sure you still own that email address)

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...