Changeset 9751 for main/waeup.kwarapoly
- Timestamp:
- 1 Dec 2012, 06:48:28 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kwarapoly/trunk/src/waeup/kwarapoly/interswitch/browser.py
r9737 r9751 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 19 import hashlib 22 from xml.dom.minidom import parseString23 20 import grok 24 from zope.event import notify25 21 from zope.interface import Interface 26 22 from zope.component import getUtility, queryAdapter 23 from kofacustom.nigeria.interswitch.helpers import query_interswitch 27 24 from waeup.kofa.browser.layout import KofaPage, UtilityView 28 from waeup.kofa.accesscodes import create_accesscode 29 from waeup.kofa.interfaces import RETURNING, IKofaUtils 25 from waeup.kofa.interfaces import IKofaUtils 30 26 from waeup.kofa.utils.helpers import to_timezone 31 27 from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent … … 55 51 httplib.HTTPConnection.debuglevel = 0 56 52 57 58 def SOAP_post(soap_action,xml):59 """Handles making the SOAP request.60 61 Further reading:62 http://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryWs.asmx?op=getTransactionData63 """64 h = httplib.HTTPConnection(HOST)65 headers={66 'Host':HOST,67 'Content-Type':'text/xml; charset=utf-8',68 'Content-Length':len(xml),69 'SOAPAction':'"%s"' % soap_action,70 }71 h.request('POST', URL, body=xml,headers=headers)72 r = h.getresponse()73 d = r.read()74 if r.status!=200:75 raise ValueError('Error connecting: %s, %s' % (r.status, r.reason))76 return d77 78 def get_SOAP_response(product_id, transref):79 xml="""\80 <?xml version="1.0" encoding="utf-8"?>81 <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/">82 <soap:Body>83 <getTransactionData xmlns="http://tempuri.org/">84 <product_id>%s</product_id>85 <trans_ref>%s</trans_ref>86 </getTransactionData>87 </soap:Body>88 </soap:Envelope>""" % (product_id, transref)89 result_xml=SOAP_post("http://tempuri.org/getTransactionData",xml)90 doc=parseString(result_xml)91 response=doc.getElementsByTagName('getTransactionDataResult')[0].firstChild.data92 return response93 94 def query_interswitch(payment):95 sr = get_SOAP_response(PRODUCT_ID, payment.p_id)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, 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 53 def interswitch_img_url(view): 137 54 static = view.static … … 139 56 'interswitch_verve_mastercard.gif', None) is None: 140 57 static = queryAdapter( 141 self.request, Interface, name='waeup.kwarapoly.interswitch')58 view.request, Interface, name='waeup.kwarapoly.interswitch') 142 59 return static['interswitch_verve_mastercard.gif']() 143 60 … … 368 285 369 286 def update(self): 370 ob_class = self.__implemented__.__name__371 287 if self.context.p_state == 'paid': 372 288 self.flash(_('This ticket has already been paid.')) 373 289 return 374 290 student = self.context.student 375 success, msg, log = query_interswitch(self.context) 291 success, msg, log = query_interswitch( 292 self.context, PRODUCT_ID, HOST, URL) 376 293 student.writeLogMessage(self, log) 377 294 if not success: … … 400 317 return 401 318 applicant = self.context.__parent__ 402 success, msg, log = query_interswitch(self.context) 319 success, msg, log = query_interswitch( 320 self.context, PRODUCT_ID, HOST, URL) 403 321 applicant.writeLogMessage(self, log) 404 322 if not success:
Note: See TracChangeset for help on using the changeset viewer.