node:crypto for HMAC-SHA256 and timing-safe comparison.
Importing utilities
createRazorpayPaymentSignature
Create the expected payment signature from an order ID and payment ID.${orderId}|${paymentId}.
verifyRazorpayPaymentSignature
Verify a payment signature against the expected value.true if the signature is valid, false otherwise.
verifyRazorpayPaymentStatus
Check whether a payment object satisfies business-level requirements without verifying the cryptographic signature.reason is one of:
"order_mismatch"—order_iddoes not matchexpectedOrderId"amount_mismatch"—amountdoes not matchexpectedAmount"payment_not_captured"—statusis not"captured"
createRazorpayWebhookSignature
Create a webhook signature from a raw request body and webhook secret. Useful for testing or for custom webhook routes.verifyRazorpayWebhookSignature
Verify a webhook signature from thex-razorpay-signature header.
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
UsecreateRazorpayPaymentSignature and createRazorpayWebhookSignature in tests to generate valid signatures without making real requests.
signature.test.ts