question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not able to verify signature of payment

See original GitHub issue

I have tried following code for verifying payment signature. But signature from payment and generated at my point are diffrent. Please let me know if i am doing something wrong here. Additionally in docs, there’s no sample code for nodejs. It will be really good if we can just find it there.

let generatedSignature = crypto
  .createHmac(
     "SHA256",
     "my-secret"
).update(payment.razorpay_payment_id + '|' + payment.razorpay_order_id)
.digest('hex');
let isSignatureValid = generatedSignature == payment.razorpay_signature;

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
MrSpark2591commented, Sep 17, 2019

Closing this issue, As I have figured out that the payment signature is generated using live mode secret key even though you are in test mode and the order was generated in test mode.

So if you want to check the Payment signature always use Live mode secret key. Above code will work if you use Live mode secret key.

0reactions
DibyajyotiMishracommented, Apr 14, 2021

I am getting undefined values of razorpayOrderId and razorpaySignature from the handler response while working on test mode. So the payment verification fails in the backend. I have been stuck at this for over a day now. Any help is highly appreciated.

This is my code snippet:

` const launchRazorpay = async () => { const order = await axios.post"http://localhost:8081/api/subscription/pay");

const { amount, id: order_id, currency } = order.data;

console.log(order);

const options = {
  key: "rzp_test_asdfg345dfCVBN",
  amount: amount,
  currency: currency,
  name: "Razorpay",
  description: "PAY YOUR SUBSCRIPTION FEES",
  image: `${process.env.PUBLIC_URL}/assets/images/logo.png`,
  orderId: order_id,
  handler: function (response) {
    alert(response.razorpay_payment_id);// pay_asd1234
    alert(response.razorpay_order_id);// undefined
    alert(response.razorpay_signature);// undefined
  },
  prefill: {
    name: "abc",
    email: "abc@gmail.com",
    contact: "+911234567890",
  },
};
console.log("====================================");
console.log(options.orderId === order_id); // true
console.log(response.razorpay_order_id === order_id);// false
console.log("====================================");
const paymentObject = new window.Razorpay(options);
paymentObject.open();

};

`

@harman28 sir, any suggestions?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Verify the digital signature on a signed email message
If a digital signature isn't valid, there can be many causes. For example, the sender's certificate may have expired, it may have been...
Read more >
Verify response with signature | Google Pay for India
For a response with a signature, verify the signature with the corresponding Google Pay public key. If the verification succeeds, check that the...
Read more >
Razorpay signature verification not happening as SHA256 ...
I am making an app in which after a successful payment I create a digest which I verify using the suggest way ...
Read more >
Validating digital signatures, Adobe Acrobat
Under Categories, select Signatures. For Verification, click More. To automatically validate all signatures in a PDF when you open the document ...
Read more >
Could not verify Apple Pay token s… | Apple Developer Forums
Hello, we are having problems with verifying some Apple Pay signatures in payment tokens. ... The openssl asn1parse and dumpasn1 also could not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found