Giter VIP home page Giter VIP logo

flask-daraja-api's Introduction

Flask M-Pesa Integration

This application allows you to integrate M-Pesa functionalities into your Flask application. It enables features like initiating STK push requests.

Prerequisites

Before you begin, ensure you have the following:

  • A Safaricom Developer Portal account. Safaricom Developer Portal
  • Consumer Key and Consumer Secret obtained from the Safaricom Developer Portal.
  • Test credentials assigned to you by Safaricom.

Setup

  1. Environment Configuration:

    • Create a .env file in the root directory of your Flask project.

    • Add the following credentials to your .env file:

      # Secret Key
      SECRET_KEY= # Your Safaricom Secret Key
      
      # Daraja API credentials
      CONSUMER_KEY= # Your Safaricom Consumer Key
      CONSUMER_SECRET= # Your Safaricom Consumer Secret
      SHORTCODE= # Your Safaricom Short Code
      PASSKEY= # Your Passkey
      
      # Database URI
      SQLALCHEMY_DATABASE_URI= # Your  Database URI
  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:
        python -m venv venv
        venv\Scripts\activate
      • For macOS/Linux:
        python3 -m venv venv
        source venv/bin/activate
  3. Environment Activation:

    • Once the virtual environment is activated, depending on your operating system, run the appropriate command to source the .env file:

      • For Linux/MacOS:
        source .env
      • For Windows:
        call setenv.bat

Database Migration

To manage database migrations, follow these steps:

  1. Initialize the migration environment:

    flask db init
  2. Create an initial migration:

    flask db migrate -m "Initial migration"
  3. Apply the migration to the database:

    flask db upgrade

Usage

Endpoints

  1. Initiate M-Pesa STK Push

    • Endpoint: /initiate_mpesa_stk_push
    • Methods: POST, GET
    • Description: Initiate STK push for M-Pesa payment.
  2. View Records

    • Endpoint: /view_records
    • Method: GET
    • Description: View M-Pesa transaction records.

flask-daraja-api's People

Contributors

munuhee avatar

Stargazers

 avatar

Watchers

 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.