Index: /main/waeup.futminna/trunk/src/waeup/futminna/interswitch/browser.py
===================================================================
--- /main/waeup.futminna/trunk/src/waeup/futminna/interswitch/browser.py	(revision 9784)
+++ /main/waeup.futminna/trunk/src/waeup/futminna/interswitch/browser.py	(revision 9785)
@@ -19,9 +19,10 @@
 import grok
 from zope.component import getUtility
-from kofacustom.nigeria.interswitch.helpers import query_interswitch
-from waeup.kofa.browser.layout import KofaPage, UtilityView
+from kofacustom.nigeria.interswitch.browser import (
+    InterswitchPaymentRequestWebservicePageStudent
+    )
+from waeup.kofa.browser.layout import KofaPage
 from waeup.kofa.interfaces import RETURNING, CLEARED, IKofaUtils
 from waeup.kofa.utils.helpers import to_timezone
-from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent
 from waeup.futminna.students.interfaces import ICustomStudentOnlinePayment
 from waeup.futminna.interfaces import MessageFactory as _
@@ -34,4 +35,5 @@
 INSTITUTION_NAME = 'FUTMinna'
 CURRENCY = '566'
+GATEWAY_AMT = 300.0
 #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
 #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
@@ -44,26 +46,4 @@
 #URL = '/test_paydirect/services/TransactionQueryWs.asmx'
 httplib.HTTPConnection.debuglevel = 0
-
-class InterswitchActionButtonStudent(APABStudent):
-    grok.order(1)
-    grok.context(ICustomStudentOnlinePayment)
-    grok.require('waeup.payStudent')
-    icon = 'actionicon_pay.png'
-    text = _('CollegePAY')
-    target = 'goto_interswitch'
-
-    @property
-    def target_url(self):
-        if self.context.p_state != 'unpaid':
-            return ''
-        return self.view.url(self.view.context, self.target)
-
-class InterswitchRequestWebserviceActionButtonStudent(APABStudent):
-    grok.order(2)
-    grok.context(ICustomStudentOnlinePayment)
-    grok.require('waeup.payStudent')
-    icon = 'actionicon_call.png'
-    text = _('Requery CollegePAY')
-    target = 'request_webservice'
 
 class InterswitchPageStudent(KofaPage):
@@ -111,5 +91,5 @@
         xmldict['provider_bank_id'] = PROVIDER_BANK_ID
         xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
-        provider_amt = 1500
+        provider_amt = 1500.0
         xmldict['provider_amt'] = 100 * provider_amt
 
@@ -124,5 +104,5 @@
         if self.context.p_category == 'schoolfee':
             xmldict['institution_amt'] = 100 * (
-                self.context.amount_auth - provider_amt - 300)
+                self.context.amount_auth - provider_amt - GATEWAY_AMT)
             if self.context.student.current_mode in ('pg_ft'):
                 self.pay_item_id = "11703"
@@ -183,15 +163,17 @@
         elif self.context.p_category == 'clearance':
             xmldict['institution_amt'] = 100 * (
-                self.context.amount_auth - 300)
+                self.context.amount_auth - GATEWAY_AMT)
             xmldict['institution_acct'] = "1750005063"
             xmldict['institution_bank_id'] = '120'
             self.pay_item_id = "11706"
+            provider_amt = 0.0
 
         elif 'maintenance' in self.context.p_category:
             xmldict['institution_amt'] = 100 * (
-                self.context.amount_auth - 300)
+                self.context.amount_auth - GATEWAY_AMT)
             xmldict['institution_acct'] = "2018856637"
             xmldict['institution_bank_id'] = '8'
             self.pay_item_id = "11705"
+            provider_amt = 0.0
 
         # Interswitch amount is not part of the xml data
@@ -220,31 +202,14 @@
 
         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(UtilityView, grok.View):
+class InterswitchPaymentRequestWebservicePageStudent(
+    InterswitchPaymentRequestWebservicePageStudent):
     """ Request webservice view for the CollegePAY gateway
     """
     grok.context(ICustomStudentOnlinePayment)
-    grok.name('request_webservice')
-    grok.require('waeup.payStudent')
-
-    def update(self):
-        if self.context.p_state == 'paid':
-            self.flash(_('This ticket has already been paid.'))
-            return
-        student = self.context.student
-        success, msg, log = query_interswitch(
-            self.context, PRODUCT_ID, HOST, URL)
-        student.writeLogMessage(self, log)
-        if not success:
-            self.flash(msg)
-            return
-        success, msg, log = self.context.doAfterStudentPayment()
-        if log is not None:
-            student.writeLogMessage(self, log)
-        self.flash(msg)
-        return
-
-    def render(self):
-        self.redirect(self.url(self.context, '@@index'))
-        return
+    product_id = PRODUCT_ID
+    gateway_host = HOST
+    gateway_url = URL
Index: /main/waeup.futminna/trunk/src/waeup/futminna/interswitch/tests.py
===================================================================
--- /main/waeup.futminna/trunk/src/waeup/futminna/interswitch/tests.py	(revision 9784)
+++ /main/waeup.futminna/trunk/src/waeup/futminna/interswitch/tests.py	(revision 9785)
@@ -16,4 +16,5 @@
 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 ##
+import os
 from zope.component import getUtility
 from zope.catalog.interfaces import ICatalog
@@ -27,5 +28,5 @@
 #   If you enable this, please make sure the external services
 #   do exist really and are not bothered by being spammed by a test programme.
-EXTERNAL_TESTS = False
+EXTERNAL_TESTS = True
 
 def external_test(func):
@@ -57,6 +58,6 @@
                            self.browser.contents)
         ctrl = self.browser.getControl(name='val_id')
-        value = ctrl.options[0]
-        self.browser.getLink(value).click()
+        self.value = ctrl.options[0]
+        self.browser.getLink(self.value).click()
         self.assertMatches('...Amount Authorized...',
                            self.browser.contents)
@@ -68,5 +69,10 @@
     def test_interswitch_form(self):
         # Manager can access InterswitchForm
+        self.assertEqual(self.student['payments'][self.value].provider_amt, 0.0)
+        self.assertEqual(self.student['payments'][self.value].gateway_amt, 0.0)
         self.browser.getLink("CollegePAY", index=0).click()
+        # Split amounts have been set.
+        self.assertEqual(self.student['payments'][self.value].provider_amt, 1500.0)
+        self.assertEqual(self.student['payments'][self.value].gateway_amt, 300.0)
         # The total amount to be processed by Interswitch
         # has been reduced by the Interswitch fee of 150 Nairas
@@ -99,4 +105,7 @@
         # Manager can access InterswitchForm
         self.browser.getLink("CollegePAY", index=0).click()
+        # Split amounts have been set.
+        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
+        self.assertEqual(self.student['payments'][value].gateway_amt, 300.0)
         # The total amount to be processed by Interswitch
         # has been reduced by the Interswitch fee of 150 Nairas
@@ -143,4 +152,7 @@
         # Manager can access InterswitchForm
         self.browser.getLink("CollegePAY", index=0).click()
+        # Split amounts have been set.
+        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
+        self.assertEqual(self.student['payments'][value].gateway_amt, 300.0)
         # The total amount to be processed by Interswitch
         # has been reduced by the Interswitch fee of 150 Nairas
@@ -159,4 +171,8 @@
     @external_test
     def test_webservice(self):
+        # First we have open InterswitchPageStudent to set provider_amt
+        # and gateway_amt
+        self.browser.open(self.payment_url + '/goto_interswitch')
+        # Now we can call the webservice
         self.browser.open(self.payment_url + '/request_webservice')
         self.assertMatches('...Unsuccessful callback...',
@@ -171,2 +187,48 @@
         self.assertEqual(len(results), 1)
         self.assertEqual(results[0].p_state, 'failed')
+
+        # Let's replace the p_id with a valid p_id of the Uniben
+        # live system. This is definitely not an appropriate
+        # solution for testing, but we have no choice since
+        # Interswitch doesn't provide any interface
+        # for testing.
+        payment = self.student['payments'][self.value]
+        payment.p_id = 'p3522296094055'
+        self.browser.open(self.payment_url + '/request_webservice')
+        self.assertMatches('...Callback amount does not match...',
+                          self.browser.contents)
+        # The payment is now in state failed ...
+        self.assertMatches('...<span>Failed</span>...',
+                          self.browser.contents)
+        # Let's replace the amount autorized with the amount of the
+        # live system payment
+        payment.amount_auth = payment.r_amount_approved
+        self.browser.open(self.payment_url + '/request_webservice')
+        self.assertMatches('...Successful payment...',
+                          self.browser.contents)
+        # The payment is now in state paid ...
+        self.assertMatches('...<span>Paid</span>...',
+                          self.browser.contents)
+        # ... and the catalog has been updated
+        cat = getUtility(ICatalog, name='payments_catalog')
+        results = list(
+            cat.searchResults(p_state=('paid', 'paid')))
+        self.assertEqual(len(results), 1)
+        self.assertEqual(results[0].p_state, 'paid')
+        # Approval is logged in students.log ...
+        logfile = os.path.join(
+            self.app['datacenter'].storage, 'logs', 'students.log')
+        logcontent = open(logfile).read()
+        self.assertTrue(
+            'zope.mgr - '
+            'waeup.futminna.interswitch.browser.InterswitchPaymentRequestWebservicePageStudent - '
+            'M1000000 - successful schoolfee payment: p3522296094055\n'
+            in logcontent)
+        # ... and in payments.log
+        logfile = os.path.join(
+            self.app['datacenter'].storage, 'logs', 'payments.log')
+        logcontent = open(logfile).read()
+        self.assertTrue(
+            '"zope.mgr",M1000000,p3522296094055,schoolfee,'
+            '20000.0,00,1500.0,300.0,0.0,,,\n'
+            in logcontent)
Index: /main/waeup.futminna/trunk/src/waeup/futminna/students/browser.py
===================================================================
--- /main/waeup.futminna/trunk/src/waeup/futminna/students/browser.py	(revision 9784)
+++ /main/waeup.futminna/trunk/src/waeup/futminna/students/browser.py	(revision 9785)
@@ -32,5 +32,6 @@
     """
     grok.context(ICustomStudentOnlinePayment)
-    form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
+    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
+        'provider_amt', 'gateway_amt', 'thirdparty_amt')
     form_fields[
         'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
@@ -48,5 +49,6 @@
     """
     grok.context(ICustomStudentOnlinePayment)
-    form_fields = grok.AutoFields(ICustomStudentOnlinePayment)
+    form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit(
+        'provider_amt', 'gateway_amt', 'thirdparty_amt')
     form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
     form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
