Logo Lanfrica

n-cognto/Duplex-mpesa-parse

Domaine:

digital infrastructure

Type de record:

software
Créateur:
n-c
Hôte:
# Dual MPESA Parser The `DualMPESAParser` is a Python class designed to parse M-PESA transaction messages in both English and Swahili. It extracts relevant details from the messages, such as transaction type, amount, sender/recipient information, and balance details. ## Features - Supports parsing of M-PESA messages in both English and Swahili. - Extracts transaction details such as transaction ID, amount, sender/recipient, date, time, and balance. - Handles various transaction types including received, paid, sent, M-Shwari, airtime purchase, withdrawal, balance check, and more. - Identifies and handles failed transactions. ## Installation Ensure you have Python 3 installed. Clone the repository and navigate to the directory containing `dual_purpose.py`. ```bash git clone cd ``` ## Usage You can use the `DualMPESAParser` class in your Python scripts to parse M-PESA messages. Below is an example of how to use the parser: ```python from dual_purpose import DualMPESAParser parser = DualMPESAParser() message = "TA22OI958I Confirmed.Ksh50.00 transferred from M-Shwari account on 2/1/25 at 11:00 AM. M-Shwari balance is Ksh925.46 .M-PESA balance is Ksh359.50 .Transaction cost Ksh.0.00" result = parser.parse_message(message) print(result) ``` ## Example Messages Here are some example messages and their parsed results: ### English Messages 1. **Message:** ``` TA22OI958I Confirmed.Ksh50.00 transferred from M-Shwari account on 2/1/25 at 11:00 AM. M-Shwari balance is Ksh925.46 .M-PESA balance is Ksh359.50 .Transaction cost Ksh.0.00 ``` **Parsed Result:** ```json { "transaction_id": "TA22OI958I", "mshwari_amount": "50.00", "mshwari_direction": "from", "datetime": "2025-01-02 11:00:00", "mpesa_balance": 359.50, "transaction_cost": 0.0, "status": "SUCCESS", "transaction_type": "MSHWARI", "amount": 50.0 } ``` 2. **Message:** ``` TA27OIFCSZ Confirmed.on 2/1/25 at 11:01 AMWithdraw Ksh300.00 from 343595 - Anzal Express Ltdlongonot farm along moi south lake Agg New M-P …