2020-01-09 18:24:09 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module DiscourseSubscriptions
|
|
|
|
class HooksController < ::ApplicationController
|
|
|
|
def create
|
2020-01-12 19:10:06 -05:00
|
|
|
begin
|
|
|
|
|
|
|
|
# payload, sig_header, endpoint_secret
|
|
|
|
event = ::Stripe::Webhook.construct_event(
|
|
|
|
{},
|
|
|
|
'stripe-webhook-signature',
|
|
|
|
'endpoint_secret'
|
|
|
|
)
|
|
|
|
|
|
|
|
rescue JSON::ParserError => e
|
|
|
|
# Invalid payload
|
|
|
|
status 400
|
|
|
|
return
|
|
|
|
rescue Stripe::SignatureVerificationError => e
|
|
|
|
# Invalid signature
|
|
|
|
status 400
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-01-09 18:24:09 -05:00
|
|
|
head 200
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|