Logo Lanfrica

munuhee/mpesa-payment-service

Domain:

digital infrastructure

Record type:

software
Creator:
mun
Host:
This repository contains a RESTful microservice that integrates with the Daraja API for processing MPESA payments using the C2B Lipa na M-PESA Online API (STK Push Prompt). The service sends payment prompts to customers' phones and updates the transaction status in the database. # Mpesa Payment Service The Lipa na M-PESA Online API, also known as M-PESA Express (STK Push/NI Push), is a merchant-initiated Customer to Business (C2B) payment method. The Lipa na M-PESA online API process is explained below: 1. The Merchant (Partner) captures and sets the API required parameters and sends the API request. 2. The API receives the request and validates it internally first, then sends you an acknowledgment response. 3. Through API Proxy, an STK Push trigger request is sent to the M-PESA registered phone number of the customer's making the payment. 4. The customer confirms by entering their M-PESA PIN. 5. The response is sent back to M-PESA and is processed as below: a) M-PESA validates the customer's PIN b) M-PESA debits the customer's Mobile Wallet. c) M-PESA credits the Merchant (Partner) account. 6. Once the request is processed send the RESULTS back to the API Management system, which is then forwarded to the merchant via the callback URL specified in the REQUEST. 7. The customer receives an SMS confirmation message of the payment. This application allows you to integrate M-Pesa functionalities into your Flask application. It enables features like initiating STK push requests. ## Installation 1. Clone the repository: ```bash git clone github.com cd mpesa-payment-service ``` 2. **Virtual Environment Setup:** - It's a best practice to work within a virtual environment to manage package dependencies. Here's how to set it up based on your operating system: - **For Windows:** ```bash python -m venv venv venv\Scripts\activate ``` - **For macOS/Linux:** ```bash python3 -m venv venv source venv/bin/activate ``` 3. Upgrade `pip` and install the required packages: ```bash python3 -m pip install --upgrade pip pip install -r requirements.txt ``` ## Prerequisites Before you begin, ensure you have the following: - A Safaricom Developer Portal account. Safaricom Developer Portal - Consumer Ke …