Ruby on Rails - parameters from Paypal: invalid byte sequence in utf-8

I am following this tutorial on integrating Paypal into my Rails application but I have a hook issue. Paypal is returning the URL to me via POST, but I have an error:

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

      

Here is my 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

      

I have tried several solutions like notification_params: params.encoding(xxx)

or force_encode(xxx)

without success. I cannot use encode

or anything else, because params is ActiveRecord::Parameters

, not String

...

The problem is that my name is in Paypal "Stéphane"

, but it returns "St\xE9phane"

.

Here is the complete log from the server:

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'

      

thank

+3


source to share


2 answers


After some more additional searches, I found the correct solution: fooobar.com/questions/679586 / ...



+1


source


After several attempts without any success, I decided to work around the problem. Since there is a text column across the database field, then I did to create a row of all my parameters. After that, I was able to save my row to the database column of the textbox.



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]
    parameters = String.new
    params.each do |key, value|
      parameters += key + " = " + value + " | "
    end

    @purchase.update_attributes notification_params: parameters, status: status, transaction_id: params[:txn_id], date: Time.now
  end

  render nothing: true
end

      

0


source







All Articles