Skip to content

Webhooks

Nemo edited this page Jul 31, 2017 · 3 revisions

You can verify Razorpay webhooks with the following code:

Razorpay::Utility.verify_webhook_signature(webhook_body, webhook_signature, webhook_secret)

This will throw a SecurityError exception if the signature is invalid. The parameters are as follows:

  • webhook_body: The complete webhook body. You can use request.raw_post in Rails, req.body.read in Rack, or request.body.read in Sinatra. Please consult your framework's documentation for the equivalent.
  • webhook_signature: We send the webhook signature in a request header with the key X-Razorpay-Signature . You can read the header using request.headers["X-Razorpay-Signature"] in Rails, env["HTTP_X_RAZORPAY_SIGNATURE"] in Rack, or request.env["HTTP_X-Razorpay-Signature"] in Sinatra.
  • webhook_secret: The secret you set at the time of setting up the webhook.

You can parse the webhook after it has been validated by using JSON.parse webhook_body.

Please see the Razorpay Webhooks Documentation for more details.

Clone this wiki locally