Changeset 9780 for main/waeup.fceokene/trunk/src
- Timestamp:
- 6 Dec 2012, 17:52:21 (12 years ago)
- Location:
- main/waeup.fceokene/trunk/src/waeup/fceokene
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.fceokene/trunk/src/waeup/fceokene/interswitch/browser.py
r9752 r9780 19 19 import grok 20 20 from zope.component import getUtility 21 from kofacustom.nigeria.interswitch.helpers import query_interswitch 21 from kofacustom.nigeria.interswitch.helpers import ( 22 query_interswitch, write_payments_log) 22 23 from waeup.kofa.browser.layout import KofaPage, UtilityView 23 24 from waeup.kofa.interfaces import IKofaUtils … … 36 37 INSTITUTION_NAME = 'FCEOkene' 37 38 CURRENCY = '566' 39 GATEWAY_AMT = 150.0 38 40 #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' 39 41 #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' … … 129 131 self.site_redirect_url = self.url(self.context, 'request_webservice') 130 132 # Provider data 133 provider_amt = 1600.0 131 134 xmldict['detail_ref'] = self.context.p_id 132 135 xmldict['provider_acct'] = PROVIDER_ACCT 133 136 xmldict['provider_bank_id'] = PROVIDER_BANK_ID 134 137 xmldict['provider_item_name'] = PROVIDER_ITEM_NAME 135 xmldict['provider_amt'] = 100 * 1600138 xmldict['provider_amt'] = 100 * provider_amt 136 139 # Institution data 140 fceokene_split_amt = 1400.0 137 141 xmldict['fceokene_acct'] = "0000000000000" 138 142 xmldict['institution_bank_id'] = '0' … … 154 158 xmldict['institution_acct'] = "6216801025" 155 159 xmldict['institution_bank_id'] = '117' 156 xmldict['fceokene_split'] = 100 * 1400160 xmldict['fceokene_split'] = 100 * fceokene_split_amt 157 161 xmldict['institution_amt'] = 100 * ( 158 self.context.amount_auth - 1600 - 150 - 1400) 162 self.context.amount_auth - provider_amt - 163 GATEWAY_AMT - fceokene_split_amt) 159 164 elif 'maintenance' in self.context.p_category: 165 fceokene_split_amt = 0.0 166 provider_amt = 0.0 160 167 self.pay_item_id = '8300' 161 168 xmldict['institution_amt'] = 100 * ( 162 self.context.amount_auth - 150)169 self.context.amount_auth - GATEWAY_AMT) 163 170 xmldict['institution_acct'] = "1012044132" 164 171 xmldict['institution_bank_id'] = '117' … … 169 176 <item_details detail_ref="%(detail_ref)s" college="%(institution_name)s" department="%(department)s" faculty="%(faculty)s"> 170 177 <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" /> 171 <item_detail item_id="2" item_name="FCEOkene Split" item_amt="%(fceokene_split) s" bank_id="117" acct_num="6216801058" />178 <item_detail item_id="2" item_name="FCEOkene Split" item_amt="%(fceokene_split)d" bank_id="117" acct_num="6216801058" /> 172 179 <item_detail item_id="3" item_name="%(provider_item_name)s" item_amt="%(provider_amt)d" bank_id="%(provider_bank_id)s" acct_num="%(provider_acct)s" /> 173 180 </item_details> … … 182 189 183 190 self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext 191 self.context.provider_amt = provider_amt 192 self.context.gateway_amt = GATEWAY_AMT 193 self.context.thirdparty_amt = fceokene_split_amt 184 194 return 185 195 … … 221 231 xmldict['detail_ref'] = self.context.p_id 222 232 # Provider data 223 xmldict['provider_amt'] = 100 * 500 233 provider_amt = 500.0 234 xmldict['provider_amt'] = 100 * provider_amt 224 235 xmldict['provider_acct'] = PROVIDER_ACCT 225 236 xmldict['provider_bank_id'] = PROVIDER_BANK_ID 226 237 xmldict['provider_item_name'] = PROVIDER_ITEM_NAME 227 238 # Institution data 228 xmldict['institution_amt'] = 100 * (self.context.amount_auth - 500 - 150) 239 xmldict['institution_amt'] = 100 * (self.context.amount_auth - 240 provider_amt - GATEWAY_AMT) 229 241 xmldict['institution_acct'] = '1012445289' 230 242 xmldict['institution_bank_id'] = '117' … … 239 251 </payment_item_detail>""" % xmldict 240 252 self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext 253 self.context.provider_amt = provider_amt 254 self.context.gateway_amt = GATEWAY_AMT 241 255 return 242 256 … … 258 272 student.writeLogMessage(self, log) 259 273 if not success: 260 msg = self.request['QUERY_STRING'].replace('%20',' ')261 self.flash(_('Response from Interswitch: ') + msg)262 return274 self.flash(msg) 275 return 276 write_payments_log(student.student_id, self.context) 263 277 success, msg, log = self.context.doAfterStudentPayment() 264 278 if log is not None: … … 289 303 self.flash(msg) 290 304 return 305 write_payments_log(applicant.applicant_id, self.context) 291 306 success, msg, log = self.context.doAfterApplicantPayment() 292 307 if log is not None: -
main/waeup.fceokene/trunk/src/waeup/fceokene/interswitch/tests.py
r9711 r9780 16 16 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 17 ## 18 import os 18 19 from zope.component import getUtility 19 20 from zope.catalog.interfaces import ICatalog … … 27 28 # If you enable this, please make sure the external services 28 29 # do exist really and are not bothered by being spammed by a test programme. 29 EXTERNAL_TESTS = False30 EXTERNAL_TESTS = True 30 31 31 32 def external_test(func): … … 57 58 self.browser.contents) 58 59 ctrl = self.browser.getControl(name='val_id') 59 value = ctrl.options[0]60 self.browser.getLink( value).click()60 self.value = ctrl.options[0] 61 self.browser.getLink(self.value).click() 61 62 self.assertMatches('...Amount Authorized...', 62 63 self.browser.contents) … … 80 81 def test_interswitch_form(self): 81 82 83 self.assertEqual(self.student['payments'][self.value].provider_amt, 0.0) 84 self.assertEqual(self.student['payments'][self.value].gateway_amt, 0.0) 85 self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 0.0) 82 86 # Manager can access InterswitchForm for the created school fee ticket 83 87 self.browser.getLink("CollegePAY", index=0).click() 88 # Split amounts have been set 89 self.assertEqual(self.student['payments'][self.value].provider_amt, 1600.0) 90 self.assertEqual(self.student['payments'][self.value].gateway_amt, 150.0) 91 self.assertEqual(self.student['payments'][self.value].thirdparty_amt, 1400.0) 84 92 self.assertMatches('...Total Amount Authorized:...', 85 93 self.browser.contents) … … 133 141 self.browser.contents) 134 142 self.payment_url = self.browser.url 143 self.assertEqual(self.student['payments'][value].provider_amt, 0.0) 144 self.assertEqual(self.student['payments'][value].gateway_amt, 0.0) 145 self.assertEqual(self.student['payments'][value].thirdparty_amt, 0.0) 135 146 # Manager can access InterswitchForm 136 147 self.browser.getLink("CollegePAY", index=0).click() 148 # Split amounts have been set 149 self.assertEqual(self.student['payments'][value].provider_amt, 0.0) 150 self.assertEqual(self.student['payments'][value].gateway_amt, 150.0) 151 self.assertEqual(self.student['payments'][value].thirdparty_amt, 0.0) 137 152 # The total amount to be processed by Interswitch 138 153 # has been reduced by the Interswitch fee of 150 Nairas … … 171 186 @external_test 172 187 def test_webservice(self): 188 # First we have open InterswitchPageStudent to set provider_amt 189 # and gateway_amt 190 self.browser.open(self.payment_url + '/goto_interswitch') 191 # Now we can call the webservice 173 192 self.browser.open(self.payment_url + '/request_webservice') 174 193 #self.assertMatches('...Unsuccessful callback...', 175 194 # self.browser.contents) 176 self.assertMatches('... Response from Interswitch...',195 self.assertMatches('...Unsuccessful callback...', 177 196 self.browser.contents) 178 197 # The payment is now in state failed ... … … 185 204 self.assertEqual(len(results), 1) 186 205 self.assertEqual(results[0].p_state, 'failed') 206 207 # Let's replace the p_id with a valid p_id of the Uniben 208 # live system. This is definitely not an appropriate 209 # solution for testing, but we have no choice since 210 # Interswitch doesn't provide any interface 211 # for testing. 212 payment = self.student['payments'][self.value] 213 payment.p_id = 'p3536651296379' 214 self.browser.open(self.payment_url + '/request_webservice') 215 self.assertMatches('...Callback amount does not match...', 216 self.browser.contents) 217 # The payment is now in state failed ... 218 self.assertMatches('...<span>Failed</span>...', 219 self.browser.contents) 220 # Let's replace the amount autorized with the amount of the 221 # live system payment 222 payment.amount_auth = payment.r_amount_approved 223 self.browser.open(self.payment_url + '/request_webservice') 224 self.assertMatches('...Successful payment...', 225 self.browser.contents) 226 # The payment is now in state paid ... 227 self.assertMatches('...<span>Paid</span>...', 228 self.browser.contents) 229 # ... and the catalog has been updated 230 cat = getUtility(ICatalog, name='payments_catalog') 231 results = list( 232 cat.searchResults(p_state=('paid', 'paid'))) 233 self.assertEqual(len(results), 1) 234 self.assertEqual(results[0].p_state, 'paid') 235 # Approval is logged in students.log ... 236 logfile = os.path.join( 237 self.app['datacenter'].storage, 'logs', 'students.log') 238 logcontent = open(logfile).read() 239 self.assertTrue( 240 'zope.mgr - ' 241 'waeup.fceokene.interswitch.browser.InterswitchPaymentRequestWebservicePageStudent - ' 242 'K1000000 - successful schoolfee payment: p3536651296379\n' 243 in logcontent) 244 # ... and in payments.log 245 logfile = os.path.join( 246 self.app['datacenter'].storage, 'logs', 'payments.log') 247 logcontent = open(logfile).read() 248 self.assertTrue( 249 '"zope.mgr",K1000000,p3536651296379,schoolfee,' 250 '3150.0,00,1600.0,150.0,1400.0,,,\n' 251 in logcontent) 187 252 188 253 class InterswitchTestsApplicants(ApplicantsFullSetup): … … 205 270 self.assertMatches('...ticket created...', 206 271 self.browser.contents) 207 #ctrl = self.browser.getControl(name='val_id')208 #value = ctrl.options[0]209 #self.browser.getLink(value).click()210 272 self.assertMatches('...Amount Authorized...', 211 273 self.browser.contents) … … 214 276 self.browser.contents) 215 277 self.payment_url = self.browser.url 278 self.browser.open(self.manage_path) 279 ctrl = self.browser.getControl(name='val_id') 280 self.value = ctrl.options[0] 216 281 217 282 … … 219 284 220 285 # Manager can access InterswitchForm 286 self.browser.open(self.payment_url) 221 287 self.browser.getLink("CollegePAY", index=0).click() 222 288 self.assertMatches('...Total Amount Authorized:...', … … 228 294 @external_test 229 295 def test_webservice(self): 230 296 # First we have open InterswitchPageStudent to set provider_amt 297 # and gateway_amt 298 self.browser.open(self.payment_url + '/goto_interswitch') 299 # Now we can call the webservice 231 300 self.browser.open(self.payment_url + '/request_webservice') 232 301 self.assertMatches('...Unsuccessful callback...', 233 302 self.browser.contents) 234 # The payment is now in state failed 303 # The payment is now in state failed ... 235 304 self.assertMatches('...<span>Failed</span>...', 236 305 self.browser.contents) 306 # ... and the catalog has been updated 307 cat = getUtility(ICatalog, name='payments_catalog') 308 results = list( 309 cat.searchResults(p_state=('failed', 'failed'))) 310 self.assertEqual(len(results), 1) 311 self.assertEqual(results[0].p_state, 'failed') 312 313 # Let's replace the p_id with a valid p_id of the Uniben 314 # live system. This is definitely not an appropriate 315 # solution for testing, but we have no choice since 316 # Interswitch doesn't provide any interface 317 # for testing. 318 payment = self.applicant[self.value] 319 payment.p_id = 'p3536651296379' 320 self.browser.open(self.payment_url + '/request_webservice') 321 self.assertMatches('...Callback amount does not match...', 322 self.browser.contents) 323 # The payment is now in state failed ... 324 self.assertMatches('...<span>Failed</span>...', 325 self.browser.contents) 326 # Let's replace the amount autorized with the amount of the 327 # live system payment 328 payment.amount_auth = payment.r_amount_approved 329 self.browser.open(self.payment_url + '/request_webservice') 330 self.assertMatches('...Successful payment...', 331 self.browser.contents) 332 # The payment is now in state paid ... 333 self.assertMatches('...<span>Paid</span>...', 334 self.browser.contents) 335 # ... and the catalog has been updated 336 cat = getUtility(ICatalog, name='payments_catalog') 337 results = list( 338 cat.searchResults(p_state=('paid', 'paid'))) 339 self.assertEqual(len(results), 1) 340 self.assertEqual(results[0].p_state, 'paid') 341 # Approval is logged in students.log ... 342 logfile = os.path.join( 343 self.app['datacenter'].storage, 'logs', 'applicants.log') 344 logcontent = open(logfile).read() 345 self.assertTrue( 346 'zope.mgr - ' 347 'waeup.fceokene.interswitch.browser.InterswitchPaymentRequestWebservicePageApplicant - ' 348 '%s - successful payment: p3536651296379\n' 349 % self.applicant.applicant_id in logcontent) 350 # ... and in payments.log 351 logfile = os.path.join( 352 self.app['datacenter'].storage, 'logs', 'payments.log') 353 logcontent = open(logfile).read() 354 self.assertTrue( 355 '"zope.mgr",%s,p3536651296379,application,' 356 '3150.0,00,500.0,150.0,0.0,,,\n' % self.applicant.applicant_id 357 in logcontent) -
main/waeup.fceokene/trunk/src/waeup/fceokene/students/browser.py
r9406 r9780 36 36 """ 37 37 grok.context(ICustomStudentOnlinePayment) 38 form_fields = grok.AutoFields(ICustomStudentOnlinePayment) 38 form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( 39 'provider_amt', 'gateway_amt', 'thirdparty_amt') 39 40 form_fields[ 40 41 'creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') … … 52 53 """ 53 54 grok.context(ICustomStudentOnlinePayment) 54 form_fields = grok.AutoFields(ICustomStudentOnlinePayment) 55 form_fields = grok.AutoFields(ICustomStudentOnlinePayment).omit( 56 'provider_amt', 'gateway_amt', 'thirdparty_amt') 55 57 form_fields['creation_date'].custom_widget = FriendlyDatetimeDisplayWidget('le') 56 58 form_fields['payment_date'].custom_widget = FriendlyDatetimeDisplayWidget('le')
Note: See TracChangeset for help on using the changeset viewer.