Sha256: d448039cd1558c42b4e2f15c4d713587a9049e321f96288056d4eff7ed086da1

Contents?: true

Size: 1.24 KB

Versions: 6

Compression:

Stored size: 1.24 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
        verifier = Pay::Paddle::Webhooks::SignatureVerifier.new(check_params.as_json)
        if verifier.verify
          case params["alert_name"]
          when "subscription_created"
            Pay::Paddle::Webhooks::SubscriptionCreated.new(check_params.as_json)
          when "subscription_updated"
            Pay::Paddle::Webhooks::SubscriptionUpdated.new(check_params.as_json)
          when "subscription_cancelled"
            Pay::Paddle::Webhooks::SubscriptionCancelled.new(check_params.as_json)
          when "subscription_payment_succeeded"
            Pay::Paddle::Webhooks::SubscriptionPaymentSucceeded.new(check_params.as_json)
          when "subscription_payment_refunded"
            Pay::Paddle::Webhooks::SubscriptionPaymentRefunded.new(check_params.as_json)
          end
          render json: {success: true}, status: :ok
        else
          head :ok
        end
      end

      private

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pay-2.4.4 app/controllers/pay/webhooks/paddle_controller.rb
pay-2.4.3 app/controllers/pay/webhooks/paddle_controller.rb
pay-2.4.2 app/controllers/pay/webhooks/paddle_controller.rb
pay-2.4.0 app/controllers/pay/webhooks/paddle_controller.rb
pay-2.3.1 app/controllers/pay/webhooks/paddle_controller.rb
pay-2.3.0 app/controllers/pay/webhooks/paddle_controller.rb