Bill Payment Automation System Using Python, Barcode Integration & OCR

  • Home
  • /Bill Payment Automation System Using Python, Barcode Integration & OCR
Project Details Cover 1
Project Details Cover 2
Project Details Cover 3
Project Details Cover 4
Project Details Cover 5
Project Details Cover 6
Project Details Cover 7
Project Details Cover 8

Bill Payment Automation System Using Python, Barcode Integration & OCR

Project Overview Title: Bill Payment Automation System Using Python, Barcode Integration & OCR

Industry: Financial Services / Utility Bill Payment

Project Category: Desktop Application / Automation

Project Duration: Approximately 2 months

Project Cost: ~$2,500

Project Started On: September 2024

Role: Full-Stack Python Developer / Automation Engineer

Live URL: N/A (Desktop Application)

Tags: • Python • OCR (Tesseract) • Barcode Scanning • Automation • NADRA e-Sahulat • Desktop Application

Challenges • High Volume of Bills: Processing 500-700 bills per day manually was time-consuming and physically exhausting. • Human Error & Irreversible Mistakes: A single wrong digit in the consumer number meant a non-refundable payment to the wrong account. • Encrypted Barcodes for LESCO: While other bills had straightforward barcode information, LESCO used an encryption mechanism that required an official decryption technique from the LESCO head office. • Integration with NADRA e-Sahulat: To automate data entry in the e-Sahulat portal, the system needed robust simulation of keyboard input, mouse clicks, and real-time verification of on-screen status messages and amounts.

Solution 1. Decrypting LESCO Barcodes The first breakthrough came from contacting LESCO head office to obtain their custom decryption technique. Once available, this logic was incorporated into the Python script, enabling parsing of encrypted data for consumer numbers, due dates, and amounts.

2. Barcode Scanning & Data Extraction For other bills (PTCL, SNGPL, LWASA, etc.), barcodes were not encrypted, allowing straightforward data retrieval. Using a barcode scanning SDK in Python, the system extracted: • Consumer Number • Due Date • Bill Amount

The system then auto-populated corresponding fields in the NADRA e-Sahulat portal, eliminating manual data entry.

3. Python Automation Scripts To simulate user actions in the NADRA e-Sahulat portal, Python Mouse and Keyboard SDK tooling (for example PyAutoGUI) was used. The automated process included: • Opening the portal and moving cursor to correct text fields. • Entering CNIC and mobile number once (saved as variables). • Filling in the consumer number from barcode data. • Clicking Show Bill and taking screenshot for amount confirmation. • Verifying amount by reading on-screen value using Tesseract OCR. • Comparing OCR value with barcode-extracted amount. • Automating payment when amounts match. • Skipping payment on mismatch to avoid financial errors. • Monitoring prompts like Payment in Progress and Your bill has been paid, then returning to main menu for next bill.

4. OCR (Tesseract) for Accuracy The portal displays a waiting message before final bill amount appears. OCR checks this state and waits until the amount is fully visible before proceeding. This prevents premature payment actions and incorrect captures.

5. Desktop Application The entire flow was wrapped in a user-friendly desktop application: • Single Input for CNIC and Mobile Number. • Scan & Pay interface triggering full automation. • Real-time logs for successful and skipped payments.

Technologies Used • Python: Core logic and scripting. • PyAutoGUI / Mouse & Keyboard SDK: Automated clicks and keystrokes. • Tesseract OCR: Read amounts, status messages, and confirmations from screenshots. • Barcode Libraries: Decode and parse consumer data. • Custom Decryption (LESCO): Handle LESCO encrypted barcodes. • Desktop Application Framework (such as PyQt or Tkinter): User-friendly interface.

Results & Impact Reduced Time & Effort • Processes up to 700 bills in under 2 hours, down from 4-6 hours manual work. • Greatly reduced eye strain and hand fatigue.

Lowered Financial Risk • Amount matching before payment nearly eliminates incorrect payments. • Mismatches trigger automatic cancel to prevent non-refundable losses.

Scalable & Efficient • Handles higher bill volume without additional manpower. • A small team or even one person can oversee hundreds of payments.

Error Reduction • Repetitive typing errors are largely eliminated because critical fields are auto-filled from barcode scans.

Enhanced Accuracy & Transparency • Real-time logs simplify tracking and audit review. • OCR gates prevent unsafe steps until the correct state is detected.

Lessons Learned • Decryption Challenges: Obtaining LESCO decryption details was a critical dependency and showed the importance of official collaboration with proprietary systems. • Robust Error Handling: Screenshot-based checks and fallback logic improved resilience against lag and portal issues. • Usability Matters: Desktop GUI significantly improved adoption compared to command-line only workflows. • Testing & Iteration: Cross-provider testing (LESCO, PTCL, SNGPL, LWASA) was essential for production reliability.

Conclusion The Bill Payment Automation System combined barcode decryption, OCR validation, and GUI automation into one dependable workflow. By using Python and verification-first processing, the solution delivered faster operations, higher accuracy, and far lower human error under high daily volume.

Client:
Personal Project
Date:
September 2024 (Approximately 2 Months) - Present
Services:
Full-Stack Python Developer / Automation Engineer