Skip to main content

A django port of pesapal payment gateway

Project description

https://badge.fury.io/py/django-pesapal.png https://travis-ci.org/odero/django-pesapal.png?branch=master https://coveralls.io/repos/odero/django-pesapal/badge.png?branch=master Development Status

A django port of pesapal payment gateway

Documentation

The full documentation is at https://django-pesapal.readthedocs.org.

Quickstart

Install django-pesapal:

pip install django-pesapal

Then use it in a project:

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

    INSTALLED_APPS = (
        ...
        'django_pesapalv3',  # use this if using v3 api
        # 'django_pesapal',   # use this if using v1/classic api
    )
  2. Include the django_pesapal URLconf in your project urls.py like this:

    url(r"^v3/payments", include("django_pesapalv3.urls")),
    # url(r'^payments/', include('django_pesapal.urls')),  # use this if using v1/classic api
  3. You can set your own return url by adding this to settings.py:

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

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

    from django_pesapalv3.views import PaymentRequestMixin
    
    class PaymentView(PaymentRequestMixin, TemplateView):
    
        def get_pesapal_payment_iframe(self):
    
            '''
            Authenticates with pesapal to get the payment iframe src
            '''
            ipn = self.get_default_ipn()  # you can replace this with your own ipn registration method
    
            order_info = {
                "id": self.request.GET.get("id", uuid.uuid4().hex),  # replace this with a valid merchant id
                "currency": "KES",
                "amount": 10,
                "description": "Payment for X",
                "callback_url": self.build_url(
                    reverse("django_pesapalv3:transaction_completed")
                ),
                "notification_id": ipn,
                "billing_address": {
                    "first_name": "John",
                    "last_name": "Doe",
                    "email": "pesapal@example.com",
                },
            }
            req = self.submit_order_request(**order_info)
            iframe_src_url = req["redirect_url"]
            return iframe_src_url
  6. In case you are using v1/classic api, use this instead:

    from django_pesapal.views import PaymentRequestMixin
    
    class PaymentView(PaymentRequestMixin, TemplateView):
    
        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': 'user@example.com',
            }
    
            iframe_src_url = self.get_payment_url(**order_info)
            return iframe_src_url
  7. Once payment has been processed, you will be redirected to an intermediate screen where the user can finish ordering. Clicking the “Check status” button will check the payment status to ensure that the payment was successful and then redirects the user to PESAPAL_TRANSACTION_DEFAULT_REDIRECT_URL.

Configuration

Setting

Default Value

PESAPAL_DEMO

True

PESAPAL_CONSUMER_KEY

‘’

PESAPAL_CONSUMER_SECRET

‘’

PESAPAL_OAUTH_CALLBACK_URL

‘transaction_completed’

PESAPAL_OAUTH_SIGNATURE_METHOD

‘SignatureMethod_HMAC_SHA1’

PESAPAL_TRANSACTION_DEFAULT_REDIRECT_URL

‘/’ or ‘/v3/’

PESAPAL_TRANSACTION_FAILED_REDIRECT_URL

‘’

PESAPAL_REDIRECT_WITH_REFERENCE

True

PESAPAL_TRANSACTION_MODEL

‘django_pesapal.Transaction’

PESAPAL_IPN_URL (for v3)

‘django_pesapalv3:transaction_ipn’

PESAPAL_CALLBACK_URL (for v3)

‘django_pesapalv3:transaction_completed’

History

2.0 (2024-12-27)

  • Support for Django 5.1

  • Update dependencies

  • Support Py310, Py311

  • Add support for pesapal v3 API

  • Breaking change - Update Transaction model - change merchant_reference field from int to string

  • Add payment_account field to Transaction model

1.3.3 (2023-01-26)

  • Bug fix: Handling invalid data

1.3.2 (2022-01-21)

  • Support for Django 3.9

  • Update dependencies

  • Support Py38, Py39

  • Remove EOL py27

1.3.1 (2019-07-16)

  • Update dependencies

  • Support Py37

  • Remove EOL py34

1.3.0 (2018-09-29)

  • Support for Django 2.1

  • Support Py36

1.2.0 (2016-12-11)

  • Dropped support for Django 1.7

  • Fixes and Upgrades to support Django 1.8 - 1.10

  • Use Django’s UUIDField

1.1.0 (2016-05-03)

  • Support Django 1.9

  • Update payment_method field length from 16 to 24

  • Remove support for Py33. Support Py35

1.0.1 (2015-11-21)

  • Fix querydict bug

1.0.0 (2015-11-11)

  • Support Django 1.8

  • Support Py33 and Py34

  • Return proper IPN response

0.3.4 (2015-08-12)

  • Restructure flow to better support IPN processing

0.3.3 (2015-06-29)

  • Setup build had not packaged the templates

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 __init__.py

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 urls.py

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

Source Distribution

django-pesapal-2.0.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

django_pesapal-2.0-py2.py3-none-any.whl (21.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-pesapal-2.0.tar.gz.

File metadata

  • Download URL: django-pesapal-2.0.tar.gz
  • Upload date:
  • Size: 20.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for django-pesapal-2.0.tar.gz
Algorithm Hash digest
SHA256 bdc1bc1e615f9f4662d114c09fdc246a97ec504ab25a263c059bcf1d09817f1e
MD5 9f55802888b4545b5c3096e97a8d9f0f
BLAKE2b-256 3659b8d69306ceb89093eeb3d1001006f2120d53352f4f20d4c81a6db18823ee

See more details on using hashes here.

File details

Details for the file django_pesapal-2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_pesapal-2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9bff8669cc71cc19fc16b4de6812ef18211b56ba7d8cf0a7acec31cbbd95f319
MD5 5b14865203ca3265303df5d1d471d0f3
BLAKE2b-256 9457b5ee9bac9266a70ee7c42e8b0d10bdbf441c061c93556090d1ea2befaef9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page