Index: /main/waeup.fceokene/trunk/src/waeup/fceokene/interswitch/browser.py
===================================================================
--- /main/waeup.fceokene/trunk/src/waeup/fceokene/interswitch/browser.py	(revision 9779)
+++ /main/waeup.fceokene/trunk/src/waeup/fceokene/interswitch/browser.py	(revision 9780)
@@ -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 = 'FCEOkene'
 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'
@@ -129,10 +131,12 @@
         self.site_redirect_url = self.url(self.context, 'request_webservice')
         # Provider data
+        provider_amt = 1600.0
         xmldict['detail_ref'] = self.context.p_id
         xmldict['provider_acct'] = PROVIDER_ACCT
         xmldict['provider_bank_id'] = PROVIDER_BANK_ID
         xmldict['provider_item_name'] = PROVIDER_ITEM_NAME
-        xmldict['provider_amt'] = 100 * 1600
+        xmldict['provider_amt'] = 100 * provider_amt
         # Institution data
+        fceokene_split_amt = 1400.0
         xmldict['fceokene_acct'] = "0000000000000"
         xmldict['institution_bank_id'] = '0'
@@ -154,11 +158,14 @@
                 xmldict['institution_acct'] = "6216801025"
                 xmldict['institution_bank_id'] = '117'
-            xmldict['fceokene_split'] = 100 * 1400
+            xmldict['fceokene_split'] = 100 * fceokene_split_amt
             xmldict['institution_amt'] = 100 * (
-                self.context.amount_auth - 1600 - 150 - 1400)
+                self.context.amount_auth - provider_amt -
+                GATEWAY_AMT - fceokene_split_amt)
         elif 'maintenance' in self.context.p_category:
+            fceokene_split_amt = 0.0
+            provider_amt = 0.0
             self.pay_item_id = '8300'
             xmldict['institution_amt'] = 100 * (
-                self.context.amount_auth - 150)
+                self.context.amount_auth - GATEWAY_AMT)
             xmldict['institution_acct'] = "1012044132"
             xmldict['institution_bank_id'] = '117'
@@ -169,5 +176,5 @@
 <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)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="FCEOkene Split" item_amt="%(fceokene_split)s" bank_id="117" acct_num="6216801058" />
+<item_detail item_id="2" item_name="FCEOkene Split" item_amt="%(fceokene_split)d" bank_id="117" acct_num="6216801058" />
 <item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />
 </item_details>
@@ -182,4 +189,7 @@
 
         self.xml_data = """<input type="hidden" name="xml_data" value='%s'  />""" % xmltext
+        self.context.provider_amt = provider_amt
+        self.context.gateway_amt = GATEWAY_AMT
+        self.context.thirdparty_amt = fceokene_split_amt
         return
 
@@ -221,10 +231,12 @@
         xmldict['detail_ref'] = self.context.p_id
         # Provider data
-        xmldict['provider_amt'] = 100 * 500
+        provider_amt = 500.0
+        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
         # Institution data
-        xmldict['institution_amt'] = 100 * (self.context.amount_auth - 500 - 150)
+        xmldict['institution_amt'] = 100 * (self.context.amount_auth -
+            provider_amt - GATEWAY_AMT)
         xmldict['institution_acct'] = '1012445289'
         xmldict['institution_bank_id'] = '117'
@@ -239,4 +251,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
 
@@ -258,7 +272,7 @@
         student.writeLogMessage(self, log)
         if not success:
-            msg = self.request['QUERY_STRING'].replace('%20',' ')
-            self.flash(_('Response from Interswitch: ') + msg)
-            return
+            self.flash(msg)
+            return
+        write_payments_log(student.student_id, self.context)
         success, msg, log = self.context.doAfterStudentPayment()
         if log is not None:
@@ -289,4 +303,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.fceokene/trunk/src/waeup/fceokene/interswitch/tests.py
===================================================================
--- /main/waeup.fceokene/trunk/src/waeup/fceokene/interswitch/tests.py	(revision 9779)
+++ /main/waeup.fceokene/trunk/src/waeup/fceokene/interswitch/tests.py	(revision 9780)
@@ -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)
@@ -80,6 +81,13 @@
     def test_interswitch_form(self):
 
+        self.assertEqual(self.student['payments'][self.value].provider_amt, 0.0)
+        self.assertEqual(self.student['payments'][self.value].gateway_amt, 0.0)
+        self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 0.0)
         # Manager can access InterswitchForm for the created school fee ticket
         self.browser.getLink("CollegePAY", index=0).click()
+        # Split amounts have been set
+        self.assertEqual(self.student['payments'][self.value].provider_amt, 1600.0)
+        self.assertEqual(self.student['payments'][self.value].gateway_amt, 150.0)
+        self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 1400.0)
         self.assertMatches('...Total Amount Authorized:...',
                            self.browser.contents)
@@ -133,6 +141,13 @@
             self.browser.contents)
         self.payment_url = self.browser.url
+        self.assertEqual(self.student['payments'][value].provider_amt, 0.0)
+        self.assertEqual(self.student['payments'][value].gateway_amt, 0.0)
+        self.assertEqual(self.student['payments'][value].thirdparty_amt, 0.0)
         # 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, 150.0)
+        self.assertEqual(self.student['payments'][value].thirdparty_amt, 0.0)
         # The total amount to be processed by Interswitch
         # has been reduced by the Interswitch fee of 150 Nairas
@@ -171,8 +186,12 @@
     @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...',
         #                  self.browser.contents)
-        self.assertMatches('...Response from Interswitch...',
+        self.assertMatches('...Unsuccessful callback...',
                           self.browser.contents)
         # The payment is now in state failed ...
@@ -185,4 +204,50 @@
         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 = 'p3536651296379'
+        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.fceokene.interswitch.browser.InterswitchPaymentRequestWebservicePageStudent - '
+            'K1000000 - successful schoolfee payment: p3536651296379\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",K1000000,p3536651296379,schoolfee,'
+            '3150.0,00,1600.0,150.0,1400.0,,,\n'
+            in logcontent)
 
 class InterswitchTestsApplicants(ApplicantsFullSetup):
@@ -205,7 +270,4 @@
         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)
@@ -214,4 +276,7 @@
             self.browser.contents)
         self.payment_url = self.browser.url
+        self.browser.open(self.manage_path)
+        ctrl = self.browser.getControl(name='val_id')
+        self.value = ctrl.options[0]
 
 
@@ -219,4 +284,5 @@
 
         # Manager can access InterswitchForm
+        self.browser.open(self.payment_url)
         self.browser.getLink("CollegePAY", index=0).click()
         self.assertMatches('...Total Amount Authorized:...',
@@ -228,9 +294,64 @@
     @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...',
                           self.browser.contents)
-        # The payment is now in state failed
+        # The payment is now in state failed ...
         self.assertMatches('...<span>Failed</span>...',
                           self.browser.contents)
+        # ... and the catalog has been updated
+        cat = getUtility(ICatalog, name='payments_catalog')
+        results = list(
+            cat.searchResults(p_state=('failed', 'failed')))
+        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.applicant[self.value]
+        payment.p_id = 'p3536651296379'
+        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', 'applicants.log')
+        logcontent = open(logfile).read()
+        self.assertTrue(
+            'zope.mgr - '
+            'waeup.fceokene.interswitch.browser.InterswitchPaymentRequestWebservicePageApplicant - '
+            '%s - successful payment: p3536651296379\n'
+            % self.applicant.applicant_id 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",%s,p3536651296379,application,'
+            '3150.0,00,500.0,150.0,0.0,,,\n' % self.applicant.applicant_id
+            in logcontent)
Index: /main/waeup.fceokene/trunk/src/waeup/fceokene/students/browser.py
===================================================================
--- /main/waeup.fceokene/trunk/src/waeup/fceokene/students/browser.py	(revision 9779)
+++ /main/waeup.fceokene/trunk/src/waeup/fceokene/students/browser.py	(revision 9780)
@@ -36,5 +36,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')
@@ -52,5 +53,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')
