Webhook verification for Razorpay.
This module provides utilities for verifying webhook signatures to ensure that webhooks are genuinely from Razorpay.
Usage
# Verify webhook signature
signature = get_req_header("x-razorpay-signature")
body = get_req_body()
if Razorpay.Webhook.verify(body, signature, "your_webhook_secret") do
# Process webhook
process_webhook(body)
else
# Invalid signature
{:error, :invalid_signature}
endNote
Always verify webhook signatures in production to prevent unauthorized requests.
Summary
Functions
Extracts webhook signature from headers.
Generates a webhook signature for a payload.
Verifies a webhook signature.
Functions
Extracts webhook signature from headers.
Parameters
headers: Map or keyword list of headers
Returns
- Signature string or nil if not found
Examples
signature = Razorpay.Webhook.extract_signature(%{"x-razorpay-signature" => "sig_123"})
Generates a webhook signature for a payload.
Parameters
payload: Raw webhook payload bodysecret: Webhook secret
Returns
- Hexadecimal signature string
Examples
signature = Razorpay.Webhook.generate_signature(payload, "secret")
Verifies a webhook signature.
Parameters
payload: Raw webhook payload bodysignature: Thex-razorpay-signatureheader valuesecret: Your webhook secret from Razorpay dashboard
Returns
trueif signature is validfalseif signature is invalid
Examples
# Verify signature
RazorpayEx.Webhook.verify(payload, signature, "webhook_secret_123")