Sha256: d4406b09d6be6214b2bec5d3eeb0e0ed4efbb27605e4f5a27c288ffe6f4a76c4

Contents?: true

Size: 1.01 KB

Versions: 24

Compression:

Stored size: 1.01 KB

Contents

module Pay
  module Webhooks
    class PaddleController < Pay::ApplicationController
      if Rails.application.config.action_controller.default_protect_from_forgery
        skip_before_action :verify_authenticity_token
      end

      def create
        queue_event(verified_event)
        head :ok
      rescue Pay::Paddle::Error
        head :bad_request
      end

      private

      def queue_event(event)
        return unless Pay::Webhooks.delegator.listening?("paddle.#{params[:alert_name]}")

        record = Pay::Webhook.create(processor: :paddle, event_type: params[:alert_name], event: event)
        Pay::Webhooks::ProcessJob.perform_later(record)
      end

      def verified_event
        event = verify_params.as_json
        verifier = Pay::Paddle::Webhooks::SignatureVerifier.new(event)
        return event if verifier.verify
        raise Pay::Paddle::Error, "Unable to verify Paddle webhook event"
      end

      def verify_params
        params.except(:action, :controller).permit!
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
pay-3.0.24 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.23 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.22 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.21 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.20 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.19 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.18 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.17 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.16 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.15 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.14 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.13 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.12 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.11 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.10 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.9 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.8 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.7 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.6 app/controllers/pay/webhooks/paddle_controller.rb
pay-3.0.5 app/controllers/pay/webhooks/paddle_controller.rb