Changeset 9750 for main/waeup.futminna/trunk/src/waeup
- Timestamp:
- 1 Dec 2012, 06:48:05 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.futminna/trunk/src/waeup/futminna/interswitch/browser.py
r9712 r9750 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_accesscode27 23 from waeup.kofa.interfaces import RETURNING, CLEARED, IKofaUtils 28 24 from waeup.kofa.utils.helpers import to_timezone 29 25 from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent 30 from waeup.kofa.applicants.viewlets import ApprovePaymentActionButton as APABApplicant31 26 from waeup.futminna.students.interfaces import ICustomStudentOnlinePayment 32 from waeup.futminna.applicants.interfaces import ICustomApplicantOnlinePayment33 27 from waeup.futminna.interfaces import MessageFactory as _ 34 28 … … 50 44 #URL = '/test_paydirect/services/TransactionQueryWs.asmx' 51 45 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 46 132 47 class InterswitchActionButtonStudent(APABStudent): … … 315 230 316 231 def update(self): 317 ob_class = self.__implemented__.__name__318 232 if self.context.p_state == 'paid': 319 233 self.flash(_('This ticket has already been paid.')) 320 234 return 321 235 student = self.context.student 322 success, msg, log = query_interswitch(self.context) 236 success, msg, log = query_interswitch( 237 self.context, PRODUCT_ID, HOST, URL) 323 238 student.writeLogMessage(self, log) 324 239 if not success:
Note: See TracChangeset for help on using the changeset viewer.