Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails paypal notify validate Japanese

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

like image 648
dalf Avatar asked Nov 21 '12 07:11

dalf


1 Answers

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".

like image 130
dalf Avatar answered Oct 19 '22 18:10

dalf