Skip to main content

A django port of pesapal payment gateway

Project description Development Status

A django port of pesapal payment gateway


The full documentation is at


Install django-pesapal:

pip install django-pesapal

Then use it in a project:

import django_pesapal
  1. Add django_pesapal to your INSTALLED_APPS setting like this:

  2. Include the django_pesapal URLconf in your project like this:

    url(r'^payments/', include('django_pesapal.urls')),

You can set your own return url by adding this to

PESAPAL_TRANSACTION_DEFAULT_REDIRECT_URL = 'app_name:url_name'  # this needs to be a reversible
  1. Run python migrate to create the models.

  2. Create a method that receives payment details and returns the pesapal iframe url:

    from django_pesapal.views import PaymentRequestMixin
    class PaymentView(PaymentRequestMixin):
        def get_pesapal_payment_iframe(self):
            Authenticates with pesapal to get the payment iframe src
            order_info = {
                'first_name': 'Some',
                'last_name': 'User',
                'amount': 100,
                'description': 'Payment for X',
                'reference': 2,  # some object id
                'email': '',
            iframe_src_url = self.get_payment_url(**order_info)
            return iframe_src_url

# Once payment has been processed, you will be redirected to an intermediate screen where the user can check the payment status to ensure that the payment was successful.

NB: get_payment_url is defined as:

def get_payment_url(self, **kwargs):
    Use the computed order information to generate a url for the Pesapal iframe.

    Params should include the following keys:
        Required params: `amount`, `description`, `reference`, `email`
        Optional params: `first_name`, `last_name`

#. PaymentRequestMixin also defins get_payment_status, which can be used check the payment status. The intermediate screen has a button for checking the payment status. Clicking on the button automatically checks the current status on the server and then notifies the user.


Setting Default Value
PESAPAL_OAUTH_CALLBACK_URL ‘transaction_completed’


0.3.2 (2015-06-13)

  • Fix documentation formatting issues

0.3.1 (2015-06-13)

  • Allow specifying own transaction model
  • Pass all transaction info when redirecting
  • Update intermediate template

0.3 (2015-06-12)

  • Introduce intermediate payment processing screen
  • Update Django version to 1.7+
  • Add support to receive and process IPN
  • Save all details about the transaction and status

0.2.1 (2015-04-03)

  • Added test sandbox
  • Updated Django version
  • Updated django-uuidfield

0.2 (2015-03-17)

  • Support anonymous checkouts
  • Add support for getting payment status
  • Major structural refactoring. Use mixins
  • Use Mixins and XML Builder

0.1.5 (2014-09-25)

  • Pin dependencies to specific versions
  • Update how imports should be done
  • Remove imports from

0.1.4 (2014-09-23)

  • Fix import bug. Tests for projects using this fail in Shippable
  • Set max Django version to 1.7

0.1.3 (2014-07-18)

  • Packaging for PyPi

0.1.2 (2014-06-30)

  • Fix import bug in
  • Fix how callback url is constructed
  • Fix: Live URL uses https

0.1.1 (2014-06-30)

  • Refactor handling of redirect urls. Model validation of transaction and merchant reference
  • Rename settings to conf. Set default oauth redirect url
  • Add django-uuidfield to dependencies

0.1.0 (2014-06-30)

  • First release on PyPI.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-pesapal, version 0.3.2
Filename, size File type Python version Upload date Hashes
Filename, size django_pesapal-0.3.2-py2.py3-none-any.whl (13.9 kB) File type Wheel Python version 2.7 Upload date Hashes View
Filename, size django-pesapal-0.3.2.tar.gz (10.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page