mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-05 02:41:33 +00:00
Build Event object in controller instead of service object
This commit is contained in:
@@ -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]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
module Stripe
|
||||
class WebhookHandler
|
||||
def initialize(params)
|
||||
@event = Event.construct_from(params)
|
||||
def initialize(event)
|
||||
@event = event
|
||||
end
|
||||
|
||||
def handle
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user