Index: main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/browser.py
===================================================================
--- main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/browser.py	(revision 9750)
+++ main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/browser.py	(revision 9751)
@@ -16,16 +16,12 @@
 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 ##
-from datetime import datetime
 import httplib
-import urllib
 import hashlib
-from xml.dom.minidom import parseString
 import grok
-from zope.event import notify
 from zope.interface import Interface
 from zope.component import getUtility, queryAdapter
+from kofacustom.nigeria.interswitch.helpers import query_interswitch
 from waeup.kofa.browser.layout import KofaPage, UtilityView
-from waeup.kofa.accesscodes import create_accesscode
-from waeup.kofa.interfaces import RETURNING, IKofaUtils
+from waeup.kofa.interfaces import IKofaUtils
 from waeup.kofa.utils.helpers import to_timezone
 from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent
@@ -55,83 +51,4 @@
 httplib.HTTPConnection.debuglevel = 0
 
-
-def SOAP_post(soap_action,xml):
-    """Handles making the SOAP request.
-
-    Further reading:
-    http://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryWs.asmx?op=getTransactionData
-    """
-    h = httplib.HTTPConnection(HOST)
-    headers={
-        'Host':HOST,
-        'Content-Type':'text/xml; charset=utf-8',
-        'Content-Length':len(xml),
-        'SOAPAction':'"%s"' % soap_action,
-    }
-    h.request('POST', URL, body=xml,headers=headers)
-    r = h.getresponse()
-    d = r.read()
-    if r.status!=200:
-        raise ValueError('Error connecting: %s, %s' % (r.status, r.reason))
-    return d
-
-def get_SOAP_response(product_id, transref):
-    xml="""\
-<?xml version="1.0" encoding="utf-8"?>
-<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
-  <soap:Body>
-    <getTransactionData xmlns="http://tempuri.org/">
-      <product_id>%s</product_id>
-      <trans_ref>%s</trans_ref>
-    </getTransactionData>
-  </soap:Body>
-</soap:Envelope>""" % (product_id, transref)
-    result_xml=SOAP_post("http://tempuri.org/getTransactionData",xml)
-    doc=parseString(result_xml)
-    response=doc.getElementsByTagName('getTransactionDataResult')[0].firstChild.data
-    return response
-
-def query_interswitch(payment):
-    sr = get_SOAP_response(PRODUCT_ID, payment.p_id)
-    wlist = sr.split(':')
-    if len(wlist) != 7:
-        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]
-    payment.r_amount_approved = float(wlist[2]) / 100
-    payment.r_card_num = wlist[3]
-    payment.r_pay_reference = wlist[5]
-    payment.r_company = u'interswitch'
-    if payment.r_code != '00':
-        msg = _('Unsuccessful callback: ${a}', mapping = {'a': sr})
-        log = 'unsuccessful callback for %s payment %s: %s' % (
-            payment.p_category, payment.p_id, sr)
-        payment.p_state = 'failed'
-        notify(grok.ObjectModifiedEvent(payment))
-        return False, msg, log
-    if payment.r_amount_approved != payment.amount_auth:
-        msg = _('Callback amount does not match.')
-        log = 'wrong callback for %s payment %s: %s' % (
-            payment.p_category, payment.p_id, sr)
-        payment.p_state = 'failed'
-        notify(grok.ObjectModifiedEvent(payment))
-        return False, msg, log
-    if wlist[4] != payment.p_id:
-        msg = _('Callback transaction id does not match.')
-        log = 'wrong callback for %s payment %s: %s' % (
-            payment.p_category, payment.p_id, sr)
-        payment.p_state = 'failed'
-        notify(grok.ObjectModifiedEvent(payment))
-        return False, msg, log
-    payment.p_state = 'paid'
-    payment.payment_date = datetime.utcnow()
-    msg = _('Successful callback received')
-    log = 'valid callback for %s payment %s: %s' % (
-        payment.p_category, payment.p_id, sr)
-    notify(grok.ObjectModifiedEvent(payment))
-    return True, msg, log
-
 def interswitch_img_url(view):
     static = view.static
@@ -139,5 +56,5 @@
         'interswitch_verve_mastercard.gif', None) is None:
         static = queryAdapter(
-            self.request, Interface, name='waeup.kwarapoly.interswitch')
+            view.request, Interface, name='waeup.kwarapoly.interswitch')
     return static['interswitch_verve_mastercard.gif']()
 
@@ -368,10 +285,10 @@
 
     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.student
-        success, msg, log = query_interswitch(self.context)
+        success, msg, log = query_interswitch(
+            self.context, PRODUCT_ID, HOST, URL)
         student.writeLogMessage(self, log)
         if not success:
@@ -400,5 +317,6 @@
             return
         applicant = self.context.__parent__
-        success, msg, log = query_interswitch(self.context)
+        success, msg, log = query_interswitch(
+            self.context, PRODUCT_ID, HOST, URL)
         applicant.writeLogMessage(self, log)
         if not success:
