Using Stripe webhooks with Rails
-
28-10-2019 - |
문제
I have successfully built out a rails app as per Ryan Bates' railscast (http://railscasts.com/episodes/288-billing-with-stripe) - However, in the railscast he doesn't cover webhooks. I was wondering if there are any good examples in the public domain of implementing and using webhooks to manage a subscription billing that has been created.
Any thoughts / direction would be super helpful?
Thanks!
해결책
There's a nice gem for this: https://github.com/integrallis/stripe_event.
It looks to be well written and maintained.
In your gemfile you can simply add the line -
gem 'stripe_event'
There's clear doc in the readme on github.
다른 팁
Most all payment gateways, including stripe, have some way of telling the client (your webapp) whether the charge went through or not.
For stripe, their docs show how to receive a webhook notification from them.
The flow is:
- Create a controller and method in your app to receive the webhook calls from stripe. Note that the calls will come in as POSTs, not GETs
- Register the url with stripe using their dashboard. This is a manual step that you do once.
- When your method is called from stripe, use the event info to update your models which track the status of your users' subscriptions.
Any questions?