gpt4 book ai didi

ruby-on-rails - Ruby on Rails - 来自 Paypal 的参数 : invalid byte sequence in utf-8

转载 作者:太空宇宙 更新时间:2023-11-03 15:44:32 28 4
gpt4 key购买 nike

我正在关注 this tutorial to integrate Paypal到我的 Rails 应用程序,但 Hook 有问题。 Paypal 通过 POST 返回 url,但我一直有错误:

ArgumentError (invalid byte sequence in UTF-8):
app/controllers/purchases_controller.rb:24:in `hook'

这是我的钩子(Hook):

protect_from_forgery except: [:hook]
def hook
params.permit! # Permit all Paypal input params
status = params[:payment_status]
if status == "Completed"
@purchase = Purchase.find params[:invoice]
Line 24 --> @purchase.update_attributes notification_params: params, status: status, transaction_id: params[:txn_id], date: Time.now
end
render nothing: true
end

我尝试了多种解决方案,例如 notification_params: params.encoding(xxx)force_encode(xxx) 都没有成功。我不能使用 encode 或其他任何东西,因为 params 是 ActiveRecord::Parameters,而不是 String...

问题似乎是,在 Paypal 中我的名字是 "Stéphane" 但它返回 "St\xE9phane"

这是来自服务器的完整日志:

Started POST "/hook" for 127.0.0.1 at 2014-10-26 11:59:51 +0100
Processing by PurchasesController#hook as HTML
Parameters: {"mc_gross"=>"1.00", "invoice"=>"19", "protection_eligibility"=>"Eligible", "address_status"=>"unconfirmed", "payer_id"=>"FSXBUQDGG6KWN", "tax"=>"0.00", "address_street"=>"Av. de la Pelouse, 87648672 Mayet", "payment_date"=>"03:57:09 Oct 26, 2014 PDT", "payment_status"=>"Completed", "charset"=>"windows-1252", "address_zip"=>"75002", "first_name"=>"St\xE9phane", "mc_fee"=>"0.34", "address_country_code"=>"FR", "address_name"=>"St\xE9phane Xxxxx", "notify_version"=>"3.8", "custom"=>"", "payer_status"=>"verified", "business"=>"stephanexxxxx@gmail.com", "address_country"=>"France", "address_city"=>"Paris", "quantity"=>"1", "verify_sign"=>"AOLXbVgQrAtqa0Lllz6erhuaVkd-ADHLMH5k6uuEypyAZ7WCQUuOpfxY", "payer_email"=>"xxxxxxx@outlook.com", "txn_id"=>"5SD166511T176754U", "payment_type"=>"instant", "last_name"=>"Xxxxx", "address_state"=>"Alsace", "receiver_email"=>"stephanexxxxxxx@gmail.com", "payment_fee"=>"0.34", "receiver_id"=>"ZNER97N82WKY2", "txn_type"=>"web_accept", "item_name"=>"XXXX", "mc_currency"=>"USD", "item_number"=>"1", "residence_country"=>"FR", "test_ipn"=>"1", "handling_amount"=>"0.00", "transaction_subject"=>"", "payment_gross"=>"1.00", "shipping"=>"0.00", "ipn_track_id"=>"d4e0d603abd89"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" = 'da39a3ee5e6b4b0d3255bfef95601890afd80709' LIMIT 1
Purchase Load (0.2ms) SELECT "purchases".* FROM "purchases" WHERE "purchases"."id" = ? ORDER BY created_at DESC LIMIT 1 [["id", 19]]
(0.1ms) begin transaction
(0.1ms) rollback transaction
Completed 500 Internal Server Error in 11ms

ArgumentError (invalid byte sequence in UTF-8):
app/controllers/purchases_controller.rb:24:in `hook'

谢谢

最佳答案

经过更深入的搜索,我找到了正确的解决方案:https://stackoverflow.com/a/13504253/1805275

关于ruby-on-rails - Ruby on Rails - 来自 Paypal 的参数 : invalid byte sequence in utf-8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26572276/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com