2017-01-22 13 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

こんにちはChris。あなたがRailsを初めて使う人のために:ここに投稿するコードは、通常のRailsコントローラのようには見えません。あなたの通知コントローラにすべてのコードを投稿できますか?私は 'class NotifyController Mauddev

+0

こんにちはMauddev、あなたのコメントのおかげで。私は本当にこれに新しいです、私はフルコントローラを追加しました。あなたが何かを作ってくれることを願っています。 –

答えて

3

コントローラーの最上部にprotect_from_forgeryと電話するか、ApplicationControllerprotect_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のみのアプリで作業している場合、私はあなたがRailsのAPIを検討することをお勧め: https://github.com/rails-api/rails-api

関連する問題