M-Pesa Kenya Payment Gateway for Moodle
This plugin provides integration with M-Pesa Kenya’s payment system for Moodle, allowing your site to accept payments via M-Pesa’s mobile money service.
Features
- Seamless integration with M-Pesa’s Daraja API
- Support for both sandbox and production environments
- Secure payment processing with transaction verification
- Support for all M-Pesa payment methods (STK Push, Paybill, Till Number)
- Comprehensive transaction logging
- Mobile-friendly payment interface
- Support for multiple currencies (KES, USD, etc.)
Requirements
- Moodle 4.1 or later
- PHP 7.4 or later
- cURL extension enabled
- OpenSSL extension enabled
- M-Pesa Daraja API credentials (Consumer Key and Secret)
- Valid M-Pesa Paybill or Till Number
Installation
- Copy the
mpesakenya folder to moodle/payment/gateway/
- Log in to your Moodle site as an administrator
- Go to Site administration > Notifications
- Follow the on-screen instructions to complete the installation
- Configure the plugin (see Configuration section below)
Configuration
- Go to Site administration > Plugins > Payment gateways > Manage payment gateways
- Click on the eye icon to enable the M-Pesa Kenya payment gateway
- Click on “Settings” to configure the gateway
- Enter the following information:
- Consumer Key: Your M-Pesa Daraja API Consumer Key
- Consumer Secret: Your M-Pesa Daraja API Consumer Secret
- Shortcode: Your M-Pesa Paybill or Till Number
- Passkey: Your M-Pesa API Passkey
- Environment: Select either Sandbox (for testing) or Production
- Callback URL: Use the provided URL in your M-Pesa Daraja API settings
Setting up M-Pesa Daraja API
- Register for an account at Safaricom Developer Portal
- Create a new app to get your Consumer Key and Secret
- Request for STK Push permissions for your app
- Whitelist your server’s IP address in the Daraja portal
- Configure the callback URL in the Daraja portal to point to:
https://your-moodle-site.com/payment/gateway/mpesakenya/callback.php
Testing
Before going live, test the payment gateway in sandbox mode:
- Set the environment to “Sandbox” in the plugin settings
- Use the test credentials provided by M-Pesa
- Make a test payment using a test phone number
- Verify that the payment is recorded in Moodle
Going Live
- Test all payment flows thoroughly in sandbox mode
- Request to go live from the Safaricom Developer Portal
- Update the plugin settings with your production credentials
- Change the environment to “Production”
- Test the payment gateway with a small amount before processing real payments
Support
For support, please open an issue in the GitHub repository or contact the plugin maintainer.
License
This plugin is licensed under the GNU General Public License v3.0. See the LICENSE file for details.
Contributing
Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.
Security
If you discover any security issues, please report them to the maintainer directly instead of using the issue tracker.
Changelog
1.0.0 (2024-09-18)
- Initial release
- Support for M-Pesa STK Push
- Sandbox and production environments
- Transaction logging
- Mobile-friendly interface