Changeset 8247 for main/waeup.uniben/trunk/src/waeup/uniben/etranzact
- Timestamp:
- 22 Apr 2012, 12:56:07 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.uniben/trunk/src/waeup/uniben/etranzact/browser.py
r8129 r8247 23 23 from waeup.kofa.browser.layout import KofaPage, UtilityView 24 24 from waeup.kofa.students.interfaces import IStudentOnlinePayment 25 from waeup.kofa.students.browser import write_log_message 26 from waeup.kofa.students.viewlets import RequestCallbackActionButton 25 from waeup.kofa.applicants.interfaces import IApplicantOnlinePayment 26 from waeup.kofa.applicants.viewlets import RequestCallbackActionButton as RCABApplicant 27 from waeup.kofa.students.viewlets import RequestCallbackActionButton as RCABStudent 27 28 from waeup.uniben.interfaces import MessageFactory as _ 28 from waeup.uniben.utils.utils import actions_after_payment 29 from waeup.uniben.students.utils import actions_after_student_payment 30 from waeup.uniben.applicants.utils import actions_after_applicant_payment 29 31 30 TERMINAL_ID = '0 000000001'31 QUERY_URL = 'http ://demo.etranzact.com:8080/WebConnect/queryPayoutletTransaction.jsp'32 TERMINAL_ID = '0500000003' 33 QUERY_URL = 'https://www.etranzact.net/Query/queryPayoutletTransaction.jsp' 32 34 33 class EtranzactEnterPinActionButton(RequestCallbackActionButton): 34 grok.order(5) 35 36 def query_etranzact(confirmation_number, user, payment, view): 37 ob_class = view.__implemented__.__name__.replace('waeup.kofa.','') 38 postdict = {} 39 postdict['TERMINAL_ID'] = TERMINAL_ID 40 #postdict['RESPONSE_URL'] = 'http://dummy' 41 postdict['CONFIRMATION_NO'] = confirmation_number 42 data = urllib.urlencode(postdict) 43 try: 44 f = urllib.urlopen(url=QUERY_URL, data=data) 45 success = f.read() 46 user.loggerInfo(ob_class, 'callback received: %s' % success) 47 if 'COL1' not in success: 48 view.flash(_('Invalid or unsuccessful callback: ${a}', 49 mapping = {'a': success})) 50 user.loggerInfo(ob_class, 'invalid callback: %s' % payment.p_id) 51 payment.p_state = 'failed' 52 return False 53 success = success.replace('%20',' ').split('&') 54 # We expect at least two parameters 55 if len(success) < 2: 56 view.flash(_('Invalid callback: ${a}', 57 mapping = {'a': success})) 58 user.loggerInfo(ob_class, 'invalid callback: %s' % payment.p_id) 59 payment.p_state = 'failed' 60 return False 61 try: 62 success_dict = dict([tuple(i.split('=')) for i in success]) 63 except ValueError: 64 view.flash(_('Invalid callback: ${a}', 65 mapping = {'a': success})) 66 user.loggerInfo(ob_class, 'invalid callback: %s' % payment.p_id) 67 payment.p_state = 'failed' 68 return False 69 except IOError: 70 view.flash(_('eTranzact IOError')) 71 return False 72 payment.r_code = u'ET' 73 payment.r_desc = u'%s' % success_dict.get('TRANS_DESCR') 74 payment.r_amount_approved = float(success_dict.get('TRANS_AMOUNT',0.0)) 75 payment.r_card_num = None 76 payment.r_pay_reference = u'%s' % success_dict.get('RECEIPT_NO') 77 if payment.r_amount_approved != payment.amount_auth: 78 view.flash(_('Wrong amount')) 79 user.loggerInfo(ob_class, 'successful callback but wrong amount: %s' 80 % payment.p_id) 81 payment.p_state = 'failed' 82 return False 83 tcode = payment.p_id 84 tcode = tcode[len(tcode)-8:len(tcode)] 85 col1 = success_dict.get('COL1') 86 col1 = col1[len(col1)-8:len(col1)] 87 if tcode != col1: 88 view.flash(_('Wrong transaction code')) 89 write_log_message( 90 view,'successful callback but wrong transaction code: %s' 91 % payment.p_id) 92 user.loggerInfo(ob_class, 'successful callback wrong transaction code: %s' 93 % payment.p_id) 94 payment.p_state = 'failed' 95 return False 96 user.loggerInfo(ob_class, 'successful callback: %s' % payment.p_id) 97 payment.p_state = 'paid' 98 payment.payment_date = datetime.now() 99 return True 100 101 class EtranzactEnterPinActionButtonApplicant(RCABApplicant): 35 102 icon = 'actionicon_call.png' 36 103 text = _('Query eTranzact History') 37 104 target = 'enterpin' 38 105 39 class EtranzactEnterPinPage(KofaPage): 106 class EtranzactEnterPinActionButtonStudent(RCABStudent): 107 icon = 'actionicon_call.png' 108 text = _('Query eTranzact History') 109 target = 'enterpin' 110 111 class EtranzactEnterPinPageStudent(KofaPage): 40 112 """ 41 113 """ … … 49 121 action = 'query_history' 50 122 51 class EtranzactQueryHistoryPage(UtilityView, grok.View): 123 class EtranzactEnterPinPageApplicant(EtranzactEnterPinPageStudent): 124 """ 125 """ 126 grok.require('waeup.payApplicant') 127 grok.context(IApplicantOnlinePayment) 128 129 class EtranzactQueryHistoryPageStudent(UtilityView, grok.View): 52 130 """ Query history of eTranzact payments 53 131 """ … … 61 139 return 62 140 student = self.context.getStudent() 63 postdict = {} 64 postdict['TERMINAL_ID'] = TERMINAL_ID 65 #postdict['RESPONSE_URL'] = 'http://dummy' 66 postdict['CONFIRMATION_NO'] = confirmation_number 67 data = urllib.urlencode(postdict) 68 try: 69 f = urllib.urlopen(url=QUERY_URL, data=data) 70 success = f.read() 71 if '-1' in success: 72 self.flash(_('Unsuccessful callback')) 73 write_log_message(self,'unsuccessful callback: %s' % self.context.p_id) 74 self.context.p_state = 'failed' 75 return 76 success = success.replace('%20',' ').split('&') 77 # We expect at least two parameters 78 if len(success) < 2: 79 self.flash(_('Invalid callback: ${a}', 80 mapping = {'a': success})) 81 write_log_message(self,'invalid callback: %s' % self.context.p_id) 82 self.context.p_state = 'failed' 83 return 84 try: 85 success_dict = dict([tuple(i.split('=')) for i in success]) 86 except ValueError: 87 self.flash(_('Invalid callback: ${a}', 88 mapping = {'a': success})) 89 write_log_message(self,'invalid callback: %s' % self.context.p_id) 90 self.context.p_state = 'failed' 91 return 92 except IOError: 93 self.flash(_('eTranzact IOError')) 94 return 95 write_log_message(self,'callback received: %s' % success) 96 97 self.context.r_code = u'ET' 98 self.context.r_desc = u'%s' % success_dict.get('TRANS_DESCR') 99 self.context.r_amount_approved = float(success_dict.get('TRANS_AMOUNT',0.0)) 100 self.context.r_card_num = None 101 self.context.r_pay_reference = u'%s' % success_dict.get('RECEIPT_NO') 102 103 if self.context.r_amount_approved != self.context.amount_auth: 104 self.flash(_('Wrong amount')) 105 write_log_message( 106 self,'successful callback but wrong amount: %s' 107 % self.context.p_id) 108 self.context.p_state = 'failed' 109 return 110 111 if success_dict.get('COL1') != self.context.p_id: 112 self.flash(_('Wrong transaction id')) 113 write_log_message( 114 self,'successful callback but wrong transaction id: %s' 115 % self.context.p_id) 116 self.context.p_state = 'failed' 117 return 118 119 write_log_message(self,'successful callback: %s' % self.context.p_id) 120 121 self.context.p_state = 'paid' 122 self.context.payment_date = datetime.now() 123 124 actions_after_payment(student, self.context, self) 125 141 if query_etranzact(confirmation_number, student, self.context, self): 142 actions_after_student_payment(student, self.context, self) 126 143 return 127 144 … … 129 146 self.redirect(self.url(self.context, '@@index')) 130 147 return 148 149 class EtranzactQueryHistoryPageApplicant(UtilityView, grok.View): 150 """ Query history of eTranzact payments 151 """ 152 grok.context(IApplicantOnlinePayment) 153 grok.name('query_history') 154 grok.require('waeup.payApplicant') 155 156 def update(self, confirmation_number=None): 157 if self.context.p_state == 'paid': 158 self.flash(_('This ticket has already been paid.')) 159 return 160 applicant = self.context.__parent__ 161 if query_etranzact(confirmation_number, applicant, self.context, self): 162 actions_after_applicant_payment(applicant, self) 163 return 164 165 def render(self): 166 self.redirect(self.url(self.context, '@@index')) 167 return
Note: See TracChangeset for help on using the changeset viewer.