2017-01-22 11 views
2

Mollie API를 설치하려고하지만 Webhook이 작동하지 않습니다. Ruby on Rails 4에서 작업 중입니다. 계속해서 말합니다. CSRF 토큰 독자성을 확인할 수 없습니다.. 내가 stackoverflow에서 여러 답변을했지만 그들은 작동하지 않습니다. 예 :CSRF 토큰 인증을 확인할 수 없음

  • skip_before_filter :
  • protect_from_forgery 제외 verify_authenticity_token : [: 알릴]와
  • protect_from_forgery : null_session, 경우 : -> {?} request.format.json

하는 내 통지 제어기 모양은 다음과 같습니다.

class ReservationsController < ApplicationController 
    before_action :authenticate_user!, except: [:notify] 

    skip_before_filter :verify_authenticity_token 

    def preload 
     training = Training.find(params[:training_id]) 
     today = Date.today 
     reservations = training.reservations.where("date >= ?", today) 

     render json: reservations 
    end 

    def create 



     @thrill = Thrill.find(params[:thrill_id]) 
     if @thrill.reservations.length < @thrill.training.tr_max_attendants 
      @reservation = current_user.reservations.create(reservation_params) 

      if @reservation 

       require 'Mollie/API/Client' 

       mollie = Mollie::API::Client.new('test_gUejkz43UkdeCauC22J6UNqqVRdpwW') 

       payment = mollie.payments.create(
        amount: 10.00, 
        description: 'My first API payment', 
        redirect_Url: 'http://d7459af1.ngrok.io/your_trips', 
        webhookUrl: 'http://d7459af1.ngrok.io/notify', 
        metadata: { 
         reservationid: @reservation.id 
        } 
       ) 



       @reservation.update_attributes payid:payment.id 

       redirect_to payment.payment_url 


      else 
       redirect_to @thrill.training, notice: "Helaas, de training is vol" 
      end 
     end 
    end 

    protect_from_forgery except: [:notify] 
# protect_from_forgery with: :null_session, if: -> {request.format.json?} 

    def notify 

     require 'Mollie/API/Client' 

     mollie = Mollie::API::Client.new('test_gUejkz43UkdeCauC22J6UNqqVRdpwW') 

     payment = mollie.payments.get(payment.id) 

     params.permit! 
     status = params[:payment_status] 

     if payment.paid? 

      reservation = Reservation.find(params[:payid]) 
      reservation.update_attributes status:true 
     else 
      reservation.destroy 
     end 

     render nothing: true 

    end 

    protect_from_forgery except: [:your_trips] 
    def your_trips 
     @reservations = current_user.reservations.joins(:thrill).order('thrills.thrilldate asc').where('? <= thrills.thrilldate', Date.today) 
    end 

    def your_reservations 
     @trainings = current_user.trainings 
    end 

    private 
     def reservation_params 

      params.permit(:thrill_id, :user_id) 
     end 


    end 

누군가가 팁 또는 힌트를 얻은 경우 매우 감사하겠습니다. 감사합니다.

+0

안녕하세요. 레일스를 처음 사용하는 경우 : 여기에 게시하는 코드는 일반 레일즈 컨트롤러처럼 보이지 않습니다. 통보 컨트롤러에 모든 코드를 게시 할 수 있습니까? 나는 그것이'class NotifyController Mauddev

+0

안녕하세요, Mauddev, 귀하의 의견에 감사드립니다. 나는 참으로 새로운 것이고, 나는 풀 컨트롤러를 추가했다. 당신이 뭔가를 만들 수 있기를 바랍니다. –

답변

3

컨트롤러 상단에서 protect_from_forgery으로 전화해야합니다. 에서 protect_from_forgery 전화를 삭제할 수 있습니다.

예 : 당신이 :except 매개 변수에 여러 작업을 전달할 수 있습니다

class ReservationsController < ApplicationController 
    before_action :authenticate_user!, except: [:notify] 

    skip_before_filter :verify_authenticity_token 

    protect_from_forgery except: [:notify, :your_trips] 

    # actions go below here 

사이드 참고 : 당신은 JSON의 API에만 응용 프로그램에서 작업하는 경우, 당신이 레일 API를 조사하는 것이 좋습니다 : https://github.com/rails-api/rails-api