Index: /main/waeup.uniben/trunk/src/waeup/uniben/interswitch/browser.py
===================================================================
--- /main/waeup.uniben/trunk/src/waeup/uniben/interswitch/browser.py	(revision 9774)
+++ /main/waeup.uniben/trunk/src/waeup/uniben/interswitch/browser.py	(revision 9775)
@@ -19,5 +19,6 @@
 import grok
 from zope.component import getUtility
-from kofacustom.nigeria.interswitch.helpers import query_interswitch
+from kofacustom.nigeria.interswitch.helpers import (
+    query_interswitch, write_payments_log)
 from waeup.kofa.browser.layout import KofaPage, UtilityView
 from waeup.kofa.interfaces import IKofaUtils
@@ -36,4 +37,5 @@
 INSTITUTION_NAME = 'Uniben'
 CURRENCY = '566'
+GATEWAY_AMT = 150.0
 #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx'
 #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx'
@@ -156,5 +158,5 @@
         xmldict['institution_amt'] = '0.0'
         if self.context.p_category == 'schoolfee':
-            provider_amt = 1500
+            provider_amt = 1500.0
             if student.current_mode.endswith('_ft'):
                 self.pay_item_id = '5700'
@@ -181,5 +183,5 @@
         elif self.context.p_category == 'clearance':
             self.pay_item_id = '5702'
-            provider_amt = 1500
+            provider_amt = 1500.0
             if student.current_mode == 'pg_ft':
                 xmldict['institution_acct'] = '5330832799'
@@ -196,10 +198,10 @@
         elif self.context.p_category == 'gown':
             self.pay_item_id = '5704'
-            provider_amt = 0
+            provider_amt = 0.0
             xmldict['institution_bank_id'] = '7'
             xmldict['institution_acct'] = '1016232382'
         elif self.context.p_category.startswith('hostel_maintenance'):
             self.pay_item_id = '5705'
-            provider_amt = 0
+            provider_amt = 0.0
             xmldict['institution_bank_id'] = '129'
             xmldict['institution_acct'] = '0014414547'
@@ -209,5 +211,5 @@
         xmldict['institution_name'] = INSTITUTION_NAME
         xmldict['institution_amt'] = 100 * (
-            self.context.amount_auth - provider_amt - 150)
+            self.context.amount_auth - provider_amt - GATEWAY_AMT)
         # Interswitch amount is not part of the xml data
         if provider_amt == 0:
@@ -225,4 +227,6 @@
 </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
 
@@ -262,5 +266,5 @@
             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 = 400
+        provider_amt = 400.0
         if self.applicant.applicant_id.startswith('pg'):
             xmldict['institution_acct'] = '0031716030'
@@ -277,5 +281,5 @@
         xmldict['provider_bank_id'] = PROVIDER_BANK_ID
         xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
-        xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - 150)
+        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
@@ -288,4 +292,6 @@
 </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
 
@@ -368,4 +374,5 @@
             self.flash(msg)
             return
+        write_payments_log(student.student_id, self.context)
         success, msg, log = self.context.doAfterStudentPayment()
         if log is not None:
@@ -396,4 +403,5 @@
             self.flash(msg)
             return
+        write_payments_log(applicant.applicant_id, self.context)
         success, msg, log = self.context.doAfterApplicantPayment()
         if log is not None:
Index: /main/waeup.uniben/trunk/src/waeup/uniben/interswitch/tests.py
===================================================================
--- /main/waeup.uniben/trunk/src/waeup/uniben/interswitch/tests.py	(revision 9774)
+++ /main/waeup.uniben/trunk/src/waeup/uniben/interswitch/tests.py	(revision 9775)
@@ -16,4 +16,5 @@
 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 ##
+import os
 from zope.component import createObject, getUtility
 from zope.catalog.interfaces import ICatalog
@@ -58,6 +59,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)
@@ -122,6 +123,11 @@
         ctrl = self.browser.getControl(name='val_id')
         value = ctrl.options[1]
+        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
+        self.assertEqual(self.student['payments'][value].gateway_amt, 0.0)
         self.browser.getLink(value).click()
         self.browser.getLink("CollegePAY", index=0).click()
+        # Split amounts have been set.
+        self.assertEqual(self.student['payments'][value].provider_amt, 1500.0)
+        self.assertEqual(self.student['payments'][value].gateway_amt, 150.0)
         self.assertMatches('...<input type="hidden" name="pay_item_id" value="5701" />...',
                            self.browser.contents)
@@ -148,4 +154,6 @@
         # Manager can access InterswitchForm
         self.browser.getLink("CollegePAY", index=0).click()
+        self.assertEqual(self.student['payments'][value].provider_amt, 1500.0)
+        self.assertEqual(self.student['payments'][value].gateway_amt, 150.0)
         self.assertMatches('...<input type="hidden" name="pay_item_id" value="5702" />...',
                            self.browser.contents)
@@ -176,4 +184,6 @@
         # Manager can access InterswitchForm
         self.browser.getLink("CollegePAY", index=0).click()
+        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
+        self.assertEqual(self.student['payments'][value].gateway_amt, 150.0)
         self.assertMatches('...<input type="hidden" name="pay_item_id" value="5704" />...',
                            self.browser.contents)
@@ -201,4 +211,6 @@
         # Manager can access InterswitchForm
         self.browser.getLink("CollegePAY", index=0).click()
+        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
+        self.assertEqual(self.student['payments'][value].gateway_amt, 150.0)
         self.assertMatches('...<input type="hidden" name="pay_item_id" value="5705" />...',
                            self.browser.contents)
@@ -237,5 +249,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...',
@@ -250,4 +265,51 @@
         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 = 'p3547789850240'
+        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.uniben.interswitch.browser.InterswitchPaymentRequestWebservicePageStudent - '
+            'B1000000 - successful schoolfee payment: p3547789850240\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",B1000000,p3547789850240,schoolfee,'
+            '12000.0,00,1500.0,150.0,0.0,,,\n'
+            in logcontent)
+
 
 class InterswitchTestsApplicants(ApplicantsFullSetup):
Index: /main/waeup.uniben/trunk/src/waeup/uniben/students/browser.py
===================================================================
--- /main/waeup.uniben/trunk/src/waeup/uniben/students/browser.py	(revision 9774)
+++ /main/waeup.uniben/trunk/src/waeup/uniben/students/browser.py	(revision 9775)
@@ -70,5 +70,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')
@@ -106,5 +107,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')
