An open API service indexing awesome lists of open source software.

https://github.com/classyid/payment-receipt-api

API ekstraksi data bukti pembayaran menggunakan Gemini AI. Mendukung 30+ platform seperti mobile banking, e-wallet, dan payment gateway Indonesia.
https://github.com/classyid/payment-receipt-api

Last synced: 4 months ago
JSON representation

API ekstraksi data bukti pembayaran menggunakan Gemini AI. Mendukung 30+ platform seperti mobile banking, e-wallet, dan payment gateway Indonesia.

Awesome Lists containing this project

README

          

# Payment Receipt API

API ekstraksi data bukti pembayaran menggunakan Gemini AI dengan dukungan untuk 30+ platform payment Indonesia.

## Features

- **Multi-Platform Support**: BNI Mobile, BCA, DANA, Flip, BSI, Bank Jatim, dan 25+ platform lainnya
- **Advanced OCR**: Powered by Gemini AI untuk akurasi ekstraksi data tinggi
- **Comprehensive Data Extraction**: 40+ data points termasuk nominal, tanggal, pengirim, penerima
- **Load Balancing**: Multi API key support dengan automatic failover
- **RESTful API**: JSON response dengan pagination dan search capabilities
- **Database Storage**: SQLite dengan schema komprehensif untuk audit trail

## Supported Platforms

### Mobile Banking
- BNI Mobile (wondr), BCA Mobile, BRI Mobile, Mandiri (Livin')
- Bank Syariah Indonesia (BSI), BYOND by BSI
- Bank Jatim, Bank Muamalat

### E-Wallets
- DANA, OVO, GoPay, LinkAja, ShopeePay

### Payment Gateways
- Flip, Midtrans, Virtual Account

### Physical Receipts
- ATM Transfer receipts, SMS Banking, Bank slips

## Quick Start

### Prerequisites
- Python 3.7+
- Gemini API key

### Installation

1. Clone repository:
```bash
git clone https://github.com/classyid/payment-receipt-api.git
cd payment-receipt-api
```

2. Install dependencies:
```bash
pip install flask flask-cors requests
```

3. Configure API key:
```python
# Edit bukti.py
GEMINI_API_KEYS = [
'your-gemini-api-key-here'
]
```

4. Run the application:
```bash
python bukti.py
```

API akan berjalan di `http://localhost:5579`

## API Usage

### Process Payment Receipt

```bash
curl -X POST http://localhost:5579/api/process-payment \
-H "Content-Type: application/json" \
-d '{
"fileData": "base64_encoded_image_data",
"fileName": "receipt.jpg",
"mimeType": "image/jpeg"
}'
```

### Response Example

```json
{
"status": "success",
"data": {
"analysis": {
"parsed": {
"platform": "BNI Mobile",
"transaction": {
"status": "Berhasil",
"amount": "664025",
"date": "14/08/2025",
"type": "BI-FAST"
},
"sender": {
"name": "xy",
"bank": "BNI"
},
"receiver": {
"name": "xx",
"bank": "BSI"
}
}
}
}
}
```

## API Endpoints

| Endpoint | Method | Description |
|----------|---------|-------------|
| `/api/process-payment` | POST | Process payment receipt |
| `/api/docs` | GET | API documentation |
| `/api/stats` | GET | Usage statistics |
| `/api/payments/history` | GET | Payment history |
| `/api/payments/search` | GET | Search payments |
| `/api/health` | GET | Health check |

## Data Extraction Capabilities

- **Transaction Info**: Status, date, time, amount, fees, reference numbers
- **Party Details**: Sender/receiver names, bank info, account numbers
- **Platform Data**: App name, channel, terminal info
- **Additional**: Description, purpose, merchant, location, balances

## Configuration

### Environment Variables (Optional)
```bash
export GEMINI_API_KEY="your-api-key"
export DATABASE_PATH="payment_receipts.db"
export UPLOAD_FOLDER="uploads"
```

### Multiple API Keys
```python
GEMINI_API_KEYS = [
'key1-for-load-balancing',
'key2-for-failover',
'key3-for-high-availability'
]
```

## Performance

- **Processing Time**: 2-5 seconds per document
- **Accuracy Rate**: 95%+ for clear documents
- **Supported File Types**: JPG, PNG, PDF, GIF, BMP, WebP
- **Max File Size**: 16MB
- **Concurrent Requests**: Unlimited with load balancing

## Database Schema

### payment_receipts
Stores extracted payment data with 40+ fields including:
- Transaction details (status, amount, fees, dates)
- Party information (sender/receiver details)
- Platform-specific data (app, channel, terminal)
- Additional metadata (merchant, location, balances)

### metadata
File information and processing status

### logs
API calls, errors, and processing history

## Development

### Project Structure
```
payment-receipt-api/
├── bukti.py # Main application
├── uploads/ # File storage
├── payment_receipts.db # SQLite database
├── requirements.txt # Dependencies
└── README.md
```

### Testing
```bash
# Health check
curl http://localhost:5579/api/health

# Get statistics
curl http://localhost:5579/api/stats

# View documentation
curl http://localhost:5579/api/docs
```

## Error Handling

- Automatic retry with multiple API keys
- Comprehensive error logging
- Graceful fallback for parsing failures
- Input validation and sanitization

## Security

- File type validation
- Size limits
- SQL injection protection
- Error message sanitization
- No sensitive data in logs

## Contributing

1. Fork the repository
2. Create feature branch (`git checkout -b feature/new-feature`)
3. Commit changes (`git commit -am 'Add new feature'`)
4. Push to branch (`git push origin feature/new-feature`)
5. Create Pull Request

## License

MIT License - see LICENSE file for details

## Support

- Create an issue for bug reports
- Feature requests welcome
- Documentation improvements appreciated

## Changelog

### v3.0.0
- Enhanced AI prompt for better recognition
- Added 30+ platform support
- Implemented load balancing
- Added comprehensive database schema
- New search and pagination features

### v2.0.0
- Added multiple platform support
- Enhanced error handling
- Database storage implementation

### v1.0.0
- Initial release with basic payment processing

## Acknowledgments

- Powered by Google Gemini AI
- Built with Flask framework
- Inspired by Indonesian fintech ecosystem

---

**Note**: This API is designed for Indonesian payment platforms. Ensure compliance with local data protection regulations when processing financial documents.
```

## Additional Files to Include

### .gitignore
```
# Python
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
env/
venv/
.venv/
pip-log.txt
pip-delete-this-directory.txt

# Database
*.db
*.sqlite3

# Uploads
uploads/
*.jpg
*.png
*.pdf

# Environment
.env
.env.local

# IDE
.vscode/
.idea/
*.swp
*.swo

# Logs
*.log
logs/

# OS
.DS_Store
Thumbs.db
```

### requirements.txt
```
flask==2.3.3
flask-cors==4.0.0
requests==2.31.0
gunicorn==21.2.0
python-dotenv==1.0.0
```

### LICENSE (MIT)
```
MIT License

Copyright (c) 2025 [Classy Indonesia]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```