Changeset 9285 for main/waeup.futminna/trunk/src
- Timestamp:
- 4 Oct 2012, 09:32:39 (12 years ago)
- Location:
- main/waeup.futminna/trunk/src/waeup/futminna/interswitch
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.futminna/trunk/src/waeup/futminna/interswitch/browser.py
r8957 r9285 24 24 from waeup.kofa.browser.layout import KofaPage, UtilityView 25 25 from waeup.kofa.accesscodes import create_accesscode 26 from waeup.kofa.interfaces import RETURNING, IKofaUtils26 from waeup.kofa.interfaces import RETURNING, CLEARED, IKofaUtils 27 27 from waeup.kofa.utils.helpers import to_timezone 28 28 from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent … … 33 33 from waeup.futminna.interfaces import MessageFactory as _ 34 34 35 PRODUCT_ID = ' 57'35 PRODUCT_ID = '117' 36 36 SITE_NAME = 'futminna-kofa.waeup.org' 37 PROVIDER_ACCT = ' 1010764827'38 PROVIDER_BANK_ID = ' 117'37 PROVIDER_ACCT = '0061001000021095' 38 PROVIDER_BANK_ID = '89' 39 39 PROVIDER_ITEM_NAME = 'BT Education' 40 40 INSTITUTION_NAME = 'FUTMinna' … … 136 136 return self.view.url(self.view.context, self.target) 137 137 138 class InterswitchActionButtonApplicant(APABApplicant):139 grok.order(1)140 grok.context(ICustomApplicantOnlinePayment)141 grok.require('waeup.payApplicant')142 icon = 'actionicon_pay.png'143 text = _('CollegePAY')144 target = 'goto_interswitch'145 146 @property147 def target_url(self):148 if self.context.p_state != 'unpaid':149 return ''150 return self.view.url(self.view.context, self.target)151 152 # Deprecated153 #class InterswitchRequestCallbackActionButtonStudent(RCABStudent):154 # grok.order(3)155 # grok.context(ICustomStudentOnlinePayment)156 # icon = 'actionicon_call.png'157 # text = _('Request CollegePAY callback')158 159 # def target_url(self):160 # if self.context.p_state == 'paid':161 # return ''162 # site_redirect_url = self.view.url(self.view.context, 'isw_callback')163 # args = {164 # 'transRef':self.context.p_id,165 # 'prodID':PRODUCT_ID,166 # 'redirectURL':site_redirect_url}167 # return QUERY_URL + '?%s' % urllib.urlencode(args)168 169 # Alternative preferred solution170 138 class InterswitchRequestWebserviceActionButtonStudent(APABStudent): 171 139 grok.order(2) … … 175 143 text = _('Requery CollegePAY') 176 144 target = 'request_webservice' 177 178 class InterswitchRequestWebserviceActionButtonApplicant(APABApplicant):179 grok.order(2)180 grok.context(ICustomApplicantOnlinePayment)181 grok.require('waeup.payApplicant')182 icon = 'actionicon_call.png'183 text = _('Requery CollegePAY')184 target = 'request_webservice'185 186 145 187 146 class InterswitchPageStudent(KofaPage): … … 229 188 xmldict['provider_bank_id'] = PROVIDER_BANK_ID 230 189 xmldict['provider_item_name'] = PROVIDER_ITEM_NAME 231 if student.current_mode.endswith('_ft') \ 232 and student.state == RETURNING: 233 provider_amt = 600 234 else: 235 provider_amt = 1500 190 provider_amt = 1500 236 191 xmldict['provider_amt'] = 100 * provider_amt 192 237 193 # Institution data 238 194 studycourse = student['studycourse'] … … 241 197 xmldict['institution_acct'] = '000000000000' 242 198 xmldict['institution_bank_id'] = '00' 243 xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - 150) 199 xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - 300) 200 201 if self.context.student.current_mode in ('pg_ft'): 202 pay_item_id = "11703" 203 elif self.context.student.state == CLEARED and \ 204 self.context.student.current_level == 100: 205 pay_item_id = "11700" 206 elif self.context.student.state == CLEARED and \ 207 self.context.student.current_level == 200: 208 pay_item_id = "11701" 209 elif self.context.student.state == CLEARED and \ 210 self.context.student.current_level == 300: 211 pay_item_id = "11702" 212 elif self.context.student.state == RETURNING and \ 213 self.context.student.current_level in (100,110): 214 pay_item_id = "11701" 215 elif self.context.student.state == RETURNING and \ 216 self.context.student.current_level in (200,210): 217 pay_item_id = "11702" 218 elif self.context.student.state == RETURNING and \ 219 self.context.student.current_level in (300,310): 220 pay_item_id = "11703" 221 elif self.context.student.state == RETURNING and \ 222 self.context.student.current_level in (400,410,500,510,600): 223 pay_item_id = "11704" 224 else: 225 pay_item_id = "" 226 227 if self.context.student.current_mode == 'jm_ft': 228 xmldict['institution_acct'] = "000000000000" 229 xmldict['institution_bank_id'] = '0' 230 elif self.context.student.current_mode == 'pg_ft': 231 xmldict['institution_acct'] = "2522040000134" 232 xmldict['institution_bank_id'] = '8' 233 elif self.context.student.state == CLEARED and \ 234 self.context.student.current_level == 100: 235 xmldict['institution_acct'] = "0030001000017110" 236 xmldict['institution_bank_id'] = '89' 237 elif self.context.student.state == CLEARED and \ 238 self.context.student.current_level == 200: 239 xmldict['institution_acct'] = "0591201005146" 240 xmldict['institution_bank_id'] = '101' 241 elif self.context.student.state == CLEARED and \ 242 self.context.student.current_level == 300: 243 xmldict['institution_acct'] = "6013803345" 244 xmldict['institution_bank_id'] = '117' 245 elif self.context.student.state == RETURNING and \ 246 self.context.student.current_level in (100,110): 247 xmldict['institution_acct'] = "0591201005146" 248 xmldict['institution_bank_id'] = '101' 249 elif self.context.student.current_level in (200,210): 250 xmldict['institution_acct'] = "6013803345" 251 xmldict['institution_bank_id'] = '117' 252 elif self.context.student.current_level in (300,310): 253 xmldict['institution_acct'] = "2522040000134" 254 xmldict['institution_bank_id'] = '8' 255 #Change of acct from UBA to GTBank 256 elif self.context.student.current_level in (400,410,500,510,600): 257 xmldict['institution_acct'] = "3713516838111" 258 xmldict['institution_bank_id'] = '10' 259 244 260 xmldict['institution_item_name'] = self.context.p_category 245 261 xmldict['institution_name'] = INSTITUTION_NAME … … 254 270 return 255 271 256 class InterswitchPageApplicant(KofaPage):257 """ View which sends a POST request to the Interswitch258 CollegePAY payment gateway.259 """260 grok.context(ICustomApplicantOnlinePayment)261 grok.require('waeup.payApplicant')262 grok.template('applicant_goto_interswitch')263 grok.name('goto_interswitch')264 label = _('Submit data to CollegePAY (Interswitch Payment Gateway)')265 submit_button = _('Submit')266 action = POST_ACTION267 site_name = SITE_NAME268 currency = CURRENCY269 pay_item_id = '5703'270 product_id = PRODUCT_ID271 272 def update(self):273 if self.context.p_state != 'unpaid':274 self.flash(_("Payment ticket can't be re-send to CollegePAY."))275 self.redirect(self.url(self.context, '@@index'))276 return277 if self.context.__parent__.__parent__.expired \278 and self.context.__parent__.__parent__.strict_deadline:279 self.flash(_("Payment ticket can't be send to CollegePAY. "280 "Application period has expired."))281 self.redirect(self.url(self.context, '@@index'))282 return283 self.applicant = self.context.__parent__284 self.amount_auth = 100 * self.context.amount_auth285 xmldict = {}286 self.category = payment_categories.getTermByToken(287 self.context.p_category).title288 tz = getUtility(IKofaUtils).tzinfo289 self.local_date_time = to_timezone(290 self.context.creation_date, tz).strftime("%Y-%m-%d %H:%M:%S %Z")291 self.site_redirect_url = self.url(self.context, 'request_webservice')292 if self.applicant.applicant_id.startswith('pg'):293 provider_amt = 400294 xmldict['institution_acct'] = '0031716030'295 xmldict['institution_bank_id'] = '10'296 else:297 provider_amt = 250298 xmldict['institution_acct'] = '6220032503'299 xmldict['institution_bank_id'] = '51'300 xmldict['detail_ref'] = self.context.p_id301 xmldict['provider_amt'] = 100 * provider_amt302 xmldict['provider_acct'] = PROVIDER_ACCT303 xmldict['provider_bank_id'] = PROVIDER_BANK_ID304 xmldict['provider_item_name'] = PROVIDER_ITEM_NAME305 xmldict['institution_amt'] = 100 * (self.context.amount_auth - provider_amt - 150)306 xmldict['institution_item_name'] = self.context.p_category307 xmldict['institution_name'] = INSTITUTION_NAME308 # Interswitch amount is not part of the xml data309 xmltext = """<payment_item_detail>310 <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s">311 <item_detail item_id="1" item_name="%(institution_item_name)s" item_amt="%(institution_amt)d" bank_id="%(institution_bank_id)s" acct_num="%(institution_acct)s" />312 <item_detail item_id="2" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" />313 </item_details>314 </payment_item_detail>""" % xmldict315 self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext316 return317 318 # Deprecated319 #class InterswitchPaymentCallbackPageStudent(UtilityView, grok.View):320 # """ Callback view for the CollegePAY gateway321 # """322 # grok.context(ICustomStudentOnlinePayment)323 # grok.name('isw_callback')324 # grok.require('waeup.payStudent')325 326 # This view is not yet working for offline querying transactions327 # since the query string differs from the query string sent after328 # posting transactions. This Interswitch bug must be removed first.329 # Alternatively, we could use the webservice only and replace330 # the RequestCallbackActionButton by a RequestWebserviceActionButton331 332 # def update(self):333 # if self.context.p_state == 'paid':334 # self.flash(_('This ticket has already been paid.'))335 # return336 # student = self.context.student337 # query = self.request.form338 # write_log_message(self,'callback received: %s' % query)339 # self.context.r_card_num = query.get('cardNum', None)340 # self.context.r_code = query.get('resp', None)341 # self.context.r_pay_reference = query.get('payRef', None)342 # self.context.r_amount_approved = float(query.get('apprAmt', '0.0')) / 100343 # self.context.r_desc = query.get('desc', None)344 # if self.context.r_code != '00':345 # self.flash(_('Unsuccessful callback: ${a}',346 # mapping = {'a': query.get('desc', _('Incomplete query string.'))}))347 # write_log_message(self,'unsuccessful callback: %s' % self.context.p_id)348 # self.context.p_state = 'failed'349 # return350 # if self.context.r_amount_approved != payment.amount_auth:351 # self.flash(_('Wrong amount'))352 # write_log_message(353 # self,'successful but wrong amount: %s' % self.context.p_id)354 # self.context.p_state = 'failed'355 # return356 # try:357 # validation_list = get_SOAP_response(358 # PRODUCT_ID, self.context.p_id).split(':')359 # Validation does not make sense yet since the query string360 # formats are conflicting. We are only printing the validation361 # string, nothing else.362 # print 'WARNING: Webservice validation is not yet implemented'363 # print 'validation list: %s' % validation_list364 # except:365 # print 'Connection to webservice failed.'366 # Add webservice validation here367 # write_log_message(self,'valid callback: %s' % self.context.p_id)368 # self.context.p_state = 'paid'369 # self.context.payment_date = datetime.utcnow()370 # actions_after_student_payment(student, self.context, self)371 # return372 373 # def render(self):374 # self.redirect(self.url(self.context, '@@index'))375 # return376 377 # Alternative solution, replaces InterswitchPaymentCallbackPage378 272 class InterswitchPaymentRequestWebservicePageStudent(UtilityView, grok.View): 379 273 """ Request webservice view for the CollegePAY gateway … … 403 297 self.redirect(self.url(self.context, '@@index')) 404 298 return 405 406 class InterswitchPaymentRequestWebservicePageApplicant(UtilityView, grok.View):407 """ Request webservice view for the CollegePAY gateway408 """409 grok.context(ICustomApplicantOnlinePayment)410 grok.name('request_webservice')411 grok.require('waeup.payApplicant')412 413 def update(self):414 if self.context.p_state == 'paid':415 self.flash(_('This ticket has already been paid.'))416 return417 applicant = self.context.__parent__418 success, msg, log = query_interswitch(self.context)419 applicant.writeLogMessage(self, log)420 if not success:421 self.flash(msg)422 return423 success, msg, log = self.context.doAfterApplicantPayment()424 if log is not None:425 applicant.writeLogMessage(self, log)426 self.flash(msg)427 return428 429 def render(self):430 self.redirect(self.url(self.context, '@@index'))431 return -
main/waeup.futminna/trunk/src/waeup/futminna/interswitch/tests.py
r9155 r9285 51 51 self.browser.open(self.payments_path + '/addop') 52 52 self.browser.getControl("Create ticket").click() 53 self.assertMatches('...Payment components not yet configured...',53 self.assertMatches('...Payment ticket created...', 54 54 self.browser.contents) 55 56 57 class InterswitchTestsApplicants(ApplicantsFullSetup): 58 """Tests for the Interswitch payment gateway. 59 """ 60 61 layer = FunctionalLayer 62 63 def setUp(self): 64 super(InterswitchTestsApplicants, self).setUp() 65 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 66 self.browser.open(self.manage_path) 67 #IWorkflowState(self.student).setState('started') 68 super(InterswitchTestsApplicants, self).fill_correct_values() 69 self.applicantscontainer.application_fee = 1000.0 70 self.browser.getControl(name="transition").value = ['start'] 71 self.browser.getControl("Save").click() 72 self.browser.getControl("Add online").click() 73 self.assertMatches('...ticket created...', 74 self.browser.contents) 75 #ctrl = self.browser.getControl(name='val_id') 76 #value = ctrl.options[0] 77 #self.browser.getLink(value).click() 55 ctrl = self.browser.getControl(name='val_id') 56 value = ctrl.options[0] 57 self.browser.getLink(value).click() 78 58 self.assertMatches('...Amount Authorized...', 79 59 self.browser.contents) 80 60 self.assertMatches( 81 '...<span>1 000.0</span>...',61 '...<span>131500.0</span>...', 82 62 self.browser.contents) 83 63 self.payment_url = self.browser.url 84 85 64 86 65 def test_interswitch_form(self): … … 91 70 self.browser.contents) 92 71 self.assertMatches( 93 '...<input type="hidden" name="amount" value="1 00000.0" />...',72 '...<input type="hidden" name="amount" value="13150000.0" />...', 94 73 self.browser.contents) 95 74 96 75 @external_test 97 76 def test_webservice(self): 98 99 77 self.browser.open(self.payment_url + '/request_webservice') 100 78 self.assertMatches('...Unsuccessful callback...',
Note: See TracChangeset for help on using the changeset viewer.