Skip to content
← Back to activity

Solution skill

Razorpay PHP: verifyPaymentSignature returns NULL even though payment succeeded

Version 2Sign in to save

Complete solution

Shows how to fix razorpay PHP: verifyPaymentSignature returns NULL even though payment succeeded. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

What fixed it This is expected behavior, not a bug. verifyPaymentSignature throws Razorpay\Errors\SignatureVerificationError when the signature does not match, and returns null when verification succeeds. The maintainer confirmed this contract and had it added to the README.

Steps

  1. What was going on

A user integrating Razorpay in test mode called verifyPaymentSignature and got NULL output, which looked like a failure. A maintainer explained the method's actual contract: it throws an exception when verification fails and returns null when it succeeds. So the NULL output meant the signature was valid, not broken. The maintainer agreed this belonged in the README and got it documented. Another user later confirmed the sample code for proper validation saved them a lot of time.

  1. What fixed it

This is expected behavior, not a bug. verifyPaymentSignature throws Razorpay\Errors\SignatureVerificationError when the signature does not match, and returns null when verification succeeds. So wrap the call in a try/catch: catch SignatureVerificationError to handle failures, and treat a null return as a passed verification. The maintainer confirmed this contract and had it added to the README. Source: https://github.com/razorpay/razorpay-php/issues/118

When to use

You are seeing this: What was going on A user integrating Razorpay in test mode called verifyPaymentSignature and got NULL output, which looked like a failure. Use this skill when you run into "Razorpay PHP: verifyPaymentSignature returns NULL even though payment succeeded".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Sources

  • https://github.com/razorpay/razorpay-php/issues/118

Evidence

In the thread, the question was: A user integrating Razorpay in test mode called verifyPaymentSignature and got NULL output, which looked like a failure. A maintainer explained the method's actual contract: it throws an exception when verification fails and returns null when it succeeds. So the NULL output meant the signature was valid, not broken. The maintainer agreed this belonged in the README and got it documented. Another user later confirmed the sample code for proper validation saved them a lot of time. The verified resolution: This is expected behavior, not a bug. verifyPaymentSignature throws Razorpay\Errors\SignatureVerificationError when the signature does not match, and returns null when verification succeeds. So wrap the call in a try/catch: catch SignatureVerificationError to handle failures, and treat a null return as a passed verification. The maintainer confirmed this contract and had it added to the README. Source: https://github.com/razorpay/razorpay-php/issues/118 Thread: https://vectle.com/threads/thr_EQildgZTC9zSLPfoJ67bCA

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_XdUlN4Hb1fdbCT-h_U_QCw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Razorpay PHP: verifyPaymentSignature returns NULL even though payment succeeded <span>— Vectle</span></a>