# UPI Auto Payment System Architecture

## Overview

This system enables automatic wallet credit for users after a successful UPI payment without using a traditional payment gateway. The system detects payment notifications from UPI apps and updates the user's wallet balance automatically.

The architecture consists of three main components:

1. Android Notification Listener App (Java)
2. PHP Backend API
3. Supabase PostgreSQL Database

---

# System Architecture

User initiates a payment from the website or game.
The UPI app processes the payment.
Once the payment is completed, a notification is generated on the Android device.
The Android listener app captures the notification and extracts payment details such as amount and UTR number.
These details are sent to the backend API where the transaction is validated and stored.
After validation, the user's wallet balance is automatically updated.

Flow:

User → UPI Payment → Android Notification → Listener App → PHP API → Supabase Database → Wallet Credit

---

# Components

## 1. Android Notification Listener (Java)

Purpose:

* Capture payment notifications from UPI apps.
* Extract payment details.
* Send payment data to the backend server.

Supported Apps:

* Google Pay
* PhonePe
* Paytm
* BHIM

Extracted Data:

* Amount
* UTR (Transaction Reference)
* Sender Name
* Timestamp

Responsibilities:

* Detect payment notifications
* Parse payment data
* Send secure API request to backend

---

## 2. PHP Backend API

Purpose:

* Receive payment data from the Android listener.
* Validate transactions.
* Update wallet balances.

API Endpoint Example:
/api/payment.php

Input Parameters:

* user_id
* amount
* utr

Backend Processing Steps:

1. Validate request parameters.
2. Check if the UTR already exists.
3. Insert transaction record.
4. Update user's wallet balance.
5. Return confirmation response.

Security Checks:

* Duplicate UTR prevention
* Amount validation
* Request authentication
* Rate limiting

---

## 3. Supabase PostgreSQL Database

The system uses Supabase as the main database.

Tables:

Users Table

* id
* username
* wallet_balance

Transactions Table

* id
* user_id
* amount
* utr
* status
* created_at

Database Responsibilities:

* Store users and wallet balances
* Store transaction history
* Prevent duplicate transactions

---

# Payment Processing Flow

1. User clicks "Pay ₹100" on the website.
2. The website launches the UPI payment link.
3. User completes payment in their UPI app.
4. The Android device receives a payment notification.
5. The Notification Listener captures the message.
6. The system extracts amount and UTR.
7. Payment details are sent to the PHP backend API.
8. Backend verifies transaction data.
9. Transaction is inserted into the database.
10. User wallet balance is updated.
11. The game detects updated wallet balance.

---

# Security Design

To protect the system from fraud and duplication:

Duplicate Transaction Protection

* UTR must be unique in the transactions table.

Notification Source Validation

* Only accept notifications from verified UPI apps.

Server Validation

* Amount must match expected values.

API Protection

* Requests must include API authentication tokens.

Logging

* All payment attempts must be logged for auditing.

---

# Deployment Architecture

Frontend

* Game Website (PHP)

Backend

* PHP API Server

Database

* Supabase PostgreSQL

Mobile Service

* Android Notification Listener App

Server Environment

* VPS / Cloud hosting

---

# Scalability

The system supports scaling by:

* Using a load-balanced API server
* Separating notification processing
* Adding message queues for payment events
* Using Supabase real-time updates

---

# Future Improvements

* Dynamic payment requests
* Admin dashboard
* Fraud detection system
* Payment analytics
* Multi-device notification processing
* Automatic payment reconciliation

---

# Conclusion

This architecture allows automatic wallet credit after UPI payments without relying on traditional payment gateways. By combining Android notification detection, a PHP backend API, and a Supabase database, the system can process payments efficiently for gaming platforms and wallet-based applications.
