Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
•
Sichere ProgrammierungYour agent picks one of two options. Can you test that choice?(23.09.2026 um 01:10 Uhr)
•
Sichere ProgrammierungWe audited 110 AI usage tools. Here is where the numbers go wrong.(23.09.2026 um 01:12 Uhr)
•
Sichere ProgrammierungWhy Does Your AI Coding Agent Start Forgetting What It Was Doing?(23.09.2026 um 01:19 Uhr)
••••••••
Sichere ProgrammierungYour agent picks one of two options. Can you test that choice?(23.09.2026 um 01:10 Uhr)
•
Sichere ProgrammierungWe audited 110 AI usage tools. Here is where the numbers go wrong.(23.09.2026 um 01:12 Uhr)
•
Sichere ProgrammierungWhy Does Your AI Coding Agent Start Forgetting What It Was Doing?(23.09.2026 um 01:19 Uhr)
•••••••
Intelligence View
⚡ tsecurity.de Intelligence

Automating M-Pesa Rent Collection in Kenya: The Technical Architecture

M-Pesa handles over 90% of rent payments in Kenya. But most landlords still reconcile these payments manually — downloading statements, matching transactions to tenants line by line in Excel. We automated this entire flow. Here is how we b…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

M-Pesa handles over 90% of rent payments in Kenya. But most landlords still reconcile these payments manually — downloading statements, matching transactions to tenants line by line in Excel. We automated this entire flow.



Here is how we built the M-Pesa rent collection system inside HomeManager, our property management platform for East Africa.






The Problem



A landlord with 50 tenants receives 50+ M-Pesa transactions every month. Each transaction has:




  • Sender phone number

  • Amount

  • Account reference (if Paybill)

  • Transaction ID

  • Timestamp



To reconcile manually:




  1. Download M-Pesa statement from Safaricom portal

  2. Open tenant spreadsheet

  3. Match each transaction to a tenant

  4. Mark as paid

  5. Send receipt manually

  6. Identify who has not paid

  7. Send reminders individually



For 50 tenants, this takes 4-8 hours monthly. For 200 tenants, it is a full-time job.






The Architecture



We use Safaricom's Daraja API (M-Pesa API) with a Django backend.






Payment Flow






Tenant opens phone
→ Selects Lipa na M-Pesa → Paybill
→ Enters business number (landlord's Paybill)
→ Enters account number (their unit number, e.g., "A3")
→ Enters amount
→ Confirms with PIN

Safaricom processes payment
→ Sends IPN callback to our server
→ Our server receives transaction data

Our system:
→ Validates the callback (security check)
→ Extracts: amount, phone, account_ref, transaction_id
→ Matches account_ref to tenant unit
→ Credits tenant account
→ Generates receipt
→ Sends SMS receipt to tenant
→ Updates dashboard in real-time









Key Technical Decisions



1. Paybill over Till Number



Paybill allows an account reference field. This is critical — the tenant enters their unit number, which the system uses to auto-match the payment. Without this (Till Number), you only get a phone number and have to look up which tenant owns that number.



Full comparison: Paybill vs Till for Rent



2. IPN (Instant Payment Notification) callbacks



Safaricom sends a POST request to our endpoint every time a payment is made. This gives us real-time data — no polling, no delays.




# Simplified IPN handler
@csrf_exempt
def mpesa_callback(request):
data = json.loads(request.body)

transaction_id = data['TransID']
amount = Decimal(data['TransAmount'])
account_ref = data['BillRefNumber'] # Unit number
phone = data['MSISDN']

# Find tenant by unit reference
tenant = Tenant.objects.filter(
unit__unit_number__iexact=account_ref,
unit__property__organization=org
).first()

if tenant:
# Record payment
payment = MpesaPayment.objects.create(
tenant=tenant,
amount=amount,
transaction_id=transaction_id,
phone_number=phone
)
# Auto-reconcile against outstanding invoice
reconcile_payment(payment)
# Send SMS receipt
send_receipt_sms(tenant, amount, transaction_id)

return JsonResponse({'ResultCode': 0})






3. Fuzzy matching for account references



Tenants do not always type their unit number correctly. "A3" might come in as "a3", "A 3", "Unit A3", or "apt3". We normalize the account reference before matching:




def normalize_account_ref(ref):
"""Normalize M-Pesa account reference for matching."""
ref = ref.strip().upper()
ref = re.sub(r'[^A-Z0-9]', '', ref) # Remove special chars
ref = ref.replace('UNIT', '').replace('APT', '').replace('ROOM', '')
return ref






4. STK Push for proactive collection



Instead of waiting for tenants to initiate payment, we can trigger an STK Push — a payment prompt appears on the tenant's phone:




def trigger_stk_push(tenant, amount):
"""Send M-Pesa payment prompt to tenant's phone."""
payload = {
'BusinessShortCode': PAYBILL_NUMBER,
'Amount': amount,
'PartyA': tenant.phone_number,
'PartyB': PAYBILL_NUMBER,
'PhoneNumber': tenant.phone_number,
'AccountReference': tenant.unit.unit_number,
'TransactionDesc': f'Rent for {tenant.unit.unit_number}'
}
response = daraja_api.stk_push(payload)
return response






This is triggered automatically when reminders are sent — the tenant gets an SMS reminder AND a payment prompt simultaneously.






Results




  • Payment matching: 95%+ auto-reconciled without human intervention

  • Receipt delivery: under 10 seconds from payment to SMS receipt

  • Late payment reduction: 40-60% reduction with automated reminders + STK push

  • Admin time saved: 8+ hours/month for a 50-unit portfolio






The Stack





  • Backend: Django + Django REST Framework


  • Database: PostgreSQL


  • Task Queue: Celery + Redis (for async SMS sending and reconciliation)


  • M-Pesa Integration: Safaricom Daraja API v2


  • SMS: Africa's Talking API


  • Hosting: AWS (ECS + RDS + S3)


  • Frontend: React (web) + React Native (mobile)






Try It



The platform is live at homemanager.buniva.co.ke. We handle M-Pesa integration setup for landlords — they do not need to deal with the Daraja API themselves.



If you are building fintech for East Africa and want to discuss M-Pesa integration patterns, happy to connect.






More on property management automation in Kenya: buniva.co.ke/blog

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Automating M-Pesa Rent Collection in Kenya: The Technical Architecture

Thematisch verwandte Begriffe: Automating, MPesa, Rent, Collection · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-17636 | IBM Financial Transaction Manager (FTM) for RedHat OpenShift could allow…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel • Rechts: nächster Artikel • unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger • Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick