How alphacodeke/alphacode-shop works
Alphacode Shop is a Django M-Pesa STK Push payment application. A customer uses the payment page to submit a phone number and amount; the server validates the request, records a pending transaction, and requests an STK push from Safaricom. Safaricom later posts a callback, which updates the transaction record; the page can display transaction status and history. The README also describes automatic status updates and sandbox/production support. The graph follows the sampled routes and source calls; UI behavior beyond the excerpts is represented only where documented.
Main entry points: mpesa_api.py STK and query API · views.py Payment and callback views · index.html Payment page · urls.py App routes
Components 11
Payment interface
- Payment page
mpesa_app/templates/mpesa_app/index.html
Django payment app
- App routes
mpesa_app/urls.py - Payment and callback views
mpesa_app/views.py - Status and history views
mpesa_app/views.py - Django and M-Pesa settings
alphacode_shop/settings.py
M-Pesa integration
- STK and query API
mpesa_app/mpesa_api.py - Credentials and token
mpesa_app/mpesa_credentials.py
Transaction state
- Transaction model
mpesa_app/models.py - SQLite transaction store
alphacode_shop/settings.py
Other components
- Customer
- Safaricom Daraja
Connections 13
- Customer → Payment page: uses
readme.md - Payment page → App routes: submits requests
readme.md - App routes → Payment and callback views: routes payment and callback
mpesa_app/urls.py - App routes → Status and history views: routes status and history
mpesa_app/urls.py - Payment and callback views → Transaction model: creates and updates
mpesa_app/views.py - Payment and callback views → STK and query API: initiates STK push
mpesa_app/views.py - Status and history views → Transaction model: reads status and history
mpesa_app/views.py - Transaction model → SQLite transaction store: persists records
alphacode_shop/settings.py - STK and query API → Credentials and token: gets token and password
mpesa_app/mpesa_api.py - STK and query API → Django and M-Pesa settings: reads configuration
mpesa_app/mpesa_api.py - STK and query API → Safaricom Daraja: sends API requests
mpesa_app/mpesa_api.py - Safaricom Daraja → Payment and callback views: posts payment callback
readme.md - Payment page → Status and history views: refreshes transaction status
readme.md