-
I am following the docs here https://github.com/pay-rails/pay/blob/master/docs/stripe/1_overview.md regarding creating a webhook listener to save order details to the database. I understand I need to add the following to an initializer file e.g. # config/initializer/pay.rb
Pay::Webhooks.delegator.subscribe "stripe.checkout.session.completed", FulfillCheckout.new
Pay::Webhooks.delegator.subscribe "stripe.checkout.session.async_payment_succeeded", FulfillCheckout.new But I am confused about where to place the listener itself?? # app/models/order/webhooks/fulfill_checkout.rb??
class FulfillCheckout
def call(event)
object = event.data.object
if object.payment_status == "paid"
# example
order = Order.create!(address: object.charges.shipping.address, user_id: object.charges.data.metadata.user_id)
order.paid!
end
end
end |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
You can define the class anywhere you want. I like putting mine in |
Beta Was this translation helpful? Give feedback.
-
@excid3 Curious how you would namespace webhooks at the application level?
|
Beta Was this translation helpful? Give feedback.
You can define the class anywhere you want. I like putting mine in
app/webhooks
but you can put it in models, lib, etc.