hummingbird-me/kitsu-server

View on GitHub
app/controllers/webhooks/stripe_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
F
45%
module Webhooks
  class StripeController < ApplicationController
    include CustomControllerHelpers

    SECRET = ENV['STRIPE_WEBHOOK_SECRET']

    def notify
      payload = request.body.read
      signature = request.env['HTTP_STRIPE_SIGNATURE']
      event = Stripe::Webhook.construct_event(payload, signature, SECRET)

      StripeEventService.new(event).call

      head 204
    rescue JSON::ParserError, Stripe::SignatureVerificationError
      render_jsonapi_error 400, 'Invalid payload'
    end
  end
end