Package: django-touchnet
Django app for Touchnet integration built for KDVS Fundraiser based on Ecollege.OverviewEach payment is associated with atransaction_idthat can be any string
without whitespace but is typically a primary key.The app includes a basic template tag that has a form with Bootstrap classes
that can be used to redirect to Touchnet.There are two signals forpayment_receivedandpayment_cancelledthat
will trigger on postbacks from Touchnet.ThePostbackLogmodel stores all transactions, what was received and
returned, and is registered in the admin.The test card is5454545454545454for Mastercard.InstallationDownload from Bitbucket and install in virtual environment withpip installdjango-touchnet-x.x.tar.gz.ConfigurationInclude inINSTALLED_APPS:INSTALLED_APPS = (
    ...
    'touchnet',
    ...
)Include the required settings in your base settings, for example for development:TOUCHNET = {
    'accounting': {
        'fid': '117', # FID number for account
        'fau': '3804148111300', # FAU number for account
    },
    'posting_key': 'CM-KDVS-jfeiowajfiewao', # Random posting key for site in Touchnet Test
    'site_id': '24', # Site id in Touchnet Test
    'url': 'https://secure.touchnet.com:8443/C21642test_upay/web/index.jsp', # Touchnet Test endpoint
}And similarly for production settings:TOUCHNET = {
    'accounting': {
        'fid': '117',
        'fau': '3804148111300',
    },
    'posting_key': 'CM-KDVS-jfeaiwjfeioaw',
    'site_id': '17',
    'url': 'https://marketplace.ucdavis.edu/C21642_upay/web/index.jsp', # Production Touchnet endpoint
}Include the URLs for postback in yoururls.py:urlpatterns = patterns('',
    ...
    url(r'^touchnet/', include('touchnet.urls')),
    ...
)Also include URLs for success, error, and cancel redirects back, e.g.:urlpatterns = patterns('fundraiser.views',
    ...
    url(r'^donate/success/$', 'donate_success_detail',
            name='fundraiser_donate_success_detail'), # Touchnet success
    url(r'^donate/error/$', 'donate_error_detail',
            name='fundraiser_donate_error_detail'), # Touchnet error
    url(r'^donate/cancel/$', 'donate_cancel_detail',
            name='fundraiser_donate_cancel_detail'), # Touchnet cancel
    ...
)Finally, log into Touchnet and verify the postback URL, posting key, success
URL, error URL, and cancel URL settings match. The postback URL should end in/touchnet/postback, e.g.https://fundraiser.kdvs.org/touchnet/postback.
The URL must behttpsand the SSL certificate and IP address of the server
must be allowed by Touchnet.UsageTo process payments, connect receivers to signals inmodels.py, optionally
connect one for cancellations e.g.:# Receivers

def received_payment(sender, **kwargs):
    amount = kwargs['amount']
    transaction_id = kwargs['transaction_id']

    pledge = Pledge.objects.get(pk=transaction_id)
    pledge.amount_paid = amount
    pledge.save()
payment_received.connect(received_payment, dispatch_uid='fundraiser_received_payment')

def received_cancellation(sender, **kwargs):
    transaction_id = kwargs['transaction_id']

    pledge = Pledge.objects.get(pk=transaction_id)
    pledge.timestamp_cancelled = timezone.now()
    pledge.save()
payment_cancelled.connect(received_cancellation, dispatch_uid='fundraiser_received_cancellation')To redirect to Touchnet, create atouchnet.forms.RedirectFormwith a
transaction id (e.g. pledge pk) and an amount (e.g. donation_amount) in a view:def donate_redirect_detail(request):
    context = {}
    pledge_pk = request.session['pledge']
    pledge = Pledge.objects.get(pk=pledge_pk)
    context['redirect_form'] = RedirectForm(pledge.pk, pledge.donation_amount)
    return render(request, 'fundraiser/donate_redirect_detail.html', context)And show the form in a template, optionally submitting it automatically. If
using Bootstrap, use theshow_redirect_formtemplate tag:{% extends 'core/base.html' %}

{% load touchnet_extras %}

{% block page-title %}Payment{% endblock %}
{% block donate-status %}active{% endblock %}

{% block content %}
<h2>Continue To Payment</h2>
<p>You will be redirected to a third-party payment site.</p>
{% show_redirect_form redirect_form %}
{% endblock %}

{% block scripts %}
  <script>
    (function($) {
      $(document).ready(function() {
        $('button').attr('data-loading-text', 'Redirecting...')
            .button('loading');
        $('form').submit();
      });
    })($);
  </script>
{% endblock %}If the payment was successful, you can retrieve thetransaction_idin the
success view with the utility function, e.g.:def donate_success_detail(request):
    ...
    pledge_pk = touchnet.utils.get_transaction_id_from_request(request)
    ...ProcessCreatetransaction_idby saving a model instance for the transaction
(e.g. a pledge) or create a unique idMakeRedirectFormwithtransaction_idand amount, and displayOptionally, auto-submitRedirectFormwith JavaScriptUser is redirected to Touchnet URLSuccess:User inputs credit card informationTouchnet processes credit cardTouchnet send POST request to/touchnet/postback/Django Touchnet verifies validity and sends signal topayment_receivedReceiver receives signal and updates payment amount (e.g.pledge.amount_paid)Touchnet redirects user to success URL configuredDisplay success and confirmationError:An error occursTouchnet redirects user to error URL configuredDisplay errorCancel:User cancelsTouchnet send POST request to/touchnet/postback/Django Touchnet verifies validity and sends signal topayment_cancelledReceiver receives signal and processes further (e.g. possibly delete order)Touchnet redirects user to cancel URL configuredDisplay cancellation