PayPal Convertings Spaces in _cart Form to Plus Sign

荒凉一梦 提交于 2019-12-10 12:19:56

问题


Recently (starting March 2017), the _cart form integration with PayPal payments standard has started encoding spaces in all item info (names and options) to the plus sign (+). I verified this was happening in Chrome and added the enctype attribute to the form, which seemed to solve the issue for me. In Chrome and Firefox, I can send data to PayPal and spaces are preserved properly. Perhaps this is a fluke?

However, almost every customer that purchases is getting their info encoded improperly, which results in the IPN request not being able to verify the products they purchased.

The form:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="cmd" value="_cart"> 
<input type="hidden" name="upload" value="1"> 
<input type="hidden" name="business" value="name@example.com">
<input type="hidden" name="charset" value="utf-8">
<input type="hidden" name="item_name_1" value="Product With Spaces">
<input type="hidden" name="quantity_1" value="1"> 
<input type="hidden" name="amount_1" value="30.00">
<input type="hidden" name="on0_1" value="Name">
<input type="hidden" name="os0_1" value="First Last">
<input type="hidden" name="on1_1" value="Email">
<input type="hidden" name="os1_1" value="customer@example.com">
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" align="left" style="margin-right:7px; margin-top: 2px;">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

When submitted to PayPal, the product is shown as Product+With+Spaces and the name as First+Last. Thus the transaction record on PayPal and the IPN request have the incorrectly encoded data also.

I tried encoding the spaces as %20 or + (which would normally result in double-encoding, so I didn't expect it to help), but those literal characters were shown on PayPal.

I've read over the PayPal developer docs, and I seem to be using the most up-to-date fields and URLs. Also, this code has been running successfully for years without trouble.


回答1:


Solved! added the enctype="multipart/form-data" attribute to the paypal button form, return variables to ipn come back in same state as submitted



来源:https://stackoverflow.com/questions/43294703/paypal-convertings-spaces-in-cart-form-to-plus-sign

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!