django-paypal icon indicating copy to clipboard operation
django-paypal copied to clipboard

Custom data got truncated

Open PetrDlouhy opened this issue 2 years ago • 4 comments

Recently I have got 4 payments where the IPN returned with truncated custom field. I did create the (unencrypted) form with data like:

 'custom': '{"user_plan_id": 310606, "plan_id": 1, "pricing_id": 1, "first_order_id": 43102, "user_email": "[email protected]"}

But i am receiving IPN with only ...&custom={&... in URL, so I can't pair the payment with the data in DB.

This would probably be error on side of PayPal, but also can be caused by some interaction with the form in browser on user's side (but it happened for 4 different users). I am creating this issue mainly because I want to ask if somebody has similar experience.

PetrDlouhy avatar May 03 '22 09:05 PetrDlouhy

I would not be at all surprised if PayPal mangled data like that. I would recommend doing base64 encoding to reduce the chances of your data getting mangled. You will still need to be careful of data length - don't expect PayPal to allow you to store much, or to be correct in what it advertises as the maximum length.

In general, see if you can reduce the amount of data in your custom field, which can be done using, for example, a single user ID or creating an "Orders" table, putting the data in there and sending only the order id in the custom field.

spookylukey avatar May 03 '22 10:05 spookylukey

@spookylukey Thank you very much for your reply. I will consider what you are writing.

But length or something in the custom string is not the problem here. Tens or hundreds of payments did pass just OK in few recent months I have been using this type of payment. There have been longer custon data strings than those that didn't pass and also there is nothing special in them (special characters etc.).

This problem did occur just in the last month only for few payments out of many.

PetrDlouhy avatar May 03 '22 10:05 PetrDlouhy

This problem did occur just in the last month only for few payments out of many.

That sounds about normal. There have been many such instances of PayPal's stuff mostly working, but just not working sometimes.

spookylukey avatar May 03 '22 10:05 spookylukey

When I originally implemented the custom field logic, I taught, it would be better to store more values for cases when I will need to identify some payment. I didn't think much about the length of that field, but according to documentation it is 255 characters, which I am far from reaching. Even my tests on sandbox don't show any problems with longer with long custom values, and if the 255 limit is reached, the payment would fail sooner, before it's creation.

In fact I only really need the Order ID, but PayPal leaves me only one character in the faulty cases, so I can't work with that.

Now I will try to use item_number field as fallback to store Order ID: https://github.com/PetrDlouhy/django-plans-paypal/commit/ca29ab332233ac1d02d91c5ba34b1612dd55f3bf

PetrDlouhy avatar May 11 '22 05:05 PetrDlouhy