Code Monkey home page Code Monkey logo

django-daraja's Introduction

Daraja logo

django-daraja

This is a django library based on the Safaricom MPESA daraja API. This is a django library based on the Safaricom MPESA daraja API. Use it for a simplified experience, spend less time setting up...

Build Status Documentation Status License: MIT PyPI version PyPI - Python Version

Read the full documentation at https://django-daraja.readthedocs.io

MPESA Daraja API documentation can be found at https://developer.safaricom.co.ke

Installation

To install the package, run

$ pip install django_daraja

Examples

STK Push

An example, to send an STK push prompt to customer phone, then display response message

    from django_daraja.mpesa.core import MpesaClient

    def index(request):
        cl = MpesaClient()
        phone_number = '0700111222'
        amount = 1
        account_reference = 'reference'
        transaction_desc = 'Description'
        callback_url = request.build_absolute_uri(reverse('mpesa_stk_push_callback'))
        response = cl.stk_push(phone_number, amount, account_reference, transaction_desc, callback_url)
        return HttpResponse(response)

On your browser, you will receive a message Success. Request accepted for processing on success of the STK push. You will also receive a notification on the callback endpoint (In this case the URL with the name mpesa_stk_push_callback), having the results of the STK push.

B2C Payment

An example, to perform a BusinessPayment B2C (Business to Customer) transaction

    from django_daraja.mpesa.core import MpesaClient

    def index(request):
        cl = MpesaClient()
        phone_number = '0700111222'
        amount = 1
        transaction_desc = 'Business Payment Description'
        occassion = 'Test business payment occassion'
        callback_url = request.build_absolute_uri(reverse('mpesa_business_payment_callback'))
        response = cl.business_payment(phone_number, amount, transaction_desc, callback_url, occassion)
        return HttpResponse(response)

On your browser, you will receive a message Accept the service request successfully. on success of the transaction. You will also receive a notification on the callback endpoint (In this case the URL with the name mpesa_business_payment_callback), having the results of the Business Payment Transaction.

Note

You need a callback URL connected to the internet to receive the asynchronous result. In case you don't have one you can head over to http://darajambili.herokuapp.com and grab a callback URL to test the result.

The full documentation of all supported API's can be found at http://django-daraja.readthedocs.io

django-daraja's People

Contributors

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