Build Event object in controller instead of service object

This commit is contained in:
Rob Harrington
2017-10-12 16:31:17 +11:00
parent 4345285164
commit ed375a1e2c
3 changed files with 7 additions and 6 deletions

View File

@@ -7,7 +7,8 @@ module Stripe
# POST /stripe/webhook
def create
# TODO is there a sensible way to confirm this webhook call is actually from Stripe?
handler = WebhookHandler.new(params)
event = Event.construct_from(params)
handler = WebhookHandler.new(event)
result = handler.handle
render nothing: true, status: status_mappings[result]

View File

@@ -1,7 +1,7 @@
module Stripe
class WebhookHandler
def initialize(params)
@event = Event.construct_from(params)
def initialize(event)
@event = event
end
def handle

View File

@@ -3,8 +3,8 @@ require 'stripe/webhook_handler'
module Stripe
describe WebhookHandler do
let(:params) { { type: 'some.event' } }
let(:handler) { WebhookHandler.new(params) }
let(:event) { double(:event, type: 'some.event') }
let(:handler) { WebhookHandler.new(event) }
describe "event_mappings" do
it { expect(handler.send(:event_mappings)).to be_a Hash }
@@ -62,7 +62,7 @@ module Stripe
context "when the event has an 'account' attribute" do
before do
params[:account] = 'some.account'
allow(event).to receive(:account) { 'some.account' }
end
context "when some stripe accounts are destroyed" do