Overview
VoicePact integrates Africa’s Talking mobile money services to enable secure escrow-based payments for agricultural contracts. The system supports mobile checkout, payment verification, and automated escrow management.Payment Architecture
Payment Flow
Payment States
Configuration
Environment Variables
Payment Configuration Class
Fromapp/core/config.py:262-287:
Mobile Checkout
Initiating Checkout
Start a mobile money checkout from the buyer’s account:Payment Request Model
Fromapp/api/v1/endpoints/payments.py:19-24:
API Endpoint
Endpoint:POST /api/v1/payments/checkout
From app/api/v1/endpoints/payments.py:36-93:
Webhook Handling
Payment Webhook
Receive payment status updates from Africa’s Talking: Endpoint:POST /api/v1/payments/webhook
From app/api/v1/endpoints/payments.py:96-136:
Webhook Payload Format
Success Webhook:Escrow Management
Locking Funds in Escrow
When payment is confirmed, funds are locked until delivery:Releasing Escrow
Release funds to seller after delivery confirmation:Refunding Payment
Refund payment if contract is cancelled or disputed:Payment Query
Get Payment Status
Endpoint:GET /api/v1/payments/{payment_id}
Get Contract Payments
Endpoint:GET /api/v1/payments/contract/{contract_id}
From app/api/v1/endpoints/payments.py:170-200:
Transaction Queries
Query Transaction Status
Query Africa’s Talking for transaction details:Check Wallet Balance
Endpoint:GET /api/v1/payments/wallet/balance
From app/api/v1/endpoints/payments.py:230-241:
Payment Notifications
SMS Notifications
Send payment confirmation messages:USSD Payment Status
Check payment status via USSD:Error Handling
Common Payment Errors
Retry Logic
Automatic retry for transient failures:Testing
Test Payment Endpoint
Endpoint:POST /api/v1/payments/test/checkout
From app/api/v1/endpoints/payments.py:203-227:
Sandbox Testing
Use Africa’s Talking sandbox credentials:Best Practices
- Validate Amounts: Always validate min/max payment amounts
- Store Transaction IDs: Keep external transaction IDs for reconciliation
- Handle Timeouts: Set appropriate escrow timeouts
- Verify Webhooks: Always verify webhook authenticity
- Notify Users: Send SMS confirmations for all payment events
- Monitor Escrow: Track escrow expiration times
- Handle Failures: Implement proper error handling and retry logic
- Reconcile Daily: Regular reconciliation with AT transaction logs
Security Considerations
Webhook Security
Amount Validation
Phone Number Validation
Troubleshooting
Payment Not Processing
- Check API credentials: Verify AT_USERNAME and AT_API_KEY
- Verify phone number: Ensure correct format (+254…)
- Check amount: Verify within min/max limits
- Review logs: Check application logs for errors
- Test webhook: Ensure webhook URL is accessible
Webhook Not Receiving
- Verify URL: Check WEBHOOK_BASE_URL is correct and accessible
- Check firewall: Ensure port 443/80 is open
- Test signature: Verify WEBHOOK_SECRET matches
- Review AT dashboard: Check webhook configuration
Escrow Release Failing
- Check payment status: Verify payment is in LOCKED state
- Verify recipient: Ensure seller phone number is valid
- Check wallet balance: Ensure sufficient funds in AT wallet
- Review timeout: Check if escrow has expired
Next Steps
Africa's Talking
Core AT integration documentation
Webhooks
Complete webhook configuration
Contract Flow
Contract lifecycle management
API Reference
Payment API documentation