codebude / QRCoder

A pure C# Open Source QR Code implementation
MIT License
4.62k stars 1.1k forks source link

How to generate QR Code that is supported by UPI apps like Phonepe, Paytm, Google Pay #277

Closed subhojit-me closed 3 years ago

subhojit-me commented 3 years ago

[ ] Bug
[x] Question (e.g. about handling/usage)
[ ] Request for new feature/improvement

Expected Behavior

Tring to generate a QR Code that can be used to pay via UPI

Current Behavior

there is no Payload Generator that supports UPI, if exists and am missing that please correct me.

subhojit-me commented 3 years ago

after some study am successfully able to find that QR Code for UPI payment can be done by passing string in upi:// format with parameter specified in this doc

codebude commented 3 years ago

Thanks for pointing me to the UPI standard. Will add it to the todo list.

@subhojit-me did you really mean upi:// or did you mean payto:// scheme? I can only find information about payto:// uris, but not about upi://...

subhojit-me commented 3 years ago

Well, i used a trick about payto, did some research also to figured it out.

  1. first i was using this API and generated a QR code.
  2. after scanning the generated QR Code with this app in android it shows like this WhatsApp Image 2021-03-16 at 1 38 24 PM

So i tried the text as Payload in my code like this

var payload = $@"upi://pay?cu={upiParams.CURRENCY_CODE}&pa={upiParams.RECEIVER_VPA}&pn={upiParams.RECEIVER_NAME}&tn={upiParams.PAYMENT_NOTE}&am={upiParams.AMOUNT}";
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q);
var qrCode = new Base64QRCode(qrCodeData);

Now its working,

Please mention me if am doing anything wrong.