Index: main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/applicants/payment.py
===================================================================
--- main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/applicants/payment.py	(revision 11573)
+++ main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/applicants/payment.py	(revision 11574)
@@ -22,7 +22,9 @@
 from zope.component.interfaces import IFactory
 from zope.interface import implementedBy
+from hurry.workflow.interfaces import IWorkflowInfo
 from waeup.kofa.applicants.payment import ApplicantOnlinePayment
 from waeup.kofa.utils.helpers import attrs_to_fields
 from waeup.kwarapoly.applicants.interfaces import ICustomApplicantOnlinePayment
+from waeup.kwarapoly.interfaces import MessageFactory as _
 
 class CustomApplicantOnlinePayment(ApplicantOnlinePayment):
Index: main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/tests.py
===================================================================
--- main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/tests.py	(revision 11573)
+++ main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/tests.py	(revision 11574)
@@ -36,5 +36,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):
@@ -373,4 +373,22 @@
     @external_test
     def test_webservice(self):
+        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+        IWorkflowState(self.student).setState('cleared')
+        # We add a fake maint. payment ticket to meet the condition
+        maint_payment = CustomStudentOnlinePayment()
+        self.student['payments']['any_key'] = maint_payment
+        maint_payment.p_category = 'hostel_maintenance'
+        maint_payment.p_state = 'paid'
+        maint_payment.p_session = 2004
+        # We create the school fee payment ticket
+        self.browser.open(self.payments_path + '/addop')
+        self.browser.getControl(name="form.p_category").value = ['schoolfee']
+        self.browser.getControl("Create ticket").click()
+        self.assertMatches('...ticket created...',
+                           self.browser.contents)
+        ctrl = self.browser.getControl(name='val_id')
+        self.value = ctrl.options[1]
+        self.browser.getLink(self.value).click()
+        self.payment_url = self.browser.url
         # First we have open InterswitchPageStudent to set provider_amt
         # and gateway_amt
@@ -475,7 +493,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)
@@ -594,2 +609,53 @@
             'item_amt="450000" bank_id="9" acct_num="7000016724" />'
             in self.browser.contents)
+
+    @external_test
+    def test_webservice(self):
+
+        self.browser.open(self.payment_url + '/request_webservice')
+        self.assertMatches('...Unsuccessful callback...',
+                          self.browser.contents)
+        # The payment is now in state failed
+        self.assertMatches('...<span>Failed</span>...',
+                          self.browser.contents)
+        # Let's replace the p_id with a valid p_id of the Kwarapoly
+        # 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.
+        p_id = self.applicant.keys()[0]
+        payment = self.applicant[p_id]
+        payment.p_id = 'p3543612043224'
+        self.browser.open(self.payment_url + '/request_webservice')
+        self.assertMatches('...Callback amount does not match...',
+                          self.browser.contents)
+        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 applicants.log ...
+        logfile = os.path.join(
+            self.app['datacenter'].storage, 'logs', 'applicants.log')
+        logcontent = open(logfile).read()
+        self.assertTrue(
+            'zope.mgr - waeup.kwarapoly.interswitch.browser.InterswitchPaymentRequestWebservicePageApplicant'
+            ' - nd_anything - successful payment: p3543612043224\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",nd_anything,p3543612043224,application,52100.0,'
+            '00,0.0,0.0,0.0,,,\n'
+            in logcontent)
