Index: main/waeup.futminna/trunk/src/waeup/futminna/interswitch/browser.py
===================================================================
--- main/waeup.futminna/trunk/src/waeup/futminna/interswitch/browser.py	(revision 9995)
+++ main/waeup.futminna/trunk/src/waeup/futminna/interswitch/browser.py	(revision 10165)
@@ -18,7 +18,9 @@
 import httplib
 import grok
-from zope.component import getUtility
+from zope.interface import Interface
+from zope.component import getUtility, queryAdapter
 from kofacustom.nigeria.interswitch.browser import (
-    InterswitchPaymentRequestWebservicePageStudent
+    InterswitchPaymentRequestWebservicePageStudent,
+    InterswitchPaymentRequestWebservicePageApplicant
     )
 from waeup.kofa.browser.layout import KofaPage
@@ -26,4 +28,5 @@
 from waeup.kofa.utils.helpers import to_timezone
 from waeup.futminna.students.interfaces import ICustomStudentOnlinePayment
+from waeup.futminna.applicants.interfaces import ICustomApplicantOnlinePayment
 from waeup.futminna.interfaces import MessageFactory as _
 
@@ -46,4 +49,12 @@
 #URL = '/test_paydirect/services/TransactionQueryWs.asmx'
 httplib.HTTPConnection.debuglevel = 0
+
+def interswitch_img_url(view):
+    static = view.static
+    if static is None or static.get(
+        'interswitch_verve_mastercard.gif', None) is None:
+        static = queryAdapter(
+            view.request, Interface, name='waeup.futminna.interswitch')
+    return static['interswitch_verve_mastercard.gif']()
 
 class InterswitchPageStudent(KofaPage):
@@ -206,4 +217,82 @@
         return
 
+class InterswitchPageApplicant(KofaPage):
+    """ View which sends a POST request to the Interswitch
+    CollegePAY payment gateway.
+    """
+    grok.context(ICustomApplicantOnlinePayment)
+    grok.require('waeup.payApplicant')
+    grok.template('applicant_goto_interswitch')
+    grok.name('goto_interswitch')
+    label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')
+    submit_button = _('Submit')
+    action = POST_ACTION
+    site_name = SITE_NAME
+    currency = CURRENCY
+    pay_item_id = '103'
+    product_id = PRODUCT_ID
+    #mac = ''
+
+    def interswitch_img_url(self):
+        return interswitch_img_url(self)
+
+    def update(self):
+        if self.context.p_state != 'unpaid':
+            self.flash(_("Payment ticket can't be re-send to CollegePAY."))
+            self.redirect(self.url(self.context, '@@index'))
+            return
+        if self.context.__parent__.__parent__.expired \
+            and self.context.__parent__.__parent__.strict_deadline:
+            self.flash(_("Payment ticket can't be send to CollegePAY. "
+                         "Application period has expired."))
+            self.redirect(self.url(self.context, '@@index'))
+            return
+        self.applicant = self.context.__parent__
+        self.amount_auth = 100 * self.context.amount_auth
+        xmldict = {}
+        self.category = getUtility(
+            IKofaUtils).PAYMENT_CATEGORIES[self.context.p_category]
+        tz = getUtility(IKofaUtils).tzinfo
+        self.local_date_time = to_timezone(
+            self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")
+        self.site_redirect_url = self.url(self.context, 'request_webservice')
+        provider_amt = 500.0
+        if self.applicant.applicant_id.startswith('pg'):
+            xmldict['institution_acct'] = '2005910931'
+            xmldict['institution_bank_id'] = '8'
+        else:
+            xmldict['institution_acct'] = '00000000000'
+            xmldict['institution_bank_id'] = '00'
+        xmldict['detail_ref'] = self.context.p_id
+        xmldict['provider_amt'] = 100 * provider_amt
+        xmldict['provider_acct'] = PROVIDER_ACCT
+        xmldict['provider_bank_id'] = PROVIDER_BANK_ID
+        xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
+        xmldict['institution_amt'] = 100 * (
+            self.context.amount_auth - provider_amt - GATEWAY_AMT)
+        xmldict['institution_item_name'] = self.context.p_category
+        xmldict['institution_name'] = INSTITUTION_NAME
+
+        #hashargs = (
+        #    self.context.p_id +
+        #    PRODUCT_ID +
+        #    self.pay_item_id +
+        #    str(int(self.amount_auth)) +
+        #    self.site_redirect_url +
+        #    self.mac)
+        #self.hashvalue = hashlib.sha512(hashargs).hexdigest()
+
+        # Interswitch amount is not part of the xml data
+        xmltext = """<payment_item_detail>
+<item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">
+<item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />
+<item_detail item_id="2" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
+</item_details>
+</payment_item_detail>""" % xmldict
+        self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
+        self.context.provider_amt = provider_amt
+        self.context.gateway_amt = GATEWAY_AMT
+        return
+
 class InterswitchPaymentRequestWebservicePageStudent(
     InterswitchPaymentRequestWebservicePageStudent):
@@ -214,2 +303,11 @@
     gateway_host = HOST
     gateway_url = URL
+
+class InterswitchPaymentRequestWebservicePageApplicant(
+    InterswitchPaymentRequestWebservicePageApplicant):
+    """ Request webservice view for the CollegePAY gateway
+    """
+    grok.context(ICustomApplicantOnlinePayment)
+    product_id = PRODUCT_ID
+    gateway_host = HOST
+    gateway_url = URL
Index: main/waeup.futminna/trunk/src/waeup/futminna/interswitch/browser_templates/applicant_goto_interswitch.pt
===================================================================
--- main/waeup.futminna/trunk/src/waeup/futminna/interswitch/browser_templates/applicant_goto_interswitch.pt	(revision 10165)
+++ main/waeup.futminna/trunk/src/waeup/futminna/interswitch/browser_templates/applicant_goto_interswitch.pt	(revision 10165)
@@ -0,0 +1,80 @@
+<form i18n:domain="waeup.kwarapoly"
+  tal:attributes="action view/action" method="POST">
+
+  <p i18n:translate="">
+    These data will be submitted to the CollegePAY payment gateway,
+    please check:
+  </p>
+
+  <table class="form-table" i18n:domain="waeup.kofa">
+    <thead>
+    </thead>
+    <tbody>
+      <tr>
+        <td i18n:translate="" class="fieldname">
+          Total Amount Authorized:</td>
+        <td>
+          <span tal:replace="view/context/amount_auth">AMOUNT</span>
+        </td>
+      </tr>
+      <tr>
+        <td i18n:translate="" class="fieldname">
+          Transaction Reference:</td>
+        <td>
+          <span tal:replace="view/context/p_id">TXNREF</span>
+        </td>
+      </tr>
+      <tr>
+        <td i18n:translate="" class="fieldname">
+          Customer Id:</td>
+        <td>
+          <span tal:replace="view/applicant/applicant_id">CUSTID</span>
+        </td>
+      </tr>
+      <tr>
+        <td i18n:translate="" class="fieldname">
+          Customer Name:</td>
+        <td>
+          <span tal:replace="view/applicant/display_fullname">CUSTNAME</span>
+        </td>
+      </tr>
+      <tr>
+        <td i18n:translate="" class="fieldname">
+          Payment Item:</td>
+        <td>
+          <span tal:replace="view/context/display_item">PAYMENTITEM</span>
+        </td>
+      </tr>
+      <tr>
+        <td i18n:translate="" class="fieldname">
+          Payment Category:</td>
+        <td>
+          <span tal:replace="view/category">PAYMENTCATEGORY</span>
+        </td>
+      </tr>
+    </tbody>
+  </table>
+
+  <input type="hidden" name="product_id" tal:attributes="value view/product_id" />
+  <input type="hidden" name="currency" tal:attributes="value view/currency" />
+  <input type="hidden" name="pay_item_id" tal:attributes="value view/pay_item_id" />
+  <input type="hidden" name="site_redirect_url" tal:attributes="value view/site_redirect_url" />
+  <input type="hidden" name="site_name" tal:attributes="value view/site_name" />
+  <input type="hidden" name="local_date_time" tal:attributes="value view/local_date_time" />
+  <input type="hidden" name="amount" tal:attributes="value view/amount_auth" />
+  <input type="hidden" name="txn_ref" tal:attributes="value view/context/p_id" />
+  <input type="hidden" name="pay_item_name" tal:attributes="value view/context/display_item" />
+  <input type="hidden" name="cust_id_desc" tal:attributes="value view/category" />
+  <input type="hidden" name="cust_id" tal:attributes="value view/applicant/applicant_id" />
+  <input type="hidden" name="cust_name" tal:attributes="value view/applicant/display_fullname" />
+
+  <input type="hidden" name="payment_params" value="college_split" />
+  <span tal:replace="structure view/xml_data"></span>
+
+  <input type="submit" class="btn" tal:attributes="value view/submit_button"/>
+
+  <br /><br />
+
+  <img tal:attributes="src view/interswitch_img_url" />
+
+</form>
Index: main/waeup.futminna/trunk/src/waeup/futminna/interswitch/tests.py
===================================================================
--- main/waeup.futminna/trunk/src/waeup/futminna/interswitch/tests.py	(revision 9995)
+++ main/waeup.futminna/trunk/src/waeup/futminna/interswitch/tests.py	(revision 10165)
@@ -17,7 +17,9 @@
 ##
 import os
-from zope.component import getUtility
+from zope.component import getUtility, createObject
 from zope.catalog.interfaces import ICatalog
 from hurry.workflow.interfaces import IWorkflowState
+from waeup.kofa.university.faculty import Faculty
+from waeup.kofa.university.department import Department
 from waeup.kofa.students.tests.test_browser import StudentsFullSetup
 from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
@@ -233,2 +235,65 @@
             '20000.0,00,1500.0,300.0,0.0,,,\n'
             in logcontent)
+
+class InterswitchTestsApplicants(ApplicantsFullSetup):
+    """Tests for the Interswitch payment gateway.
+    """
+
+    layer = FunctionalLayer
+
+    def setUp(self):
+        super(InterswitchTestsApplicants, self).setUp()
+        # Create at least one FUTMinna faculty
+        self.app['faculties']['CPGS'] = Faculty(code='ABC')
+        self.app['faculties']['CPGS']['dep1'] = Department(code='dep1')
+        self.certificate2 = createObject('waeup.Certificate')
+        self.certificate2.code = u'CERT2'
+        self.certificate2.application_category = 'pg_ft'
+        self.certificate2.study_mode = 'pg_ft'
+        self.certificate2.start_level = 999
+        self.certificate2.end_level = 999
+        self.app['faculties']['CPGS']['dep1'].certificates.addCertificate(
+            self.certificate2)
+        self.applicantscontainer.application_category = 'pg_ft'
+        self.applicant.applicant_id = u'pg_anything'
+
+        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+        self.browser.open(self.manage_path)
+        #IWorkflowState(self.student).setState('started')
+        super(InterswitchTestsApplicants, self).fill_correct_values()
+        self.browser.getControl(name="form.course1").value = ['CERT2']
+        self.applicantscontainer.application_fee = 3333.0
+        self.browser.getControl(name="form.nationality").value = ['NG']
+        self.browser.getControl(name="transition").value = ['start']
+        self.browser.getControl("Save").click()
+        self.browser.getControl("Add online").click()
+        self.assertMatches('...ticket created...',
+                           self.browser.contents)
+        #ctrl = self.browser.getControl(name='val_id')
+        #value = ctrl.options[0]
+        #self.browser.getLink(value).click()
+        self.assertMatches('...Amount Authorized...',
+                           self.browser.contents)
+        self.assertMatches(
+            '...<span>3333.0</span>...',
+            self.browser.contents)
+        self.payment_url = self.browser.url
+
+
+    def test_interswitch_form(self):
+
+        # Manager can access InterswitchForm
+        self.browser.getLink("CollegePAY", index=0).click()
+        self.assertMatches('...Total Amount Authorized:...',
+                           self.browser.contents)
+        self.assertTrue(
+            '<input type="hidden" name="amount" value="333300.0" />'
+            in self.browser.contents)
+        self.assertTrue(
+            '<item_detail item_id="1" item_name="application" '
+            'item_amt="253300" bank_id="8" acct_num="2005910931" />'
+            in self.browser.contents)
+        self.assertTrue(
+            '<item_detail item_id="2" item_name="BT Education" '
+            'item_amt="50000" bank_id="31" acct_num="0026781725" />'
+            in self.browser.contents)
