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