Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Store (don't raise) when webhook type isn't recognised.
Browse files Browse the repository at this point in the history
  • Loading branch information
osahyoun committed Jun 6, 2016
1 parent 54bcc61 commit bf55ba9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
@@ -1,4 +1,6 @@
require_relative 'payment'
require_relative 'subscription'
require_relative 'mandate'

module PaymentProcessor::GoCardless
module WebhookHandler
Expand All @@ -24,17 +26,21 @@ def already_processed?(event)
end

def process_event(event)
processor = ::PaymentProcessor::GoCardless::WebhookHandler.const_get(event["resource_type"].classify).new(event)
processor.process
processor
klass_name = event["resource_type"].classify

if ::PaymentProcessor::GoCardless::WebhookHandler.const_defined?(klass_name)
processor = ::PaymentProcessor::GoCardless::WebhookHandler.const_get(klass_name).new(event)
processor.process
processor
end
end

def record_processing(event, handler)
def record_processing(event, handler = nil)
::Payment::GoCardless::WebhookEvent.create(
event_id: event['id'],
action: event['action'],
resource_type: event['resource_type'],
resource_id: handler.resource_id,
resource_id: handler.try(:resource_id),
body: event.to_json
)
end
Expand Down
28 changes: 27 additions & 1 deletion spec/lib/payment_processor/go_cardless/webhook_handler_spec.rb
Expand Up @@ -153,6 +153,33 @@ module PaymentProcessor::GoCardless
end
end

describe 'Non application events' do
let(:non_applicable_events) do
[
{"id"=>"XEVTESTJG8GPP7I",
"created_at"=>"2016-04-14T11:32:20.343Z",
"resource_type"=>"payouts",
"action"=>"customer_approval_granted",
"links"=>{"payment"=>"payment_ID_1234", "subscription"=>"index_ID_123"},
"details"=>
{"origin"=>"customer",
"cause"=>"customer_approval_granted",
"description"=>"The customer granted approval for this subscription"},
"metadata"=>{}
}
]
end

it 'stores event' do
WebhookHandler::ProcessEvents.process(non_applicable_events)
expect(Payment::GoCardless::WebhookEvent.first.attributes).to include({
event_id: "XEVTESTJG8GPP7I",
resource_id: nil
}.stringify_keys)
end

end

describe "Subscriptions" do
let(:pending_first) { true }
let(:action) { create(:action, page: page, form_data: { recurrence_number: 1 }) }
Expand Down Expand Up @@ -322,7 +349,6 @@ module PaymentProcessor::GoCardless
]
end


before do
allow( ChampaignQueue ).to receive(:push)
WebhookHandler::ProcessEvents.process(first_events)
Expand Down

0 comments on commit bf55ba9

Please sign in to comment.