レール7 |支払い成功後の ActionController::InvalidAuthenticityToken
概要
Easebuzz 経由で支払いゲートウェイを統合しました。これまでのところ、成功 URL は、orders#successE (ControllerName#MethodName) への POST リクエストです。支払いが成功した後、successE POST リクエストを呼び出すと、次の結果が得られます。
これはコードです:
def payE
@payment_response = Easebuzz::Payment.initiate({
"txnid" => "#{@order.id}",
"amount" => amount.to_f,
"firstname" => current_user.name,
"email" => current_user.email,
"phone" => current_user.phone_number,
"surl" => "http://localhost:3000/orders/#{@order.id}/successE",
"furl" => "http://localhost:3000/response.php",
"address1" => address,
"country" => "India",
#"zipcode" => "123123"
})
if @payment_response['status'] == 1
data = @payment_response['data']
redirect_to("https://testpay.easebuzz.in/pay/#{data}", allow_other_host: true, status: 303)
end
end
この問題はどうすれば解決できますか? :’)
誰か簡単な言葉で何が起こっているのか説明してもらえますか? CSRFトークンを検証しようとしていますが、検証できません nullが返されるから?私の脳に新しい知識を入れてください:-) 本当に感謝します!
解決策
外部アプリケーションからのコールバックはサポートしており、予期されたトークンを送信しないため、Ruby on Rails はこのコントローラー メソッドの信頼性トークンを検証できません。
この特定のコントローラー メソッドでのみ認証トークンを無効にするには、次のコードをコントローラーに追加します。
skip_before_action :verify_authenticity_token, only: [:successE]
Rails の RequestForgeryProtection について詳しく読んでください。