Skip to main content
The plugin exports several utilities from the server entry for working with Razorpay signatures. These use node:crypto for HMAC-SHA256 and timing-safe comparison.

Importing utilities

createRazorpayPaymentSignature

Create the expected payment signature from an order ID and payment ID.
Returns a hex-encoded HMAC-SHA256 of ${orderId}|${paymentId}.

verifyRazorpayPaymentSignature

Verify a payment signature against the expected value.
Returns true if the signature is valid, false otherwise.

verifyRazorpayPaymentStatus

Check whether a payment object satisfies business-level requirements without verifying the cryptographic signature.
Returns an object describing whether the payment is valid and why it might not be.
If the payment is not valid, reason is one of:
  • "order_mismatch" — order_id does not match expectedOrderId
  • "amount_mismatch" — amount does not match expectedAmount
  • "payment_not_captured" — status is not "captured"

createRazorpayWebhookSignature

Create a webhook signature from a raw request body and webhook secret. Useful for testing or for custom webhook routes.
Returns a hex-encoded HMAC-SHA256 of the raw body.

verifyRazorpayWebhookSignature

Verify a webhook signature from the x-razorpay-signature header.
Returns true if the signature is valid, false otherwise.

Custom verify endpoint

If you need a server-side verification endpoint outside the plugin’s built-in flow, combine the utilities like this:
verify.ts

Custom webhook route

If you want to handle webhooks on a custom route instead of the plugin endpoint, use the webhook utilities directly:
webhook.ts

Test fixtures

Use createRazorpayPaymentSignature and createRazorpayWebhookSignature in tests to generate valid signatures without making real requests.
signature.test.ts