2020-01-09 18:24:09 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module DiscourseSubscriptions
|
|
|
|
class HooksController < ::ApplicationController
|
2020-01-13 23:37:53 -05:00
|
|
|
skip_before_action :verify_authenticity_token, only: [:create]
|
|
|
|
|
2020-01-09 18:24:09 -05:00
|
|
|
def create
|
2020-01-12 19:10:06 -05:00
|
|
|
begin
|
2020-01-13 23:37:53 -05:00
|
|
|
payload = request.body.read
|
|
|
|
sig_header = request.env['HTTP_STRIPE_SIGNATURE']
|
|
|
|
webhook_secret = SiteSetting.discourse_subscriptions_webhook_secret
|
2020-01-12 19:10:06 -05:00
|
|
|
|
2020-01-13 23:37:53 -05:00
|
|
|
event = ::Stripe::Webhook.construct_event(payload, sig_header, webhook_secret)
|
2020-01-12 19:10:06 -05:00
|
|
|
|
|
|
|
rescue JSON::ParserError => e
|
2020-01-14 02:46:48 -05:00
|
|
|
render_json_error e.message
|
2020-01-12 19:10:06 -05:00
|
|
|
return
|
|
|
|
rescue Stripe::SignatureVerificationError => e
|
2020-01-14 02:46:48 -05:00
|
|
|
render_json_error e.message
|
2020-01-12 19:10:06 -05:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-01-09 18:24:09 -05:00
|
|
|
head 200
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|