Welcome to the Django Mpesa Daraja repository! This project integrates the M-Pesa Daraja API with a Django application using the django-daraja-api
package, enabling seamless mobile payments in your Django projects.
- M-Pesa Integration: Easily integrate M-Pesa payment processing with Django.
- STK Push: Initiate STK Push requests directly from your Django app.
- Transaction Status: Query the status of M-Pesa transactions.
- Transaction Reversal: Reverse M-Pesa transactions from your Django app.
- Secure: Handles M-Pesa credentials and tokens securely.
- Clone the repository:
git clone https://github.com/yourusername/django-mpesa-daraja.git
cd django-mpesa-daraja
- Create a virtual environment:
python3 -m venv env
source env/bin/activate
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables: Create a .env file in the root of the project and add your M-Pesa credentials:
MPESA_CONSUMER_KEY=your_consumer_key
MPESA_CONSUMER_SECRET=your_consumer_secret
MPESA_SHORTCODE=your_shortcode
MPESA_PASSKEY=your_passkey
MPESA_ENV=sandbox # or 'production'
- Apply migrations:
python manage.py migrate
- Run the development server:
python manage.py runserver
Once the server is running, you can initiate M-Pesa STK Push requests, check transaction statuses, and more using the API endpoints provided by the django-daraja-api package.
from daraja.mpesa import MpesaClient
mpesa_client = MpesaClient()
response = mpesa_client.stk_push(phone_number, amount, account_reference, transaction_desc)
Refer to the django-daraja-api documentation for more detailed usage instructions.
We welcome contributions! Please fork this repository, create a new branch, and submit a pull request.