Changeset 9785 for main/waeup.futminna/trunk/src/waeup/futminna/interswitch
- Timestamp:
- 7 Dec 2012, 08:59:30 (12 years ago)
- Location:
- main/waeup.futminna/trunk/src/waeup/futminna/interswitch
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.futminna/trunk/src/waeup/futminna/interswitch/browser.py
r9750 r9785 19 19 import grok 20 20 from zope.component import getUtility 21 from kofacustom.nigeria.interswitch.helpers import query_interswitch 22 from waeup.kofa.browser.layout import KofaPage, UtilityView 21 from kofacustom.nigeria.interswitch.browser import ( 22 InterswitchPaymentRequestWebservicePageStudent 23 ) 24 from waeup.kofa.browser.layout import KofaPage 23 25 from waeup.kofa.interfaces import RETURNING, CLEARED, IKofaUtils 24 26 from waeup.kofa.utils.helpers import to_timezone 25 from waeup.kofa.students.viewlets import ApprovePaymentActionButton as APABStudent26 27 from waeup.futminna.students.interfaces import ICustomStudentOnlinePayment 27 28 from waeup.futminna.interfaces import MessageFactory as _ … … 34 35 INSTITUTION_NAME = 'FUTMinna' 35 36 CURRENCY = '566' 37 GATEWAY_AMT = 300.0 36 38 #QUERY_URL = 'https://webpay.interswitchng.com/paydirect/services/TransactionQueryURL.aspx' 37 39 #QUERY_URL = 'https://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryURL.aspx' … … 44 46 #URL = '/test_paydirect/services/TransactionQueryWs.asmx' 45 47 httplib.HTTPConnection.debuglevel = 0 46 47 class InterswitchActionButtonStudent(APABStudent):48 grok.order(1)49 grok.context(ICustomStudentOnlinePayment)50 grok.require('waeup.payStudent')51 icon = 'actionicon_pay.png'52 text = _('CollegePAY')53 target = 'goto_interswitch'54 55 @property56 def target_url(self):57 if self.context.p_state != 'unpaid':58 return ''59 return self.view.url(self.view.context, self.target)60 61 class InterswitchRequestWebserviceActionButtonStudent(APABStudent):62 grok.order(2)63 grok.context(ICustomStudentOnlinePayment)64 grok.require('waeup.payStudent')65 icon = 'actionicon_call.png'66 text = _('Requery CollegePAY')67 target = 'request_webservice'68 48 69 49 class InterswitchPageStudent(KofaPage): … … 111 91 xmldict['provider_bank_id'] = PROVIDER_BANK_ID 112 92 xmldict['provider_item_name'] = PROVIDER_ITEM_NAME 113 provider_amt = 1500 93 provider_amt = 1500.0 114 94 xmldict['provider_amt'] = 100 * provider_amt 115 95 … … 124 104 if self.context.p_category == 'schoolfee': 125 105 xmldict['institution_amt'] = 100 * ( 126 self.context.amount_auth - provider_amt - 300)106 self.context.amount_auth - provider_amt - GATEWAY_AMT) 127 107 if self.context.student.current_mode in ('pg_ft'): 128 108 self.pay_item_id = "11703" … … 183 163 elif self.context.p_category == 'clearance': 184 164 xmldict['institution_amt'] = 100 * ( 185 self.context.amount_auth - 300)165 self.context.amount_auth - GATEWAY_AMT) 186 166 xmldict['institution_acct'] = "1750005063" 187 167 xmldict['institution_bank_id'] = '120' 188 168 self.pay_item_id = "11706" 169 provider_amt = 0.0 189 170 190 171 elif 'maintenance' in self.context.p_category: 191 172 xmldict['institution_amt'] = 100 * ( 192 self.context.amount_auth - 300)173 self.context.amount_auth - GATEWAY_AMT) 193 174 xmldict['institution_acct'] = "2018856637" 194 175 xmldict['institution_bank_id'] = '8' 195 176 self.pay_item_id = "11705" 177 provider_amt = 0.0 196 178 197 179 # Interswitch amount is not part of the xml data … … 220 202 221 203 self.xml_data = """<input type="hidden" name="xml_data" value='%s' />""" % xmltext 204 self.context.provider_amt = provider_amt 205 self.context.gateway_amt = GATEWAY_AMT 222 206 return 223 207 224 class InterswitchPaymentRequestWebservicePageStudent(UtilityView, grok.View): 208 class InterswitchPaymentRequestWebservicePageStudent( 209 InterswitchPaymentRequestWebservicePageStudent): 225 210 """ Request webservice view for the CollegePAY gateway 226 211 """ 227 212 grok.context(ICustomStudentOnlinePayment) 228 grok.name('request_webservice') 229 grok.require('waeup.payStudent') 230 231 def update(self): 232 if self.context.p_state == 'paid': 233 self.flash(_('This ticket has already been paid.')) 234 return 235 student = self.context.student 236 success, msg, log = query_interswitch( 237 self.context, PRODUCT_ID, HOST, URL) 238 student.writeLogMessage(self, log) 239 if not success: 240 self.flash(msg) 241 return 242 success, msg, log = self.context.doAfterStudentPayment() 243 if log is not None: 244 student.writeLogMessage(self, log) 245 self.flash(msg) 246 return 247 248 def render(self): 249 self.redirect(self.url(self.context, '@@index')) 250 return 213 product_id = PRODUCT_ID 214 gateway_host = HOST 215 gateway_url = URL -
main/waeup.futminna/trunk/src/waeup/futminna/interswitch/tests.py
r9714 r9785 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) … … 68 69 def test_interswitch_form(self): 69 70 # Manager can access InterswitchForm 71 self.assertEqual(self.student['payments'][self.value].provider_amt, 0.0) 72 self.assertEqual(self.student['payments'][self.value].gateway_amt, 0.0) 70 73 self.browser.getLink("CollegePAY", index=0).click() 74 # Split amounts have been set. 75 self.assertEqual(self.student['payments'][self.value].provider_amt, 1500.0) 76 self.assertEqual(self.student['payments'][self.value].gateway_amt, 300.0) 71 77 # The total amount to be processed by Interswitch 72 78 # has been reduced by the Interswitch fee of 150 Nairas … … 99 105 # Manager can access InterswitchForm 100 106 self.browser.getLink("CollegePAY", index=0).click() 107 # Split amounts have been set. 108 self.assertEqual(self.student['payments'][value].provider_amt, 0.0) 109 self.assertEqual(self.student['payments'][value].gateway_amt, 300.0) 101 110 # The total amount to be processed by Interswitch 102 111 # has been reduced by the Interswitch fee of 150 Nairas … … 143 152 # Manager can access InterswitchForm 144 153 self.browser.getLink("CollegePAY", index=0).click() 154 # Split amounts have been set. 155 self.assertEqual(self.student['payments'][value].provider_amt, 0.0) 156 self.assertEqual(self.student['payments'][value].gateway_amt, 300.0) 145 157 # The total amount to be processed by Interswitch 146 158 # has been reduced by the Interswitch fee of 150 Nairas … … 159 171 @external_test 160 172 def test_webservice(self): 173 # First we have open InterswitchPageStudent to set provider_amt 174 # and gateway_amt 175 self.browser.open(self.payment_url + '/goto_interswitch') 176 # Now we can call the webservice 161 177 self.browser.open(self.payment_url + '/request_webservice') 162 178 self.assertMatches('...Unsuccessful callback...', … … 171 187 self.assertEqual(len(results), 1) 172 188 self.assertEqual(results[0].p_state, 'failed') 189 190 # Let's replace the p_id with a valid p_id of the Uniben 191 # live system. This is definitely not an appropriate 192 # solution for testing, but we have no choice since 193 # Interswitch doesn't provide any interface 194 # for testing. 195 payment = self.student['payments'][self.value] 196 payment.p_id = 'p3522296094055' 197 self.browser.open(self.payment_url + '/request_webservice') 198 self.assertMatches('...Callback amount does not match...', 199 self.browser.contents) 200 # The payment is now in state failed ... 201 self.assertMatches('...<span>Failed</span>...', 202 self.browser.contents) 203 # Let's replace the amount autorized with the amount of the 204 # live system payment 205 payment.amount_auth = payment.r_amount_approved 206 self.browser.open(self.payment_url + '/request_webservice') 207 self.assertMatches('...Successful payment...', 208 self.browser.contents) 209 # The payment is now in state paid ... 210 self.assertMatches('...<span>Paid</span>...', 211 self.browser.contents) 212 # ... and the catalog has been updated 213 cat = getUtility(ICatalog, name='payments_catalog') 214 results = list( 215 cat.searchResults(p_state=('paid', 'paid'))) 216 self.assertEqual(len(results), 1) 217 self.assertEqual(results[0].p_state, 'paid') 218 # Approval is logged in students.log ... 219 logfile = os.path.join( 220 self.app['datacenter'].storage, 'logs', 'students.log') 221 logcontent = open(logfile).read() 222 self.assertTrue( 223 'zope.mgr - ' 224 'waeup.futminna.interswitch.browser.InterswitchPaymentRequestWebservicePageStudent - ' 225 'M1000000 - successful schoolfee payment: p3522296094055\n' 226 in logcontent) 227 # ... and in payments.log 228 logfile = os.path.join( 229 self.app['datacenter'].storage, 'logs', 'payments.log') 230 logcontent = open(logfile).read() 231 self.assertTrue( 232 '"zope.mgr",M1000000,p3522296094055,schoolfee,' 233 '20000.0,00,1500.0,300.0,0.0,,,\n' 234 in logcontent)
Note: See TracChangeset for help on using the changeset viewer.