Reils paypal notify

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

+8
post ruby-on-rails encoding paypal
source share
1 answer

So, I think I have a solution.

In your paypal seller’s account, go to: Profile> My tools for sale> PayPal button language encoding> Advanced options

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

Encoding: Shift_JIS

Do you want to use the same encoding for data sent from PayPal (for example, IPN, downloadable magazines, emails)?

NO, use: UTF-8

Now I can get "VERIFIED".

+9
source share

All Articles