๐ก Generating a UPI QR Code in Frappe Using Python
Unified Payments Interface (UPI) has become a preferred method of digital payments in India, offering quick, secure, and real-time transactions.
Integrating UPI QR codes directly into business documents like Sales Invoices or Quotations simplifies the payment process for clients. Instead of manually entering UPI details, customers can simply scan a QR code and pay instantly.

This blog will guide you through generating a UPI QR code dynamically using Python and integrating it within the Frappe framework.
โ Benefits of Using UPI QR Codes in ERP Systems
- ๐ Secure and instant payments
- ๐งพ Paperless and contactless process
- ๐ฉ Easy to embed in Print Formats
- ๐ฐ Speeds up payment collection
- ๐ Reduces manual errors in UPI transfers
๐ ๏ธ How We Developed It
Add a new field in your custom or standard Doctype (e.g., Sales Invoice, Quotation):
- Label: UPI QR String
- Field Type: Small Text
- Fieldname: custom_upi_qr_link
Step 2: Generate UPI String in validate
Method
In your custom app or custom script, add the following logic to generate the UPI string:
def validate(self):
self.custom_upi_qr_link = (
f"upi://pay?pa={UpiID}"
f"&pn={company_name or UPI_Account_Name}"
f"&tn=Same State GST Client"
f"&tr=&cu=INR&mode=01"
f"&am={self.grand_total}"
)
Step 3: Define get_qr_code Method in Your Custom App
Use the pyqrcode Python library to generate a base64 PNG QR code from the UPI string:
import pyqrcode
def get_qr_code(qr_text, scale=5):
return pyqrcode.create(qr_text).png_as_base64_str(scale=scale, quiet_zone=1)
Step 4: Expose the Method in hooks.py
Make your method available in Jinja (for print formats):
jinja = {
"methods": [
"your_app_path.module_name.get_qr_code",
]
}
Replace your_app_path.module_name with the actual path to your method.
Step 5: Use in Print Format (HTML)
Now, you can use this function in any print format to show the QR code:
<img src="data:image/png;base64, {{ get_qr_code(doc.custom_upi_qr_link, scale=2) }}">
๐ Final Thoughts
This small feature can significantly improve your customer's payment experience and reduce payment delays. By leveraging Python and the flexibility of the Frappe framework, adding UPI QR functionality is both simple and powerful.
No comments yet. Login to start a new discussion Start a new discussion