- Timestamp:
- 12 May 2012, 08:43:51 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.uniben/trunk/src/waeup/uniben/etranzact/browser.py
r8267 r8430 22 22 import grok 23 23 from waeup.kofa.browser.layout import KofaPage, UtilityView 24 from waeup.kofa. applicants.viewlets import RequestCallbackActionButton as RCABApplicant25 from waeup.kofa. students.viewlets import RequestCallbackActionButton as RCABStudent24 from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent 25 from waeup.kofa.applicants.viewlets import ApprovePaymentActionButton as APABApplicant 26 26 from waeup.uniben.interfaces import MessageFactory as _ 27 from waeup.uniben.students.utils import actions_after_student_payment28 from waeup.uniben.applicants.utils import actions_after_applicant_payment29 27 from waeup.uniben.students.interfaces import ICustomStudentOnlinePayment 30 28 from waeup.uniben.applicants.interfaces import ICustomApplicantOnlinePayment … … 35 33 QUERY_URL = 'http://demo.etranzact.com:8080/WebConnect/queryPayoutletTransaction.jsp' 36 34 37 def query_etranzact(confirmation_number, user, payment, view):38 ob_class = view.__implemented__.__name__35 def query_etranzact(confirmation_number, payment): 36 39 37 postdict = {} 40 38 postdict['TERMINAL_ID'] = TERMINAL_ID … … 45 43 f = urllib.urlopen(url=QUERY_URL, data=data) 46 44 success = f.read() 47 user.loggerInfo(ob_class, 'callback received: %s' % success)48 45 if 'COL1' not in success: 49 view.flash(_('Invalid or unsuccessful callback: ${a}',50 mapping = {'a': success}) )51 user.loggerInfo(ob_class, 'invalid callback: %s' % payment.p_id)46 msg = _('Invalid or unsuccessful callback: ${a}', 47 mapping = {'a': success}) 48 log = 'invalid callback for payment %s: %s' % (payment.p_id, success) 52 49 payment.p_state = 'failed' 53 return False 50 return False, msg, log 54 51 success = success.replace('%20',' ').split('&') 55 52 # We expect at least two parameters 56 53 if len(success) < 2: 57 view.flash(_('Invalid callback: ${a}', 58 mapping = {'a': success})) 59 user.loggerInfo(ob_class, 'invalid callback: %s' % payment.p_id) 54 msg = _('Invalid callback: ${a}', mapping = {'a': success}) 55 log = 'invalid callback for payment %s: %s' % (payment.p_id, success) 60 56 payment.p_state = 'failed' 61 return False 57 return False, msg, log 62 58 try: 63 59 success_dict = dict([tuple(i.split('=')) for i in success]) 64 60 except ValueError: 65 view.flash(_('Invalid callback: ${a}', 66 mapping = {'a': success})) 67 user.loggerInfo(ob_class, 'invalid callback: %s' % payment.p_id) 61 msg = _('Invalid callback: ${a}', mapping = {'a': success}) 62 log = 'invalid callback for payment %s: %s' % (payment.p_id, success) 68 63 payment.p_state = 'failed' 69 return False 64 return False, msg, log 70 65 except IOError: 71 view.flash(_('eTranzact IOError')) 72 return False 66 msg = _('eTranzact IOError') 67 log = 'eTranzact IOError' 68 return False, msg, log 73 69 payment.r_code = u'ET' 74 70 payment.r_desc = u'%s' % success_dict.get('TRANS_DESCR') … … 77 73 payment.r_pay_reference = u'%s' % success_dict.get('RECEIPT_NO') 78 74 if payment.r_amount_approved != payment.amount_auth: 79 view.flash(_('Wrong amount')) 80 user.loggerInfo(ob_class, 'successful callback but wrong amount: %s' 81 % payment.p_id) 75 msg = _('Wrong amount') 76 log = 'wrong callback for payment %s: %s' % (payment.p_id, success) 82 77 payment.p_state = 'failed' 83 return False 78 return False, msg, log 84 79 tcode = payment.p_id 85 80 tcode = tcode[len(tcode)-8:len(tcode)] … … 87 82 col1 = col1[len(col1)-8:len(col1)] 88 83 if tcode != col1: 89 view.flash(_('Wrong transaction code')) 90 write_log_message( 91 view,'successful callback but wrong transaction code: %s' 92 % payment.p_id) 93 user.loggerInfo(ob_class, 'successful callback wrong transaction code: %s' 94 % payment.p_id) 84 msg = _('Wrong transaction code') 85 log = 'wrong callback for payment %s: %s' % (payment.p_id, success) 95 86 payment.p_state = 'failed' 96 return False 97 user.loggerInfo(ob_class, 'successful callback: %s' % payment.p_id) 87 return False, msg, log 88 log = 'valid callback for payment %s: %s' % (payment.p_id, success) 89 msg = _('Successful callback received') 98 90 payment.p_state = 'paid' 99 91 payment.payment_date = datetime.now() 100 return True 92 return True, msg, log 101 93 102 class EtranzactEnterPinActionButtonApplicant( RCABApplicant):94 class EtranzactEnterPinActionButtonApplicant(APABApplicant): 103 95 grok.context(ICustomApplicantOnlinePayment) 96 grok.require('waeup.payApplicant') 104 97 grok.order(3) 105 98 icon = 'actionicon_call.png' … … 107 100 target = 'enterpin' 108 101 109 class EtranzactEnterPinActionButtonStudent( RCABStudent):102 class EtranzactEnterPinActionButtonStudent(APABStudent): 110 103 grok.context(ICustomStudentOnlinePayment) 104 grok.require('waeup.payStudent') 111 105 grok.order(3) 112 106 icon = 'actionicon_call.png' … … 140 134 141 135 def update(self, confirmation_number=None): 136 ob_class = self.__implemented__.__name__ 142 137 if self.context.p_state == 'paid': 143 138 self.flash(_('This ticket has already been paid.')) 144 139 return 145 140 student = self.context.getStudent() 146 if query_etranzact(confirmation_number, student, self.context, self): 147 actions_after_student_payment(student, self.context, self) 141 success, msg, log = query_etranzact(confirmation_number,self.context) 142 student.loggerInfo(ob_class, log) 143 if not success: 144 self.flash(msg) 145 return 146 success, msg, log = self.context.doAfterStudentPayment() 147 if log is not None: 148 student.loggerInfo(ob_class, log) 149 self.flash(msg) 148 150 return 149 151 … … 160 162 161 163 def update(self, confirmation_number=None): 164 ob_class = self.__implemented__.__name__ 162 165 if self.context.p_state == 'paid': 163 166 self.flash(_('This ticket has already been paid.')) 164 167 return 165 168 applicant = self.context.__parent__ 166 if query_etranzact(confirmation_number, applicant, self.context, self): 167 actions_after_applicant_payment(applicant, self) 169 success, msg, log = query_etranzact(confirmation_number,self.context) 170 applicant.loggerInfo(ob_class, log) 171 if not success: 172 self.flash(msg) 173 return 174 success, msg, log = self.context.doAfterApplicantPayment() 175 if log is not None: 176 applicant.loggerInfo(ob_class, log) 177 self.flash(msg) 168 178 return 169 179
Note: See TracChangeset for help on using the changeset viewer.