When I receive a notification from Paypal, I send it back to Paypal to make 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 that the user has a Japanese name. The notification received (from Paypal) is as follows:
Parameters: {"last_name"=>"\x8F\xBC\x8C\xB4", "payment_cycle"=>"Daily", "next_payment_date"....
When I try to send it back to Paypal (to make 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 RestClient doesn't like "\ x8F \ xBC \ x8C \ xB4". I tried adding: content_type => "shift_jis" as well as "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 sent to Paypal, but Paypal returns an error (INVALID), probably because Paypal expected to get "\ x8F \ xBC \ x8C \ xB4" and not "ζΎε".
Do you have any idea how I can solve this?
edit: I also post on the PayPal forum
post ruby-on-rails encoding paypal
dalf
source share