Changeset 9752
- Timestamp:
- 1 Dec 2012, 06:48:46 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.fceokene/trunk/src/waeup/fceokene/interswitch/browser.py
r9711 r9752 16 16 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 17 ## 18 from datetime import datetime19 18 import httplib 20 import urllib21 from xml.dom.minidom import parseString22 19 import grok 23 from zope.event import notify24 20 from zope.component import getUtility 21 from kofacustom.nigeria.interswitch.helpers import query_interswitch 25 22 from waeup.kofa.browser.layout import KofaPage, UtilityView 26 from waeup.kofa.accesscodes import create_accesscode 27 from waeup.kofa.interfaces import RETURNING, IKofaUtils 23 from waeup.kofa.interfaces import IKofaUtils 28 24 from waeup.kofa.utils.helpers import to_timezone 29 25 from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent … … 50 46 #URL = '/test_paydirect/services/TransactionQueryWs.asmx' 51 47 httplib.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=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 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 d73 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.data88 return response89 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, log97 payment.r_code = wlist[0]98 payment.r_desc = wlist[1]99 payment.r_amount_approved = float(wlist[2]) / 100100 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, log110 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, log117 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, log124 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, log131 48 132 49 class InterswitchActionButtonStudent(APABStudent): … … 224 141 if self.context.p_category == 'schoolfee': 225 142 self.pay_item_id = '8302' 226 studycourse = student['studycourse']227 143 if student.current_mode in ('ug_sw','prence',): 228 144 xmldict['institution_acct'] = "6216801025" … … 334 250 335 251 def update(self): 336 ob_class = self.__implemented__.__name__337 252 if self.context.p_state == 'paid': 338 253 self.flash(_('This ticket has already been paid.')) 339 254 return 340 255 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) 342 258 student.writeLogMessage(self, log) 343 259 if not success: … … 367 283 return 368 284 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) 370 287 applicant.writeLogMessage(self, log) 371 288 if not success:
Note: See TracChangeset for help on using the changeset viewer.