Changeset 17223 for main/kofacustom.lpng/trunk/src
- Timestamp:
- 13 Dec 2022, 21:15:18 (2 years ago)
- Location:
- main/kofacustom.lpng/trunk/src/kofacustom/lpng/interswitch
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/kofacustom.lpng/trunk/src/kofacustom/lpng/interswitch/browser.py
r17194 r17223 25 25 InterswitchPaymentVerifyWebservicePageApplicant, 26 26 InterswitchPaymentVerifyWebservicePageStudent, 27 InterswitchPageStudent, InterswitchPageApplicant, 27 InterswitchPageStudent, 28 InterswitchPageApplicant,) 29 from kofacustom.nigeria.interswitch.webcheckoutbrowser import ( 30 WebCheckoutPageStudent, 31 WebCheckoutPageApplicant, 32 WebCheckoutConfirmTransactionStudent, 33 WebCheckoutConfirmTransactionApplicant, 28 34 ) 29 35 from kofacustom.lpng.students.interfaces import ICustomStudentOnlinePayment … … 229 235 gateway_url = URL 230 236 mac = MAC 237 238 239 # WebCheckout customizations 240 241 class CustomWebCheckoutPageStudent(WebCheckoutPageStudent): 242 """ View which sends a POST request to the Interswitch 243 WebCheckout payment gateway. 244 """ 245 action = 'https://newwebpay.interswitchng.com/collections/w/pay' 246 currency = '566' 247 pay_item_id = 'Default_Payable_MX76823' 248 merchant_code = 'MX76823' 249 gateway_amt = GATEWAY_AMT 250 251 class CustomWebCheckoutPageApplicant(WebCheckoutPageApplicant): 252 """ View which sends a POST request to the Interswitch 253 WebCheckout payment gateway. 254 """ 255 256 action = 'https://newwebpay.interswitchng.com/collections/w/pay' 257 currency = '566' 258 pay_item_id = 'Default_Payable_MX76823' 259 merchant_code = 'MX76823' 260 gateway_amt = GATEWAY_AMT 261 262 class CustomWebCheckoutConfirmTransactionStudent(WebCheckoutConfirmTransactionStudent): 263 """ Request webservice view for the WebCheckout gateway 264 """ 265 merchant_code = 'MX76823' 266 gateway_host = 'webpay.interswitchng.com' 267 gateway_url = '/collections/api/v1/gettransaction.json' 268 https = True 269 270 class CustomWebCheckoutConfirmTransactionApplicant(WebCheckoutConfirmTransactionApplicant): 271 """ Request webservice view for the WebCheckout gateway 272 """ 273 merchant_code = 'MX76823' 274 gateway_host = 'webpay.interswitchng.com' 275 gateway_url = '/collections/api/v1/gettransaction.json' 276 https = True 277 278 -
main/kofacustom.lpng/trunk/src/kofacustom/lpng/interswitch/tests.py
r17023 r17223 22 22 from hurry.workflow.interfaces import IWorkflowState 23 23 from waeup.kofa.students.tests.test_browser import StudentsFullSetup 24 from waeup.kofa.students.payments import StudentOnlinePayment 24 25 from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup 25 26 from waeup.kofa.configuration import SessionConfiguration 27 from kofacustom.nigeria.interswitch.helpers import confirm_transaction 26 28 from kofacustom.lpng.testing import FunctionalLayer 27 29 … … 35 37 myself = __file__ 36 38 if myself.endswith('.pyc'): 37 myself = myself[:- 2]39 myself = myself[:-1] 38 40 print "WARNING: external tests are skipped!" 39 41 print "WARNING: edit %s to enable them." % myself 40 42 return 41 43 return func 42 43 44 class InterswitchTestsStudents(StudentsFullSetup):45 """Tests for the Interswitch payment gateway.46 """47 48 layer = FunctionalLayer49 50 def setUp(self):51 super(InterswitchTestsStudents, self).setUp()52 self.app['configuration']['2004'].interswitch_enabled = True53 54 def test_interswitch_form(self):55 # Manager can access InterswitchForm56 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')57 self.browser.open(self.payments_path)58 IWorkflowState(self.student).setState('cleared')59 self.student.nationality = u'NG'60 self.browser.open(self.payments_path + '/addop')61 self.browser.getControl(name="form.p_category").value = ['schoolfee']62 self.browser.getControl("Create ticket").click()63 self.assertMatches('...ticket created...',64 self.browser.contents)65 self.browser.open(self.payments_path)66 ctrl = self.browser.getControl(name='val_id')67 self.value = ctrl.options[0]68 self.browser.getLink(self.value).click()69 self.assertMatches('...Amount Authorized...',70 self.browser.contents)71 self.assertTrue(72 '<span>40000.0</span>' in self.browser.contents)73 self.payment_url = self.browser.url74 self.browser.getLink("Pay via Interswitch", index=0).click()75 self.assertTrue('<input type="hidden" name="pay_item_id" value="0000" />' in76 self.browser.contents)77 self.assertEqual(self.student.current_mode, 'ug_ft')78 self.assertTrue(79 '<input type="hidden" name="amount" value="4015000" />' in80 self.browser.contents)81 self.assertTrue(82 'item_name="Annual Membership Fee" item_amt="4000000" bank_id="00" acct_num="00000000"' in83 self.browser.contents)84 85 def test_interswitch_form_ticket_expired(self):86 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')87 acc_payment = createObject('waeup.StudentOnlinePayment')88 acc_payment.p_state = 'unpaid'89 acc_payment.p_category = 'clearance'90 acc_payment.p_id = 'xyz'91 acc_payment.pay_item_id = '123'92 acc_payment.amount_auth = 1000.093 self.student['payments']['xyz'] = acc_payment94 self.browser.open(self.payments_path + '/xyz')95 self.browser.getLink("Pay via Interswitch", index=0).click()96 self.assertMatches('...<input type="hidden" name="pay_item_id" value="0000" />...',97 self.browser.contents)98 self.assertMatches('...Total Amount Authorized:...',99 self.browser.contents)100 self.assertEqual(self.student.current_mode, 'ug_ft')101 self.assertMatches(102 '...<input type="hidden" name="amount" value="115000" />...',103 self.browser.contents)104 delta = timedelta(days=8)105 acc_payment.creation_date -= delta106 self.browser.open(self.payments_path + '/xyz')107 self.browser.getLink("Pay via Interswitch", index=0).click()108 self.assertMatches(109 '...This payment ticket is too old. Please create a new ticket...',110 self.browser.contents)111 delta = timedelta(days=2)112 acc_payment.creation_date += delta113 self.browser.open(self.payments_path + '/xyz')114 self.browser.getLink("Pay via Interswitch", index=0).click()115 self.assertMatches('...Total Amount Authorized:...',116 self.browser.contents)117 118 @external_test119 def test_webservice(self):120 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')121 self.browser.open(self.payments_path)122 IWorkflowState(self.student).setState('cleared')123 self.student.nationality = u'NG'124 self.browser.open(self.payments_path + '/addop')125 self.browser.getControl(name="form.p_category").value = ['schoolfee']126 self.browser.getControl("Create ticket").click()127 self.assertMatches('...ticket created...',128 self.browser.contents)129 ctrl = self.browser.getControl(name='val_id')130 self.value = ctrl.options[0]131 self.browser.getLink(self.value).click()132 self.payment_url = self.browser.url133 # First we have open InterswitchPageStudent to set provider_amt134 # and gateway_amt135 self.browser.open(self.payment_url + '/goto_interswitch')136 # Now we can call the webservice137 self.browser.open(self.payment_url + '/request_webservice')138 self.assertMatches('...Unsuccessful callback...',139 self.browser.contents)140 # The payment is now in state failed ...141 self.assertMatches('...<span>Failed</span>...',142 self.browser.contents)143 # ... and the catalog has been updated144 cat = getUtility(ICatalog, name='payments_catalog')145 results = list(146 cat.searchResults(p_state=('failed', 'failed')))147 self.assertEqual(len(results), 1)148 self.assertEqual(results[0].p_state, 'failed')149 150 # Let's replace the p_id with a valid p_id of the Uniben151 # live system. This is definitely not an appropriate152 # solution for testing, but we have no choice since153 # Interswitch doesn't provide any interface154 # for testing.155 payment = self.student['payments'][self.value]156 payment.p_id = 'p3547789850240'157 self.browser.open(self.payment_url + '/request_webservice')158 self.assertMatches('...Callback amount does not match...',159 self.browser.contents)160 # The payment is now in state failed ...161 self.assertMatches('...<span>Failed</span>...',162 self.browser.contents)163 # Let's replace the amount autorized with the amount of the164 # live system payment165 payment.amount_auth = payment.r_amount_approved166 self.browser.open(self.payment_url + '/request_webservice')167 self.assertMatches('...Successful payment...',168 self.browser.contents)169 # The payment is now in state paid ...170 self.assertMatches('...<span>Paid</span>...',171 self.browser.contents)172 # ... and the catalog has been updated173 cat = getUtility(ICatalog, name='payments_catalog')174 results = list(175 cat.searchResults(p_state=('paid', 'paid')))176 self.assertEqual(len(results), 1)177 self.assertEqual(results[0].p_state, 'paid')178 # Approval is logged in students.log ...179 logfile = os.path.join(180 self.app['datacenter'].storage, 'logs', 'students.log')181 logcontent = open(logfile).read()182 self.assertTrue(183 'zope.mgr - '184 'kofacustom.lpng.interswitch.browser.CustomInterswitchPaymentRequestWebservicePageStudent - '185 'X1000000 - successful schoolfee payment: p3547789850240\n'186 in logcontent)187 # ... and in payments.log188 logfile = os.path.join(189 self.app['datacenter'].storage, 'logs', 'payments.log')190 logcontent = open(logfile).read()191 self.assertTrue(192 '"zope.mgr",X1000000,p3547789850240,schoolfee,'193 '12000.0,00,0.0,150.0,0.0,,,\n'194 in logcontent)195 44 196 45 … … 218 67 self.browser.getControl(name="form.email").value = 'xx@yy.zz' 219 68 self.applicantscontainer.application_fee = 1000.0 220 self.browser.getControl(name="form.nationality").value = ['NG']221 69 self.browser.getControl(name="transition").value = ['start'] 222 70 self.browser.getControl("Save").click() 223 self.browser.getControl("Pay membership").click() 71 72 73 def test_webcheckout_form(self): 74 self.browser.getControl("Make").click() 75 self.browser.getControl(name="form.balance_amount").value = '500' 76 self.browser.getControl(name="form.p_category").value = ['donation'] 77 self.browser.getControl("Create").click() 78 224 79 self.assertMatches('...ticket created...', 225 80 self.browser.contents) 226 #ctrl = self.browser.getControl(name='val_id') 227 #value = ctrl.options[0] 228 #self.browser.getLink(value).click() 81 229 82 self.assertMatches('...Amount Authorized...', 230 83 self.browser.contents) 231 84 self.assertMatches( 232 '...<span> 1000.0</span>...',85 '...<span>500.0</span>...', 233 86 self.browser.contents) 234 87 self.payment_url = self.browser.url 235 236 237 def disabled_test_interswitch_form(self):238 88 # Manager can access InterswitchForm 239 89 self.browser.getLink("Pay via Interswitch", index=0).click() … … 251 101 self.browser.contents) 252 102 103 104 # WebCheckout tests 105 106 # https://webpay.interswitchng.com/collections/api/v1/gettransaction.json?merchantcode=MX76823&transactionreference=p6709347986663&amount=100 107 253 108 @external_test 254 def test_webservice(self): 109 def test_confirm_transaction(self): 110 host = 'webpay.interswitchng.com' 111 url = '/collections/api/v1/gettransaction.json' 112 https = True 113 merchant_code = 'MX76823' 114 payment = StudentOnlinePayment() 115 payment.p_id ='p4465649308559' 116 success, msg, log = confirm_transaction( 117 payment, merchant_code, host, url, https) 118 self.assertFalse(success) 119 self.assertTrue('Unsuccessful callback:' in msg) 120 self.assertTrue('Transaction not Found' in log) 255 121 256 self.browser.open(self.payment_url + '/request_webservice') 257 self.assertMatches('...Unsuccessful callback...', 258 self.browser.contents) 259 # The payment is now in state failed 260 self.assertMatches('...<span>Failed</span>...', 261 self.browser.contents) 122 payment.p_id ='p6709347986663' 123 payment.amount_auth = 1.0 124 success, msg, log = confirm_transaction( 125 payment, merchant_code, host, url, https) 126 self.assertTrue('Amount Inconsistency' in log) 127 payment.amount_auth = 100.0 128 success, msg, log = confirm_transaction( 129 payment, merchant_code, host, url, https) 130 self.assertEqual('Successful callback received', msg) 131 self.assertTrue(success) 132 self.assertTrue( 133 "{u'SplitAccounts': [], " 134 "u'RemittanceAmount': 0, " 135 "u'MerchantReference': u'p6709347986663', " 136 "u'PaymentReference': u'FBN|WEB|MX76823|13-12-2022|935097929|608001', " 137 "u'TransactionDate': u'2022-12-13T01:34:21', " 138 "u'RetrievalReferenceNumber': u'814212374638', " 139 "u'ResponseDescription': u'Approved by Financial Institution', " 140 "u'Amount': 10000, " 141 "u'CardNumber': u'', " 142 "u'ResponseCode': u'00', " 143 "u'BankCode': u'011'}" in log)
Note: See TracChangeset for help on using the changeset viewer.