Praveen KJ
Praveen KJ

Reputation: 650

Rails and Razorpay Webhook setup

I am trying to setup Razorpay Webhook in rails. Have done other developments in rails but pricing is new to me. i already setup and tested Webhook in razorpay dashboard and used requestbin.com to get the payload results(JSON) as mentioned in this doc https://razorpay.com/docs/webhooks/

Now, should i create a new POST route and capture the payload results(JSON) in controller and update the database accordingly?! Or is there any other way for handling Webhooks in Rails?

If it is so simple like above what is this gem https://github.com/razorpay/razorpay-ruby used for?

Upvotes: 0

Views: 871

Answers (2)

Rajdeep Singh
Rajdeep Singh

Reputation: 17834

Handling Webhooks require 3 things,

  1. Create a POST endpoint in your application
  2. Add the URL in the callback settings in the 3rd party dashboard, in your case it's Razorpay dashboard
  3. Since the Webhook endpoint is public, you need to verify whether the callback is actually from the authentic source or now. The details are usually provided in the api documentation of the 3rd party service.

After doing this, you can handle the callback in your own way according to the requirement. Preferebly Webhook callbacks params should be moved to a background service and return 204 request everytime.

Hope that helps!

Upvotes: 1

priya P
priya P

Reputation: 26

https://github.com/razorpay/razorpay-ruby is simply a ruby wrapper razorpay provides for all create/fetch methods.

In razorpay you can set up a web hook by first creating a handler path on your controller and expose it to them. You can add this route on their web hooks/add under settings on your razorpay merchant dashboard.

To make this callback more secure, razorpay allows you to setup a web hook signature from the dashboard and the above mentioned gem has a wrapper method that helps you verify the signature as well.

Upvotes: 1

Related Questions