Back to Blog
M-Pesa Integration

How to Deploy a Captive Portal with M-Pesa Vouchers (Step-by-Step)

Julius Ntale
January 15, 2025
15 min read
Share:
How to Deploy a Captive Portal with M-Pesa Vouchers (Step-by-Step)
# How to Deploy a Captive Portal with M-Pesa Vouchers (Step-by-Step)

💡 Quick Overview for Business Owners:

This comprehensive guide helps you monetize your Wi-Fi hotspot by accepting M-Pesa payments for internet access - perfect for hotels, cafes, and public spaces in Tanzania.

--- ## 🎯 What You'll Achieve

✅ Technical Outcomes

  • • Fully automated M-Pesa voucher system
  • • Professional captive portal interface
  • • Real-time payment verification
  • • Multi-tier pricing options

💰 Business Benefits

  • • Generate revenue from Wi-Fi access
  • • Reduce bandwidth abuse and freeloaders
  • • Professional guest experience
  • • Track usage and optimize pricing
--- ## 📋 Prerequisites & Requirements

🛠️ What You'll Need Before Starting:

Business Requirements:
  • • M-Pesa Business Account (Till Number)
  • • Valid business license in Tanzania
  • • SSL certificate for secure payments
  • • Reliable internet connection (backup recommended)
Technical Requirements:
  • • Network router (TP-Link Omada or UniFi recommended)
  • • Web server (Apache/Nginx)
  • • PHP 7.4+ or Python 3.8+
  • • MySQL/PostgreSQL database

⚠️ Important: M-Pesa API approval can take 2-4 weeks. Start this process first while setting up the technical infrastructure.

--- ## 🚀 Step 1: M-Pesa API Integration Setup

📱 Getting M-Pesa API Access:

1

Register with Safaricom Developer Portal

Visit developer.safaricom.co.ke and create an account

2

Apply for API Keys

Submit business documentation and use case description

3

Get Till Number Integration

Link your existing till number to the API system

### API Configuration Code Sample
// Sample M-Pesa API Configuration (PHP)
class MpesaConfig {
    const CONSUMER_KEY = 'your_consumer_key_here';
    const CONSUMER_SECRET = 'your_consumer_secret_here';
    const ENVIRONMENT = 'sandbox'; // Change to 'production' for live
    const SHORTCODE = 'your_till_number';
    const PASSKEY = 'your_lipa_na_mpesa_passkey';
    const CALLBACK_URL = 'https://yoursite.com/api/mpesa/callback';
    
    // Test credentials for sandbox
    const TEST_SHORTCODE = '174379';
    const TEST_PASSKEY = 'bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919';
}

// Payment initiation function
function initiateMpesaPayment($amount, $phone, $voucher_code) {
    $timestamp = date('YmdHis');
    $password = base64_encode(MpesaConfig::SHORTCODE . MpesaConfig::PASSKEY . $timestamp);
    
    $curl_post_data = [
        'BusinessShortCode' => MpesaConfig::SHORTCODE,
        'Password' => $password,
        'Timestamp' => $timestamp,
        'TransactionType' => 'CustomerPayBillOnline',
        'Amount' => $amount,
        'PartyA' => $phone,
        'PartyB' => MpesaConfig::SHORTCODE,
        'PhoneNumber' => $phone,
        'CallBackURL' => MpesaConfig::CALLBACK_URL,
        'AccountReference' => $voucher_code,
        'TransactionDesc' => 'Wi-Fi Access Voucher'
    ];
    
    return sendMpesaRequest('mpesa/stkpush/v1/processrequest', $curl_post_data);
}
--- ## 🎨 Step 2: Captive Portal Interface Design

🖥️ Portal Design Best Practices:

✅ Essential Elements
  • • Business branding and logo
  • • Clear pricing tiers with time limits
  • • Simple payment instructions in Swahili
  • • Mobile-responsive design (90% of users are mobile)
  • • Progress indicator for payment status
⚠️ Common Mistakes to Avoid
  • • Complex voucher code entry process
  • • No payment status feedback
  • • Missing terms and conditions
  • • No customer support contact
  • • English-only interface
### Recommended Pricing Structure
Package Duration Data Limit Price (TSh) Best For
Basic 1 Hour 500MB 1,000 Quick browsing
Standard 4 Hours 2GB 3,000 Work sessions
Premium 24 Hours 10GB 8,000 Heavy usage
Business 7 Days Unlimited 25,000 Extended stays
--- ## ⚙️ Step 3: Payment Flow Implementation

🔄 Optimized Payment Process:

1

User selects package

Clear pricing display with package benefits

2

System generates unique voucher

8-digit alphanumeric code tied to payment request

3

Payment prompt sent to phone

STK push notification with amount and business name

4

Real-time payment verification

Callback processing and voucher activation

5

Instant internet access

Automatic authentication and session start

--- ## 🌐 Step 4: Router Configuration ### TP-Link Omada Configuration

🔧 Omada Controller Setup:

  1. 1. Access Omada Controller - Navigate to your controller IP (typically 192.168.0.1)
  2. 2. Configure Guest Network - Create separate SSID for guest access
  3. 3. Enable Captive Portal - Go to Settings → Authentication → Captive Portal
  4. 4. Set Portal URL - Point to your custom portal: https://yourhotel.com/portal
  5. 5. Configure Voucher System - Enable voucher authentication with time/data limits
  6. 6. Test Authentication Flow - Verify voucher codes grant proper access
### UniFi Configuration Alternative

🔧 UniFi Dream Machine Setup:

  1. 1. UniFi Network Application - Access through web interface or mobile app
  2. 2. Guest Portal Configuration - Settings → Guest Control → Guest Portal
  3. 3. Custom Portal Template - Upload your branded portal design
  4. 4. Voucher Manager Setup - Configure voucher types and quotas
  5. 5. Bandwidth Profiles - Set speed limits per package tier
--- ## 🧪 Step 5: Testing & Quality Assurance

✅ Complete Testing Checklist:

Payment Testing:
  • • Test with small amounts (TSh 100-500) first
  • • Verify callback URL is accessible
  • • Test payment timeout scenarios
  • • Check duplicate payment handling
  • • Test with different phone number formats
User Experience Testing:
  • • Mobile responsiveness on various devices
  • • Portal loading speed (should be under 3 seconds)
  • • Voucher code entry process
  • • Session timeout and reconnection
  • • Multi-language support (English/Swahili)
--- ## 🚨 Common Challenges & Solutions

❌ Challenge: Payment Verification Delays

Problem: M-Pesa callbacks can be delayed by 30-120 seconds during peak hours.

✅ Solution:

Implement polling mechanism to check payment status every 30 seconds for up to 5 minutes. Show progress indicator to users: "Verifying payment... Please wait"

❌ Challenge: Voucher Code Confusion

Problem: Users struggle with manual voucher code entry, leading to support calls.

✅ Solution:

Implement QR code generation for vouchers. After payment, display QR code that users can scan instead of typing. Also send SMS with voucher code as backup.

❌ Challenge: Power Outages Affecting System

Problem: Tanzania's power grid issues can disrupt service and frustrate paying customers.

✅ Solution:

Install UPS for critical components (router, server, modem). Set voucher validity to extend automatically if power outage is detected. Consider offline voucher validation mode.

❌ Challenge: High Data Consumption

Problem: Users exceed expected data usage, affecting profitability and other users' experience.

✅ Solution:

Implement bandwidth shaping (limit speed instead of data) and block high-bandwidth applications like torrents. Set fair usage policies and offer data top-up options.

--- ## 📊 Revenue Optimization Tips

💰 Maximize Your Wi-Fi Revenue:

1

Dynamic Pricing

Increase prices during peak hours (evening, weekends)

2

Package Bundling

Offer discounted multi-day packages for extended stays

3

Upselling Opportunities

Promote premium packages when basic data is consumed

4

Analytics Integration

Track usage patterns to optimize pricing and capacity

5

Loyalty Programs

Offer repeat customer discounts and referral bonuses

6

Corporate Packages

Create bulk packages for business travelers and events

--- ## 📈 Performance Monitoring & Maintenance

📊 Key Metrics to Track:

📱
Payment Success Rate

Target: >95%

⏱️
Average Session Duration

Track by package type

💰
Daily Revenue

Monitor trends and patterns

--- ## 🏆 Ready to Deploy Your M-Pesa Wi-Fi System?

Get Professional Implementation Support

Don't want to handle the technical complexity? NEURALTALE provides complete M-Pesa captive portal setup services.

✅ Complete Setup

M-Pesa API integration, portal design, and router configuration

✅ Training & Support

Staff training and 24/7 technical support in English and Swahili

✅ Revenue Optimization

Analytics setup and pricing strategy consultation

--- ## ❓ Frequently Asked Questions

Q: How long does M-Pesa API approval take?

A: Typically 2-4 weeks after submitting complete documentation. We can help expedite the process with proper documentation preparation.

Q: What happens if M-Pesa service is down?

A: Implement a backup voucher system where staff can manually generate codes during M-Pesa outages. Always have alternative payment methods available.

Q: Can customers get refunds for unused time?

A: Set clear terms that vouchers are non-refundable but transferable. Consider offering credits for technical issues on your end.

Q: How much revenue can I expect?

A: Depends on location and traffic, but hotels typically generate TSh 200,000-800,000 monthly from Wi-Fi services. Coffee shops see TSh 50,000-200,000 monthly.

Q: Do I need a developer to maintain the system?

A: Basic maintenance can be handled by non-technical staff, but having a developer relationship is recommended for updates and troubleshooting.

--- ## 📋 Next Steps Action Plan

🎯 Your Implementation Timeline:

1

Week 1-2: Apply for M-Pesa API access and gather business documentation

2

Week 2-3: Set up hardware infrastructure (router, server, UPS)

3

Week 3-4: Develop and test captive portal system

4

Week 4-5: Integration testing with M-Pesa sandbox environment

5

Week 5-6: Go live with production system and staff training

💡 Pro Tip: Start with a soft launch offering free vouchers to gather user feedback and identify any issues before full commercial deployment.

---

Need help implementing your M-Pesa captive portal? Contact NEURALTALE for professional setup and ongoing support services.

Legal and Compliance Considerations

Ensure compliance with:

  • Tanzania Communications Regulatory Authority (TCRA) requirements
  • Data protection regulations
  • M-Pesa terms of service
  • Local business licensing requirements

Pricing Strategy

Based on our experience with 50+ deployments in Tanzania, here are recommended pricing tiers:

  • 1 Hour: 500 TZS
  • 4 Hours: 1,500 TZS
  • 24 Hours: 3,000 TZS
  • Weekly: 15,000 TZS

Maintenance and Monitoring

Set up monitoring for:

  • Payment success rates
  • System uptime
  • User complaints
  • Revenue tracking

Need Professional Implementation?

While this guide provides a comprehensive overview, implementing a production-ready captive portal with M-Pesa integration requires technical expertise. Our team at Neuraltale Technologies has deployed similar systems for over 50 businesses across Tanzania.

Contact us for:

  • Complete system setup and configuration
  • M-Pesa API approval assistance
  • Custom branding and design
  • Ongoing technical support
Tags:
M-PesaCaptive PortalWi-Fi HotspotTutorial

Need Help Implementing This Solution?

Our expert team can help you deploy and configure these technologies for your business.