Changeset 14737 for main/kofacustom.nigeria/trunk/src/kofacustom
- Timestamp:
- 1 Aug 2017, 07:12:58 (7 years ago)
- Location:
- main/kofacustom.nigeria/trunk/src/kofacustom/nigeria
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/interswitch/tests.py
r13477 r14737 37 37 myself = __file__ 38 38 if myself.endswith('.pyc'): 39 myself = myself[:- 2]39 myself = myself[:-1] 40 40 print "WARNING: external tests are skipped!" 41 41 print "WARNING: edit %s to enable them." % myself -
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/payments/interfaces.py
r13743 r14737 79 79 (_('Interswitch'), 'interswitch'), 80 80 (_('eTranzact'), 'etranzact'), 81 (_('eRemita'), 'remita'), 81 82 (_('Scratch Card'), 'sc'), 82 83 (_('Manifest'), 'manifest'), -
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/remita/helpers.py
r14736 r14737 18 18 """General helper functions for the remita module in custom packages. 19 19 """ 20 import grok 20 21 from datetime import datetime 21 22 import httplib … … 51 52 h.request("POST", url, body=json.dumps(data), headers=headers) 52 53 resp = h.getresponse() 54 if resp.status!=200: 55 return {'error': 'Connection error (%s, %s)' % (response.status, response.reason)} 53 56 jsonout = resp.read() 54 57 try: 55 58 parsed_json = json.loads(jsonout[6:-1]) 56 59 except ValueError: 57 return None60 return {'error': 'No JSON response'} 58 61 return parsed_json 59 62 … … 72 75 h.request("GET", url, headers=headers) 73 76 resp = h.getresponse() 77 if resp.status!=200: 78 return {'error': 'Connection error (%s, %s)' % (response.status, response.reason)} 74 79 jsonout = resp.read() 75 80 try: 76 81 parsed_json = json.loads(jsonout) 77 82 except ValueError: 78 return None83 return {'error': 'No JSON response'} 79 84 return parsed_json 85 86 87 def query_remita(payment, merchantId, api_key, RRR, host, https, verify): 88 89 jr = get_payment_status_via_rrr(merchantId, api_key, RRR, host, https) 90 error = jr.get('error') 91 if error: 92 msg = log = error 93 return False, msg, log 94 95 # A typical JSON response 96 # { 97 # u'orderId': u'3456346346', 98 # u'status': u'021', 99 # u'amount': 1000.0, 100 # u'transactiontime': u'2017-07-31 11:17:24 AM', 101 # u'message': u'Transaction Pending', 102 # u'lineitems': [{u'status': u'021', u'lineItemsId': u'itemid1'}, 103 # {u'status': u'021', u'lineItemsId': u'itemid2'} 104 # ], 105 # u'RRR': u'280007640804'} 106 107 payment.r_code = jr['status'] 108 payment.r_desc = jr['message'] 109 payment.r_amount_approved = jr['amount'] 110 payment.r_pay_reference = jr['RRR'] 111 payment.r_company = u'remita' 112 if payment.r_code != '00': 113 msg = _('Unsuccessful callback: ${a}', mapping = {'a': payment.r_desc}) 114 log = 'unsuccessful callback for %s payment %s: %s' % ( 115 payment.p_category, payment.p_id, payment.r_desc) 116 payment.p_state = 'failed' 117 notify(grok.ObjectModifiedEvent(payment)) 118 return False, msg, log 119 if round(payment.r_amount_approved, 0) != round(payment.amount_auth, 0): 120 msg = _('Callback amount does not match.') 121 log = 'wrong callback for %s payment %s: %s' % ( 122 payment.p_category, payment.p_id, str(jr)) 123 payment.p_state = 'failed' 124 notify(grok.ObjectModifiedEvent(payment)) 125 return False, msg, log 126 if jr['orderId'] != payment.p_id: 127 msg = _('Callback order id does not match.') 128 log = 'wrong callback for %s payment %s: %s' % ( 129 payment.p_category, payment.p_id, str(jr)) 130 payment.p_state = 'failed' 131 notify(grok.ObjectModifiedEvent(payment)) 132 return False, msg, log 133 payment.p_state = 'paid' 134 if not verify: 135 payment.payment_date = datetime.utcnow() 136 msg = _('Successful callback received') 137 log = 'valid callback for %s payment %s: %s' % ( 138 payment.p_category, payment.p_id, str(jr)) 139 notify(grok.ObjectModifiedEvent(payment)) 140 return True, msg, log 80 141 81 142 -
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/remita/tests.py
r14735 r14737 25 25 from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup 26 26 from waeup.kofa.configuration import SessionConfiguration 27 from waeup.kofa.students.payments importStudentOnlinePayment27 from kofacustom.nigeria.students.payments import NigeriaStudentOnlinePayment 28 28 from kofacustom.nigeria.testing import FunctionalLayer 29 29 30 30 from kofacustom.nigeria.remita.helpers import ( 31 get_JSON_POST_response, get_payment_status_via_rrr )31 get_JSON_POST_response, get_payment_status_via_rrr, query_remita) 32 32 33 33 # Also run tests that send requests to external servers? … … 40 40 myself = __file__ 41 41 if myself.endswith('.pyc'): 42 myself = myself[:- 2]42 myself = myself[:-1] 43 43 print "WARNING: external tests are skipped!" 44 44 print "WARNING: edit %s to enable them." % myself 45 45 return 46 46 return func 47 47 48 48 49 class HelperTests(unittest.TestCase): … … 83 84 u'statuscode': u'055'} 84 85 86 85 87 @external_test 86 88 def test_payment_status_via_rrr(self): … … 105 107 u'RRR': u'280007640804'} 106 108 109 110 class RemitaTestsStudents(StudentsFullSetup): 111 """Tests for the Remita payment gateway. 112 """ 113 114 layer = FunctionalLayer 115 116 merchantId = '2547916' 117 serviceTypeId = '4430731' 118 api_key = '1946' 119 orderId = '3456346346' 120 amount = '1000' 121 responseurl = 'http://xxxx' 122 host = 'www.remitademo.net' 123 124 def setUp(self): 125 super(RemitaTestsStudents, self).setUp() 126 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 127 self.browser.open(self.payments_path) 128 IWorkflowState(self.student).setState('cleared') 129 self.student.nationality = u'NG' 130 self.browser.open(self.payments_path + '/addop') 131 self.browser.getControl(name="form.p_category").value = ['schoolfee'] 132 self.browser.getControl("Create ticket").click() 133 self.assertMatches('...ticket created...', 134 self.browser.contents) 135 ctrl = self.browser.getControl(name='val_id') 136 self.value = ctrl.options[0] 137 self.browser.getLink(self.value).click() 138 self.assertMatches('...Amount Authorized...', 139 self.browser.contents) 140 self.assertTrue('<span>40000.0</span>', self.browser.contents) 141 self.payment_url = self.browser.url 142 self.payment = self.student['payments'][self.value] 143 144 145 @external_test 146 def test_query_remita(self): 147 # We can only test the first part of query_interswitch since 148 # we have no succesful payment. 149 qr = query_remita( 150 self.payment, 151 merchantId=self.merchantId, 152 api_key=self.api_key, 153 RRR='280007640804', 154 host=self.host, 155 https=False, 156 verify=False) 157 assert qr == ( 158 False, 159 u'Unsuccessful callback: ${a}', 160 u'unsuccessful callback for schoolfee payment %s: Transaction Pending' 161 % self.payment.p_id)
Note: See TracChangeset for help on using the changeset viewer.