Changeset 9748
- Timestamp:
- 30 Nov 2012, 21:14:25 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.uniben/trunk/src/waeup/uniben/interswitch/browser.py
r9745 r9748 23 23 from zope.event import notify 24 24 from zope.component import getUtility 25 from kofacustom.nigeria.interswitch.helpers import query_interswitch 25 26 from waeup.kofa.browser.layout import KofaPage, UtilityView 26 27 from waeup.kofa.accesscodes import create_accesscode … … 51 52 httplib.HTTPConnection.debuglevel = 0 52 53 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=getTransactionData59 """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 response70 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.data88 return response89 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 = sr95 return False, msg, log96 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, log101 payment.r_code = wlist[0]102 payment.r_desc = wlist[1]103 payment.r_amount_approved = float(wlist[2]) / 100104 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, log114 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, log121 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, log128 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, log135 136 54 class InterswitchActionButtonStudent(APABStudent): 137 55 grok.order(1) … … 195 113 text = _('Requery CollegePAY') 196 114 target = 'request_webservice' 197 198 115 199 116 class InterswitchPageStudent(KofaPage): … … 451 368 return 452 369 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) 454 372 student.writeLogMessage(self, log) 455 373 if not success: … … 478 396 return 479 397 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) 481 400 applicant.writeLogMessage(self, log) 482 401 if not success:
Note: See TracChangeset for help on using the changeset viewer.