-
I've been working through building logic for hooking into Pay webhooks, but I find it slightly awkward. Perhaps I missed something in the documentation, but I have two issues: First of all, subscribing to a lot of events is pretty awkward: Pay::Webhooks.configure do |events|
events.subscribe "stripe.customer.subscription.created", Billing::HandleWebhookService.new
events.subscribe "stripe.customer.subscription.updated", Billing::HandleWebhookService.new
events.subscribe "stripe.customer.subscription.deleted", Billing::HandleWebhookService.new
events.subscribe "stripe.payment_method.attached", Billing::HandleWebhookService.new
events.subscribe "stripe.payment_method.detached", Billing::HandleWebhookService.new
events.subscribe "stripe.payment_method.updated", Billing::HandleWebhookService.new
end Is there no way to just provide a list and subscribe to a single class for handling a subset of webhooks? The only improvement I could do for now, is to iterate as such: Pay::Webhooks.configure do |events|
PAY_WEBHOOKS.each do |event_name|
events.subscribe event_name, Billing::HandleWebhookService.new
end
end Second issue I am having, is working with different classes that don't implement Pay::Webhooks.configure do |events|
PAY_WEBHOOKS.each do |event_name|
events.subscribe event_name, Billing::HandleWebhookService.new
end
end
module Billing
class HandleWebhookService
def call(event)
Webhooks::Billing::HandleUpdatesWorker.perform_async(event.to_json)
end
end
end It would have been nicer to just directly call the worker or any class in general, that doesn't implement Pay::Webhooks.configure do |events|
PAY_WEBHOOKS.each do |event_name|
events.subscribe event_name, SomeWorker.perform_async
events.subscribe event_name, Class.start_sync
end
end Maybe all these things are possible already, but I couldn't find anything obvious in the documentation or looking through the source code |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
See the ActiveSupport::Notification documentation for other examples of what you can do with it. 👍 |
Beta Was this translation helpful? Give feedback.
See the ActiveSupport::Notification documentation for other examples of what you can do with it. 👍