Price: $0.08493 -3.6877%
Market Cap: $14.58B 0.5316%
Volume (24h): 1.18B 0%
Dominance: 0.5316%
Price: $0.08493 -3.6877%
Market Cap: $14.58B 0.5316%
Volume (24h): 1.18B 0%
Dominance: 0.5316% 0.5316%
  • Price: $0.08493 -3.6877%
  • Market Cap: 14.58B 0.5316%
  • Volume (24h): 1.18B 0%
  • Dominance: 0.5316% 0.5316%
  • Price: $0.08493 -3.6877%
Home > 视频 > How to Integrate M-Pesa API with Django | Daraja STK Push Tutorial (Python)

How to Integrate M-Pesa API with Django | Daraja STK Push Tutorial (Python)

Release: 2026/09/20 05:00 Reading: 0

Original author:DevNook

Original source:https://www.youtube.com/embed/G8mbH5rPq5I

Learn how to integrate M-Pesa payments into Django using Safaricom’s Daraja API and STK Push. In this step-by-step tutorial, we build a simple Django payment application called PayFlow and connect it to the M-Pesa Daraja sandbox. You’ll learn how to: * Set up a Django payment application * Connect Django to the Daraja API * Authenticate with Daraja using OAuth * Send an M-Pesa STK Push * Receive M-Pesa callbacks * Use `CheckoutRequestID` to track payments * Handle successful and failed payments * Store the M-Pesa receipt in the database * Use ngrok for local callback testing M-Pesa Payment Flow User enters phone number and amount - Django creates a pending payment - Daraja authenticates the request - Django sends an STK Push - Customer enters their M-Pesa PIN - M-Pesa processes the payment - Daraja sends a callback - Django updates the payment - Payment becomes successful or failed What We Build A simple Django + M-Pesa payment dashboard where you can make payments and track their status. Technologies * Python * Django * M-Pesa Daraja API * STK Push * SQLite * Requests * python-dotenv * ngrok Chapters 00:00 - Introduction & Finished Application 00:00 - M-Pesa Payment Flow 00:00 - Django Project Setup 00:00 - Payment Model & Form 00:00 - Payment Dashboard 00:00 - Safaricom Daraja Setup 00:00 - OAuth Access Token 00:00 - Phone Number Formatting 00:00 - STK Push 00:00 - M-Pesa Callback 00:00 - ngrok Setup 00:00 - Handling Successful & Failed Payments 00:00 - Storing M-Pesa Receipt 00:00 - Testing the Payment Flow 00:00 - Common Errors 00:00 - Final Walkthrough Important An STK Push being accepted does not mean the payment was successful. Daraja first accepts the STK Push request and gives us a `CheckoutRequestID`. The final payment result is sent later through the M-Pesa callback. This tutorial shows how Django uses that callback to update the payment as successful or failed. Resources Safaricom Daraja: https://developer.safaricom.co.ke/ GitHub repository: https://github.com/ceciliawambui/payflow Notes: https://getdevnook.com/topics/python-django-framework-integrating-m-pesa-pyments-in-django-apps If you're learning JS, React, Python, Django, APIs, and real-world software development, subscribe for more practical tutorials. #Django #MPesa #DarajaAPI #Python #STKPush #MPesaAPI #DjangoTutorial #PythonDjango #Safaricom #KenyaDevelopers

Selected Topics

  • Dogecoin whale activity
    Dogecoin whale activity
    Get the latest insights into Dogecoin whale activities with our comprehensive analysis. Discover trends, patterns, and the impact of these whales on the Dogecoin market. Stay informed with our expert analysis and stay ahead in your cryptocurrency journey.
  • Dogecoin Mining
    Dogecoin Mining
    Dogecoin mining is the process of adding new blocks of transactions to the Dogecoin blockchain. Miners are rewarded with new Dogecoin for their work. This topic provides articles related to Dogecoin mining, including how to mine Dogecoin, the best mining hardware and software, and the profitability of Dogecoin mining.
  • Spacex Starship Launch
    Spacex Starship Launch
    This topic provides articles related to SpaceX Starship launches, including launch dates, mission details, and launch status. Stay up to date on the latest SpaceX Starship launches with this informative and comprehensive resource.
  • King of Memes: Dogecoin
    King of Memes: Dogecoin
    This topic provides articles related to the most popular memes, including "The King of Memes: Dogecoin." Memecoin has become a dominant player in the crypto space. These digital assets are popular for a variety of reasons. They drive the most innovative aspects of blockchain.