2012-11-21 5 views
8

Wenn ich eine Benachrichtigung von Paypal erhalte, schicke ich sie zurück an Paypal, um sicherzugehen, dass es von Paypal ist. Der Code funktioniert gut, und ich habe kein Problem:rails paypal notify validate Japanese

# 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") 

Das Problem ist, wenn der Benutzer einen japanischen Namen hat. Die Anmeldung (von Paypal) empfangen wird, wie:

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

Wenn ich versuche, es zu Paypal zurückschicken (sicher sein, es von Paypal kam), ich habe diesen Fehler:

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

Es ist wie wenn RestClient "\ x8F \ xBC \ x8C \ xB4" nicht mag. Ich habe versucht, hinzuzufügen: content_type => "shift_jis" und auch "utf-8", aber ich habe immer diesen Fehler.

Wenn ich so etwas wie:

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

Dann ist mein RestClient.post zu Paypal senden, aber Paypal gibt einen Fehler zurück (INVALID) wahrscheinlich, weil Paypal wartet, um „\ X8F \ XBC \ x8C \ xB4 "und nicht" 松原 ".

Haben Sie eine Idee, wie ich das lösen kann?

edit: poste ich auch auf paypal forum

Antwort

9

Also ich denke, ich die Lösung. gehen

Im Verkäufer PayPal-Konto: Profil> Ich verkaufe Tools> PayPal-Button Sprachcodierung> Weitere Optionen

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

Jetzt kann ich bekommen "verified".