Giter Site home page Giter Site logo

daviskamau / nodejsdaraja Goto Github PK

View Code? Open in Web Editor NEW

This project forked from domains18/nodejsdaraja

0.0 0.0 0.0 560 KB

A simple REST API service built with javascript, express and mongodb showing how to use daraja API by safaricom to intergrate payments for eccommerce app. It utilises the Express STK push to prompt the customer to authenticate the request by the input of their Mpesa pin

JavaScript 93.58% CSS 2.86% HTML 3.57%

nodejsdaraja's Introduction

M-Pesa Stk Push Backend

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.

Prerequisites

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)

Installation

  1. Clone the repository:
git clone https://github.com/Domains18/NodejsDaraja
  1. Navigate to the project directory:
cd /path/to/your/backend
  1. Install dependencies:
npm install
  1. 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
  1. Start the server:
npm start

The backend server should now be running.

Endpoints

1. Generate OAuth Token and PushStk

  • Endpoint: /api/stkpush
  • Method: POST
  • Description: Generates an OAuth token required for M-Pesa API requests and innitiates a pushstk request.

3. Callback for Transaction Status

  • 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

Additional Information

  • 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.

License

This project is licensed under the MIT License.


nodejsdaraja's People

Contributors

domains18 avatar dependabot[bot] avatar japhethmutai avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.