Ignore:
Timestamp:
1 Dec 2012, 06:48:46 (12 years ago)
Author:
Henrik Bettermann
Message:

Import helper functions from kofacustom.nigeria.

File:
1 edited

Legend:

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

    r9711 r9752  
    1616## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    1717##
    18 from datetime import datetime
    1918import httplib
    20 import urllib
    21 from xml.dom.minidom import parseString
    2219import grok
    23 from zope.event import notify
    2420from zope.component import getUtility
     21from kofacustom.nigeria.interswitch.helpers import query_interswitch
    2522from waeup.kofa.browser.layout import KofaPage, UtilityView
    26 from waeup.kofa.accesscodes import create_accesscode
    27 from waeup.kofa.interfaces import RETURNING, IKofaUtils
     23from waeup.kofa.interfaces import IKofaUtils
    2824from waeup.kofa.utils.helpers import to_timezone
    2925from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent
     
    5046#URL = '/test_paydirect/services/TransactionQueryWs.asmx'
    5147httplib.HTTPConnection.debuglevel = 0
    52 
    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     r = h.getresponse()
    69     d = r.read()
    70     if r.status!=200:
    71         raise ValueError('Error connecting: %s, %s' % (r.status, r.reason))
    72     return d
    73 
    74 def get_SOAP_response(product_id, transref):
    75     xml="""\
    76 <?xml version="1.0" encoding="utf-8"?>
    77 <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/">
    78   <soap:Body>
    79     <getTransactionData xmlns="http://tempuri.org/">
    80       <product_id>%s</product_id>
    81       <trans_ref>%s</trans_ref>
    82     </getTransactionData>
    83   </soap:Body>
    84 </soap:Envelope>""" % (product_id, transref)
    85     result_xml=SOAP_post("http://tempuri.org/getTransactionData",xml)
    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     wlist = sr.split(':')
    93     if len(wlist) != 7:
    94         msg = _('Invalid callback: ${a}', mapping = {'a': sr})
    95         log = 'invalid callback for payment %s: %s' % (payment.p_id, sr)
    96         return False, msg, log
    97     payment.r_code = wlist[0]
    98     payment.r_desc = wlist[1]
    99     payment.r_amount_approved = float(wlist[2]) / 100
    100     payment.r_card_num = wlist[3]
    101     payment.r_pay_reference = wlist[5]
    102     payment.r_company = u'interswitch'
    103     if payment.r_code != '00':
    104         msg = _('Unsuccessful callback: ${a}', mapping = {'a': sr})
    105         log = 'unsuccessful callback for %s payment %s: %s' % (
    106             payment.p_category, payment.p_id, sr)
    107         payment.p_state = 'failed'
    108         notify(grok.ObjectModifiedEvent(payment))
    109         return False, msg, log
    110     if payment.r_amount_approved != payment.amount_auth:
    111         msg = _('Callback amount does not match.')
    112         log = 'wrong callback for %s payment %s: %s' % (
    113             payment.p_category, payment.p_id, sr)
    114         payment.p_state = 'failed'
    115         notify(grok.ObjectModifiedEvent(payment))
    116         return False, msg, log
    117     if wlist[4] != payment.p_id:
    118         msg = _('Callback transaction id does not match.')
    119         log = 'wrong callback for %s payment %s: %s' % (
    120             payment.p_category, payment.p_id, sr)
    121         payment.p_state = 'failed'
    122         notify(grok.ObjectModifiedEvent(payment))
    123         return False, msg, log
    124     payment.p_state = 'paid'
    125     payment.payment_date = datetime.utcnow()
    126     msg = _('Successful callback received')
    127     log = 'valid callback for %s payment %s: %s' % (
    128         payment.p_category, payment.p_id, sr)
    129     notify(grok.ObjectModifiedEvent(payment))
    130     return True, msg, log
    13148
    13249class InterswitchActionButtonStudent(APABStudent):
     
    224141        if self.context.p_category == 'schoolfee':
    225142            self.pay_item_id = '8302'
    226             studycourse = student['studycourse']
    227143            if student.current_mode in ('ug_sw','prence',):
    228144                xmldict['institution_acct'] = "6216801025"
     
    334250
    335251    def update(self):
    336         ob_class = self.__implemented__.__name__
    337252        if self.context.p_state == 'paid':
    338253            self.flash(_('This ticket has already been paid.'))
    339254            return
    340255        student = self.context.student
    341         success, msg, log = query_interswitch(self.context)
     256        success, msg, log = query_interswitch(
     257            self.context, PRODUCT_ID, HOST, URL)
    342258        student.writeLogMessage(self, log)
    343259        if not success:
     
    367283            return
    368284        applicant = self.context.__parent__
    369         success, msg, log = query_interswitch(self.context)
     285        success, msg, log = query_interswitch(
     286            self.context, PRODUCT_ID, HOST, URL)
    370287        applicant.writeLogMessage(self, log)
    371288        if not success:
Note: See TracChangeset for help on using the changeset viewer.