Changeset 9748 for main


Ignore:
Timestamp:
30 Nov 2012, 21:14:25 (12 years ago)
Author:
Henrik Bettermann
Message:

Import helper functions from kofacustom.nigeria.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.uniben/trunk/src/waeup/uniben/interswitch/browser.py

    r9745 r9748  
    2323from zope.event import notify
    2424from zope.component import getUtility
     25from kofacustom.nigeria.interswitch.helpers import query_interswitch
    2526from waeup.kofa.browser.layout import KofaPage, UtilityView
    2627from waeup.kofa.accesscodes import create_accesscode
     
    5152httplib.HTTPConnection.debuglevel = 0
    5253
    53 
    54 def SOAP_post(soap_action,xml):
    55     """Handles making the SOAP request.
    56 
    57     Further reading:
    58     http://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryWs.asmx?op=getTransactionData
    59     """
    60     h = httplib.HTTPConnection(HOST)
    61     headers={
    62         'Host':HOST,
    63         'Content-Type':'text/xml; charset=utf-8',
    64         'Content-Length':len(xml),
    65         'SOAPAction':'"%s"' % soap_action,
    66     }
    67     h.request('POST', URL, body=xml,headers=headers)
    68     response = h.getresponse()
    69     return response
    70 
    71 def get_SOAP_response(product_id, transref):
    72     xml="""\
    73 <?xml version="1.0" encoding="utf-8"?>
    74 <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/">
    75   <soap:Body>
    76     <getTransactionData xmlns="http://tempuri.org/">
    77       <product_id>%s</product_id>
    78       <trans_ref>%s</trans_ref>
    79     </getTransactionData>
    80   </soap:Body>
    81 </soap:Envelope>""" % (product_id, transref)
    82     response=SOAP_post("http://tempuri.org/getTransactionData",xml)
    83     if response.status!=200:
    84         return 'Connection error (%s, %s)' % (response.status, response.reason)
    85     result_xml = response.read()
    86     doc=parseString(result_xml)
    87     response=doc.getElementsByTagName('getTransactionDataResult')[0].firstChild.data
    88     return response
    89 
    90 def query_interswitch(payment):
    91     sr = get_SOAP_response(PRODUCT_ID, payment.p_id)
    92     if sr.startswith('Connection error'):
    93         msg = _('Connection error')
    94         log = sr
    95         return False, msg, log
    96     wlist = sr.split(':')
    97     if len(wlist) != 7:
    98         msg = _('Invalid callback: ${a}', mapping = {'a': sr})
    99         log = 'invalid callback for payment %s: %s' % (payment.p_id, sr)
    100         return False, msg, log
    101     payment.r_code = wlist[0]
    102     payment.r_desc = wlist[1]
    103     payment.r_amount_approved = float(wlist[2]) / 100
    104     payment.r_card_num = wlist[3]
    105     payment.r_pay_reference = wlist[5]
    106     payment.r_company = u'interswitch'
    107     if payment.r_code != '00':
    108         msg = _('Unsuccessful callback: ${a}', mapping = {'a': sr})
    109         log = 'unsuccessful callback for %s payment %s: %s' % (
    110             payment.p_category, payment.p_id, sr)
    111         payment.p_state = 'failed'
    112         notify(grok.ObjectModifiedEvent(payment))
    113         return False, msg, log
    114     if payment.r_amount_approved != payment.amount_auth:
    115         msg = _('Callback amount does not match.')
    116         log = 'wrong callback for %s payment %s: %s' % (
    117             payment.p_category, payment.p_id, sr)
    118         payment.p_state = 'failed'
    119         notify(grok.ObjectModifiedEvent(payment))
    120         return False, msg, log
    121     if wlist[4] != payment.p_id:
    122         msg = _('Callback transaction id does not match.')
    123         log = 'wrong callback for %s payment %s: %s' % (
    124             payment.p_category, payment.p_id, sr)
    125         payment.p_state = 'failed'
    126         notify(grok.ObjectModifiedEvent(payment))
    127         return False, msg, log
    128     payment.p_state = 'paid'
    129     payment.payment_date = datetime.utcnow()
    130     msg = _('Successful callback received')
    131     log = 'valid callback for %s payment %s: %s' % (
    132         payment.p_category, payment.p_id, sr)
    133     notify(grok.ObjectModifiedEvent(payment))
    134     return True, msg, log
    135 
    13654class InterswitchActionButtonStudent(APABStudent):
    13755    grok.order(1)
     
    195113    text = _('Requery CollegePAY')
    196114    target = 'request_webservice'
    197 
    198115
    199116class InterswitchPageStudent(KofaPage):
     
    451368            return
    452369        student = self.context.student
    453         success, msg, log = query_interswitch(self.context)
     370        success, msg, log = query_interswitch(
     371            self.context, PRODUCT_ID, HOST, URL)
    454372        student.writeLogMessage(self, log)
    455373        if not success:
     
    478396            return
    479397        applicant = self.context.__parent__
    480         success, msg, log = query_interswitch(self.context)
     398        success, msg, log = query_interswitch(
     399            self.context, PRODUCT_ID, HOST, URL)
    481400        applicant.writeLogMessage(self, log)
    482401        if not success:
Note: See TracChangeset for help on using the changeset viewer.