get the payload, signature and secret for webhook
This commit is contained in:
parent
0543b3a6a3
commit
95413ee161
|
@ -2,15 +2,15 @@
|
||||||
|
|
||||||
module DiscourseSubscriptions
|
module DiscourseSubscriptions
|
||||||
class HooksController < ::ApplicationController
|
class HooksController < ::ApplicationController
|
||||||
|
skip_before_action :verify_authenticity_token, only: [:create]
|
||||||
|
|
||||||
def create
|
def create
|
||||||
begin
|
begin
|
||||||
|
payload = request.body.read
|
||||||
|
sig_header = request.env['HTTP_STRIPE_SIGNATURE']
|
||||||
|
webhook_secret = SiteSetting.discourse_subscriptions_webhook_secret
|
||||||
|
|
||||||
# payload, sig_header, endpoint_secret
|
event = ::Stripe::Webhook.construct_event(payload, sig_header, webhook_secret)
|
||||||
event = ::Stripe::Webhook.construct_event(
|
|
||||||
{},
|
|
||||||
'stripe-webhook-signature',
|
|
||||||
'endpoint_secret'
|
|
||||||
)
|
|
||||||
|
|
||||||
rescue JSON::ParserError => e
|
rescue JSON::ParserError => e
|
||||||
# Invalid payload
|
# Invalid payload
|
||||||
|
|
|
@ -4,17 +4,19 @@ require 'rails_helper'
|
||||||
|
|
||||||
module DiscourseSubscriptions
|
module DiscourseSubscriptions
|
||||||
RSpec.describe HooksController do
|
RSpec.describe HooksController do
|
||||||
|
before do
|
||||||
|
SiteSetting.discourse_subscriptions_webhook_secret = 'zascharoo'
|
||||||
|
end
|
||||||
|
|
||||||
it "contructs a webhook event" do
|
it "contructs a webhook event" do
|
||||||
|
payload = 'we-want-a-shrubbery'
|
||||||
|
headers = { 'HTTP_STRIPE_SIGNATURE' => 'stripe-webhook-signature' }
|
||||||
|
|
||||||
::Stripe::Webhook
|
::Stripe::Webhook
|
||||||
.expects(:construct_event)
|
.expects(:construct_event)
|
||||||
.with({}, 'stripe-webhook-signature', 'endpoint_secret')
|
.with('we-want-a-shrubbery', 'stripe-webhook-signature', 'zascharoo')
|
||||||
.returns(true)
|
|
||||||
|
|
||||||
headers = {
|
post "/s/hooks.json", params: payload, headers: headers
|
||||||
'HTTP_STRIPE_SIGNATURE' => 'stripe-webhook-signature'
|
|
||||||
}
|
|
||||||
|
|
||||||
post "/s/hooks.json"
|
|
||||||
|
|
||||||
expect(response.status).to eq 200
|
expect(response.status).to eq 200
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue