runme | ||||
---|---|---|---|---|
|
This backend code is designed to facilitate M-Pesa Stk Push transactions. It includes functionality for generating OAuth tokens, initiating Stk Push transactions, and handling callbacks for transaction status updates.
Before running the backend code, make sure you have the following set up:
- Node.js installed
- npm (Node Package Manager) installed
- MongoDB or another database (For storing transaction data)
- Clone the repository:
git clone https://github.com/Domains18/NodejsDaraja
- Navigate to the project directory:
cd /path/to/your/backend
- Install dependencies:
npm install
- Set up environment variables:
Create a .env
file in the project root and configure the following variables:
CONSUMER_KEY=your_consumer_key
CONSUMER_SECRET=your_consumer_secret
MPESA_SHORTCODE=your_mpesa_shortcode
MPESA_PASSKEY=your_mpesa_passkey
MONGODB_URI=your_mongodb_uri
- Start the server:
npm start
The backend server should now be running.
- Endpoint:
/api/stkpush
- Method:
POST
- Description: Generates an OAuth token required for M-Pesa API requests and innitiates a pushstk request.
-
Endpoint:
/api/callback
-
Method:
POST
-
Description: Handles callbacks from M-Pesa to update transaction status.
-
If you do not have postman or want to use a frontend, click here FrontEnd
- This backend code uses Axios for making HTTP requests.
- Transaction data is stored in a MongoDB database.
- Callbacks from M-Pesa are handled to update the transaction status.
Feel free to customize and extend the backend based on your specific requirements.
This project is licensed under the MIT License.