Skip to main content

A pluggable Django application for integrating netcash.co.za payment system.

Install

$ pip install django-netcash

or

$ easy_install django-netcash

or

$ hg clone http://bitbucket.org/kmike/django-netcash/
$ cd django-netcash
$ python setup.py install

Then add ‘netcash’ to INSTALLED_APPS and execute

$ python manage.py syncdb

or (if South is in use)

$ python manage.py migrate

If South is used then the NetcashGateway instance will be created. Otherwise go to admin and add the NetcashGateway instance. It is neccessary to have at least one NetcashGateway instance in DB.

Settings

Specify your credentials in settings.py:

  • NETCASH_USERNAME

  • NETCASH_PASSWORD

  • NETCASH_PIN

  • NETCASH_TERMINAL_NUMBER

If your web server is behind reverse proxy you should also specify NETCASH_IP_HEADER option. It’s a request.META key with client ip address (default is ‘REMOTE_ADDR’).

You also have to setup your Netcash account on netcash.co.za. Login into the admin panel, go to ‘credit cards’ section then go to ‘Adjust Gateway Defaults’ and then paste your Data URL. Data URL can be found in django admin changelist page for NetcashGateway model.

Usage

Payment form

netcash.forms.NetcashForm can be used to construct the html form. It is a helper form for html output and it shouldn’t perform any validation.

Pass all the fields to form ‘initial’ argument. Form also has an optional ‘user’ parameter: it is the User instance the order is purchased by. If ‘user’ is specified, ‘m_9’ (cardholder email address) will be filled automatically if it is not passed with ‘initial’.

Example:

# views.py

from django.shortcuts import get_object_or_404
from django.views.generic.simple import direct_to_template
from django.contrib.auth.decorators import login_required

from netcash.forms import NetcashForm

@login_required
def pay_with_netcash(request, order_id)

    # Order model have to be defined by user, it is not a part
    # of django-netcash
    order = get_object_or_404(Order, pk = order_id)

    form = NetcashForm(initial={

        # required params:
        'p3': 'description of the goods',
        'p4': order.total,

        # optional params:

        # 'p10': '/cancel/button/url',
        # 'Budget': 'Y',  # will display the budget option in the Gateway popup
        # 'm_4': 'extra param 1',
        # 'm_5': 'extra param 2',
        # 'm_6': 'extra param 3',
        # 'm_9': order.user.email # cardholder email address
    }, user=order.user)

    return direct_to_template(request, 'pay_with_netcash.html', {'form': form})

The template:

{% extends 'base.html' %}

{% block content %}
    <form action="{{ form.target }}" method="POST">
        <p>{{ form.as_p }}</p>
        <p><input type="submit" value="Pay by Credit Card"></p>
    </form>
{% endblock %}

The {{ form.as_p }} output will be a number of <input type='hidden'> tags.

NetcashForm has a ‘target’ attribute with Netcash URL.

Please note that it’s up to you to implement the order processing logic. Order handling should be performed in netcash.signals.data signal handler.

netcash.signals.data signal

When Netcash posts data to Data URL netcash.signals.data signal is sent. This signal won’t be sent for suspicious data (when request is coming from untrusted ip or form validation fails).

Signal subscribers will get an ‘order’ argument with NetcashOrder instance.

Example:

import netcash.signals

def data_received(sender, **kwargs):
    netcash_order = kwargs['order']

    if netcash_order.TransactionAccepted: # order is paid
        amount = netcash_order.Amount
        # your business logic
        # ...
    else: # order is not paid
        # your business logic
        # ...

netcash.signals.data.connect(data_received)

urls.py

In order to get Data URL, Accept URL and Reject URL up and running, include netcash.urls in your urls.py:

urlpatterns = patterns('',
    #...
    url(r'^netcash/', include('netcash.urls')),
    #...
)

Templates

  • netcash/accept.html - Accept URL page. Has an ‘order’ variable in template context with NetcashOrder instance.

  • netcash/accept.html - Reject URL page. Has an ‘order’ variable in template context with NetcashOrder instance.

Release files for django-netcash 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-netcash 0.4.2
File Size Uploaded
django-netcash-0.4.2.tar.gz 12.1 kB Details

Release files / django-netcash-0.4.2.tar.gz

Download URL django-netcash-0.4.2.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6eeb154dbdec790d045bfa52bde01d7cbf7aa376cb27c04bb0af827697dd851d
BLAKE2b-256 checksum
How to use checksums
faa300d9c1f551bf5e0d90a220535c414cbe42f49f5507aa504480acff9677ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.4.2 This release

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2

1 release file

0.1.11

1 release file

0.1.10

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page