|
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.newBut 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 |
Answered by
excid3
Nov 29, 2021
Replies: 2 comments 5 replies
|
You can define the class anywhere you want. I like putting mine in |
1 reply
Answer selected by
rdtclark
|
@excid3 Curious how you would namespace webhooks at the application level?
|
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can define the class anywhere you want. I like putting mine in
app/webhooksbut you can put it in models, lib, etc.