rails paypal notify validate Japanese

时光总嘲笑我的痴心妄想 提交于 2019-12-22 04:47:08

问题


When I receive a notification from Paypal, I send it back to Paypal to be sure it is from Paypal. The code works well and I have no problem:

# payment_notifications_controller.rb # notification_validation, line 90
response = RestClient.post(PAYPAL_CONFIG["url_validate"], params.merge({"cmd" => "_notify-validate"}), :content_type => "application/x-www-form-urlencoded")

The problem is when the user has a Japanese name. The notification (from Paypal) received is like:

Parameters: {"last_name"=>"\x8F\xBC\x8C\xB4", "payment_cycle"=>"Daily", "next_payment_date"....

When I'm trying send it back to Paypal (to be sure it came from Paypal), I have this error:

ArgumentError (invalid byte sequence in UTF-8):
 app/controllers/payment_notifications_controller.rb:90::in `notification_validation'

It's like if RestClient doesn't like "\x8F\xBC\x8C\xB4". I tried to add :content_type => "shift_jis" and also "utf-8", but I always have this error.

If I do something like:

params[:last_name] = params[:last_name].encode("UTF-8", "Shift_JIS")
# now params[:last_name] is 松原

Then my RestClient.post is send to Paypal, but Paypal return an error (INVALID) probably because Paypal was waiting to get "\x8F\xBC\x8C\xB4" and not "松原".

Do you have any idea of how I can resolve that ?

edit: I also post on paypal forum


回答1:


So I think I have the solution.

In the seller paypal account go to : Profile > My selling tools > PayPal button language encoding > More options

Use the following drop-down menu to select the encoding used on your website.

Encoding: Shift_JIS

Do you want to use the same encoding for data sent from PayPal to you (e.g., IPN, downloadable logs, emails)?

NO, use: UTF-8

Now I'm able to get "VERIFIED".



来源:https://stackoverflow.com/questions/13488227/rails-paypal-notify-validate-japanese

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