Index: main/waeup.uniben/trunk/src/waeup/uniben/interswitch/browser.py
===================================================================
--- main/waeup.uniben/trunk/src/waeup/uniben/interswitch/browser.py	(revision 8424)
+++ main/waeup.uniben/trunk/src/waeup/uniben/interswitch/browser.py	(revision 8430)
@@ -32,6 +32,4 @@
 from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment
 from waeup.uniben.applicants.interfaces import ICustomApplicantOnlinePayment
-from waeup.uniben.students.utils import actions_after_student_payment
-from waeup.uniben.applicants.utils import actions_after_applicant_payment
 from waeup.uniben.interfaces import MessageFactory as _
 
@@ -91,14 +89,11 @@
     return response
 
-def query_interswitch(user, payment, view):
-    ob_class = view.__implemented__.__name__
+def query_interswitch(payment):
     sr = get_SOAP_response(PRODUCT_ID, payment.p_id)
-    user.loggerInfo(ob_class, 'callback received: %s' % sr)
     wlist = sr.split(':')
     if len(wlist) != 7:
-        view.flash(_('Invalid callback: ${a}',
-            mapping = {'a': wlist}))
-        user.loggerInfo(ob_class,'invalid callback: %s' % payment.p_id)
-        return False
+        msg = _('Invalid callback: ${a}', mapping = {'a': sr})
+        log = 'invalid callback for payment %s: %s' % (payment.p_id, sr)
+        return False, msg, log
     payment.r_code = wlist[0]
     payment.r_desc = wlist[1]
@@ -107,28 +102,28 @@
     payment.r_pay_reference = wlist[5]
     if payment.r_code != '00':
-        view.flash(_('Unsuccessful callback: ${a}', mapping = {'a': wlist[1]}))
-        user.loggerInfo(ob_class,'unsuccessful callback: %s' % payment.p_id)
+        msg = _('Unsuccessful callback: ${a}', mapping = {'a': sr})
+        log = 'usuccessful callback for payment %s: %s' % (payment.p_id, sr)
         payment.p_state = 'failed'
-        return False
+        return False, msg, log
     if payment.r_amount_approved != payment.amount_auth:
-        view.flash(_('Wrong amount'))
-        user.loggerInfo(ob_class,'successful callback but wrong amount: %s'
-            % payment.p_id)
+        msg = _('Callback amount does not match.')
+        log = 'wrong callback for payment %s: %s' % (payment.p_id, sr)
         payment.p_state = 'failed'
-        return False
+        return False, msg, log
     if wlist[4] != payment.p_id:
-        view.flash(_('Wrong transaction id'))
-        user.loggerInfo(ob_class,'successful callback but wrong transaction id: %s'
-            % payment.p_id)
+        msg = _('Callback transaction id does not match.')
+        log = 'wrong callback for payment %s: %s' % (payment.p_id, sr)
         payment.p_state = 'failed'
-        return False
-    user.loggerInfo(ob_class,'successful callback: %s' % payment.p_id)
+        return False, msg, log
     payment.p_state = 'paid'
     payment.payment_date = datetime.now()
-    return True
+    msg = _('Successful callback received')
+    log = 'valid callback for payment %s: %s' % (payment.p_id, sr)
+    return True, msg, log
 
 class InterswitchActionButtonStudent(APABStudent):
     grok.order(1)
     grok.context(ICustomStudentOnlinePayment)
+    grok.require('waeup.payStudent')
     icon = 'actionicon_pay.png'
     text = _('CollegePAY')
@@ -144,4 +139,5 @@
     grok.order(1)
     grok.context(ICustomApplicantOnlinePayment)
+    grok.require('waeup.payApplicant')
     icon = 'actionicon_pay.png'
     text = _('CollegePAY')
@@ -175,4 +171,5 @@
     grok.order(2)
     grok.context(ICustomStudentOnlinePayment)
+    grok.require('waeup.payStudent')
     icon = 'actionicon_call.png'
     text = _('Requery CollegePAY')
@@ -182,4 +179,5 @@
     grok.order(2)
     grok.context(ICustomApplicantOnlinePayment)
+    grok.require('waeup.payApplicant')
     icon = 'actionicon_call.png'
     text = _('Requery CollegePAY')
@@ -404,10 +402,18 @@
 
     def update(self):
+        ob_class = self.__implemented__.__name__
         if self.context.p_state == 'paid':
             self.flash(_('This ticket has already been paid.'))
             return
         student = self.context.getStudent()
-        if query_interswitch(student, self.context, self):
-            actions_after_student_payment(student, self.context, self)
+        success, msg, log = query_interswitch(self.context)
+        student.loggerInfo(ob_class, log)
+        if not success:
+            self.flash(msg)
+            return
+        success, msg, log = self.context.doAfterStudentPayment()
+        if log is not None:
+            student.loggerInfo(ob_class, log)
+        self.flash(msg)
         return
 
@@ -424,10 +430,18 @@
 
     def update(self):
+        ob_class = self.__implemented__.__name__
         if self.context.p_state == 'paid':
             self.flash(_('This ticket has already been paid.'))
             return
         applicant = self.context.__parent__
-        if query_interswitch(applicant, self.context, self):
-            actions_after_applicant_payment(applicant, self)
+        success, msg, log = query_interswitch(self.context)
+        applicant.loggerInfo(ob_class, log)
+        if not success:
+            self.flash(msg)
+            return
+        success, msg, log = self.context.doAfterApplicantPayment()
+        if log is not None:
+            applicant.loggerInfo(ob_class, log)
+        self.flash(msg)
         return
 
