Coder Social home page Coder Social logo

metatrevor / django-pesapal Goto Github PK

View Code? Open in Web Editor NEW

This project forked from odero/django-pesapal

0.0 1.0 0.0 197 KB

A django port of pesapal payment gateway

Home Page: https://pypi.python.org/pypi/django-pesapal

License: BSD 3-Clause "New" or "Revised" License

Makefile 6.13% Python 87.71% HTML 6.16%

django-pesapal's Introduction

django-pesapal

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_pesapal
  1. Add django_pesapal to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = (
        ...
        'django_pesapal',
    )
    
  2. Include the django_pesapal URLconf in your project urls.py like this:

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

This is optional. You can set your own return url by adding this to settings.py:

PESAPAL_OAUTH_CALLBACK_URL = 'app_name:url_name'  # this needs to be a reversible

The url has the 'merchant_reference' GET parameter which can be extracted for further processing, or ignored.

for example it can be extracted using

self.merchant_reference = request.GET.get('merchant_reference', '')

in the destination view set as the PESAPAL_OAUTH_CALLBACK_URL.

  1. Run python manage.py syncdb to create the models.

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

    from django_pesapal.app import get_payment_url
    
    def get_pesapal_payment_iframe():
        '''
        Authenticates with pesapal to get the payment iframe src
        '''
    
        order_info = {
            'amount': 100,
            'description': 'Payment for X',
            'reference': 2,  # some object id
            'email': '[email protected]'
        }
    
        iframe_src_url = get_payment_url(**order_info)
        return iframe_src_url
    

NB: get_payment_url is defined as:

def get_payment_url(**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`
    '''
  1. get_payment_status is used get the payment status and is defined as:

    def get_payment_status(**kwargs):
    
        '''
        Query the payment status from pesapal using the transaction id and the merchant reference id
    
        Params should include the following keys:
            Required params: `pesapal_merchant_reference`, `pesapal_transaction_tracking_id`
        '''
    
    
    # It returns a dictionary with the following keys
    
        response_data['_raw_request']    # The params that the request were made with
        response_data['_raw_response']   # Useful for debugging
        response_data['_comm_success']   # A bool communication status
        response_data['_payment_status'] # The payment status
        response_data['_response_time']  # Time taken for the response
    

Configuration

Setting Default Value
PESAPAL_DEMO True
PESAPAL_CONSUMER_KEY ''
PESAPAL_CONSUMER_SECRET ''
PESAPAL_IFRAME_LINK (if PESAPAL_DEMO=True) 'http://demo.pesapal.com/api/PostPesapalDirectOrderV4'
PESAPAL_IFRAME_LINK (if PESAPAL_DEMO=False) 'https://www.pesapal.com/api/PostPesapalDirectOrderV4'
PESAPAL_QUERY_STATUS_LINK (Demo Mode=True) 'http://demo.pesapal.com/API/QueryPaymentStatus'
PESAPAL_QUERY_STATUS_LINK (Demo Mode=False) 'https://www.pesapal.com/API/QueryPaymentStatus'
PESAPAL_OAUTH_CALLBACK_URL 'transaction_completed'
PESAPAL_OAUTH_SIGNATURE_METHOD 'SignatureMethod_HMAC_SHA1'
PESAPAL_TRANSACTION_DEFAULT_REDIRECT_URL ''
PESAPAL_TRANSACTION_FAILED_REDIRECT_URL ''
PESAPAL_REDIRECT_WITH_REFERENCE True

django-pesapal's People

Contributors

odero avatar metatrevor 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.