Changeset 15596
- Timestamp:
- 20 Sep 2019, 06:51:47 (5 years ago)
- Location:
- main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/applicantsbrowser.py
r15589 r15596 62 62 return self.view.url(self.view.context, self.target) 63 63 64 class EtranzactRequeryActionButtonApplicant(ManageActionButton): 65 grok.order(2) 66 grok.context(INigeriaOnlinePayment) 67 grok.view(OPDPApplicant) 68 grok.require('waeup.payApplicant') 69 icon = 'actionicon_call.png' 70 text = _('Requery eTranzact History') 71 target = 'requery_history' 72 73 @property 74 def target_url(self): 75 if not module_activated(self.context.__parent__.__parent__.year): 76 return '' 77 if self.context.p_state in ('paid', 'waived'): 78 return '' 79 return self.view.url(self.view.context, self.target) 80 64 81 class EtranzactPageApplicant(KofaPage): 65 82 """ View which sends a POST request to the eTranzact payment gateway. … … 94 111 if time_delta.days > 7: 95 112 return _("This payment ticket is too old. Please create a new ticket.") 113 # In contrast to the procedure in the Remita and Interswitch modules, 114 # we do not call requery_history but receive and evaluate 115 # the response form from eTranzact directly. This is possible 116 # because eTranzact provides the FINAL_CHECKSUM hash value 117 # which authenticates the response. 96 118 self.responseurl = self.url(self.context, 'receive_etranzact') 97 119 # Already now it becomes a eTranzact payment … … 118 140 """ View that receives the response from eTrantact payment gateway. 119 141 """ 120 #grok.context(INigeriaApplicantOnlinePayment)121 142 grok.name('receive_etranzact') 122 #grok.require('waeup.payApplicant')123 #label = _('Response from eTranzact')124 143 125 144 secret_key = SECRET_KEY … … 147 166 return 148 167 149 class EtranzactReque ryHistoryApplicant(KofaPage):150 """ Request POST redirect from eTranzact168 class EtranzactRequestPaymentStatusPageApplicant(UtilityView, grok.View): 169 """ Request webservice view for the eTranzact gateway. 151 170 """ 152 153 171 grok.context(INigeriaApplicantOnlinePayment) 154 172 grok.name('requery_history') 155 173 grok.require('waeup.payApplicant') 156 grok.template('requery_etranzact')157 label = _('Requery eTranzact history')158 submit_button = _('Requery now')159 174 160 175 host = HOST … … 164 179 logo_url = LOGO_URL 165 180 166 @property167 def action(self):168 if self.https:169 return 'https://' + self.host + '/webconnect/v3/query.jsp'170 return 'http://' + self.host + '/webconnect/v3/query.jsp'171 172 181 def update(self): 173 182 if not module_activated(self.context.__parent__.__parent__.year): 174 183 return 175 self.responseurl = self.url(self.context, 'receive_etranzact') 176 self.transaction_id = self.context.p_id 177 return 184 if self.context.p_state in ('paid', 'waived'): 185 self.flash(_('This ticket has already been paid.'), type='danger') 186 return 187 applicant = self.context.__parent__ 188 verify = False 189 raw, form = query_history(self.host, self.terminal_id, 190 self.context.p_id, self.https) 191 success, msg, log = process_response(self.context, form, self, verify) 192 applicant.writeLogMessage(self, log) 193 if not success: 194 self.flash(msg, type='danger') 195 return 196 write_payments_log(applicant.applicant_id, self.context) 197 flashtype, msg, log = self.context.doAfterApplicantPayment() 198 if log is not None: 199 applicant.writeLogMessage(self, log) 200 self.flash(msg, type=flashtype) 201 return 202 203 def render(self): 204 self.redirect(self.url(self.context.__parent__, 'edit')) 205 return -
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/helpers.py
r15593 r15596 25 25 import hashlib 26 26 import json 27 28 27 from zope.event import notify 28 from waeup.kofa.utils.helpers import extract_formvars 29 29 from kofacustom.nigeria.interfaces import MessageFactory as _ 30 30 … … 37 37 payment.thirdparty_amt)) 38 38 39 def query_history(host, terminal_id, transaction_id, https , responseurl):39 def query_history(host, terminal_id, transaction_id, https): 40 40 headers={"Content-type": "application/x-www-form-urlencoded", 41 41 "Accept": "text/plain"} … … 52 52 response = h.getresponse() 53 53 if response.status!=200: 54 return 'Connection error (%s, %s)' % (response.status, response.reason) 55 r esp= response.read()56 return r esp54 return 'Connection error (%s, %s)' % (response.status, response.reason), None 55 raw = response.read() 56 return raw, extract_formvars(raw) 57 57 58 58 # A sample caller response sent to the RESPONSE_URL … … 78 78 # CARD_TYPE=null 79 79 80 # A sample query response sent to the RESPONSE_URL 80 # A sample query response 81 82 # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 83 # "http://www.w3.org/TR/html4/loose.dtd"> 84 # <script language='javascript'> 85 # var spanId = document.getElementById("message_container"); 86 # spanId.textContent = 'Redirecting...';</script> 87 # <form method="GET" id="redirect_form" name="redirect_form" 88 # action="http://localhost:81/projects/Webconnect/response.php" target="_top"> 89 # <input type="hidden" name = "LOGO_URL" 90 # value="http://localhost:81/projects/Webconnect/images/elogo.fw.png"> 91 # <input type="hidden" name = "RESPONSE_URL" 92 # value="http://localhost:81/projects/Webconnect/response.php"> 93 # <input type="hidden" name = "CURRENCY_CODE" value="NGN"> 94 # <input type="hidden" name = "TERMINAL_ID" value="0000000001"> 95 # <input type="hidden" name = "TRANSACTION_ID" value="etz1568638104web"> 96 # <input type="hidden" name = "AMOUNT" value="100"> 97 # <input type="hidden" name = "DESCRIPTION" value="Payment Description"> 98 # <input type="hidden" name = "CHECKSUM" 99 # value="5be04064f4bb250f73650059a8e921cc"> 100 # <input type="hidden" name = "MERCHANT_CODE" value="0339990001"> 101 # <input type="hidden" name = "EMAIL" value="xyz@yahoo.com"> 102 # <input type="hidden" name = "SUCCESS" value="0"> 103 # <input type="hidden" name = "FINAL_CHECKSUM" 104 # value="FD67A4CCC39E2C8DEEEC78D6C64A61FE"> 105 # <input type="hidden" name = "STATUS_REASON" value="Approved"> 106 # <input type="hidden" name = "TRANS_NUM" value="01ESA20190916134824YA3YJ8"> 107 # <input type="hidden" name = "CARD_NO" value="506066XXXXXXXXX6666"> 108 # <input type="hidden" name = "CARD_TYPE" value="Verve"> 109 # </form> 110 # <script language='javascript'> 111 # var fom = document.forms["redirect_form"]; 112 # fom.submit();</script> 113 114 # A sample query response sent to the RESPONSE_URL after the browser has 115 # automatically executed the Javascript above (we don't use this response) 81 116 82 117 # http://salsa:8080/app/applicants/cbt2015/449072/p5686487280654/receive_etranzact? … … 99 134 100 135 def process_response(payment, form, view, verify): 101 success = form.get('RESPONSE_CODE', None) 102 if not success: 136 if not form or not form.get('RESPONSE_CODE', None): 103 137 msg = _('No valid response from eTranzact.') 104 138 log = 'No valid response from eTranzact for payment %s' % payment.p_id … … 106 140 notify(grok.ObjectModifiedEvent(payment)) 107 141 return False, msg, log 142 success = form.get('RESPONSE_CODE', None) 108 143 # Compute final checksum 109 144 transaction_id = payment.p_id … … 117 152 log = 'wrong checksum for %s payment %s: %s' % ( 118 153 payment.p_category, payment.p_id, str(form)) 154 payment.p_state = 'failed' 155 notify(grok.ObjectModifiedEvent(payment)) 119 156 return False, msg, log 120 157 payment.r_code = form.get('RESPONSE_CODE', None) -
main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/tests.py
r15593 r15596 113 113 def test_query_history(self): 114 114 transaction_id = str(random.randint(100000000, 999999999)) 115 r esponse= query_history(HOST, self.terminal_id,116 transaction_id, HTTPS , 'http://xxxxx')115 raw, formvars = query_history(HOST, self.terminal_id, 116 transaction_id, HTTPS) 117 117 self.assertTrue( 118 118 'Transaction with the given transaction_id (%s) not found' 119 % transaction_id in r esponse)119 % transaction_id in raw) 120 120 # Okay, let's create a transaction 121 121 caller_response = create_transaction(transaction_id) … … 123 123 # It seems that the transaction has been created but we don't get a 124 124 # useful response 125 query_response= query_history(HOST, self.terminal_id,126 transaction_id, HTTPS , 'http://xxxxx')125 raw, formvars = query_history(HOST, self.terminal_id, 126 transaction_id, HTTPS) 127 127 self.assertTrue( 128 128 '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\r\n ' 129 '"http://www.w3.org/TR/html4/loose.dtd">' in query_response)129 '"http://www.w3.org/TR/html4/loose.dtd">' in raw) 130 130 # The same, an 'empty' response obviously means that the transaction 131 131 # was found but no result was sent to the response_url because the … … 139 139 # Peter has manually created a successful payment. Let's use this one. 140 140 transaction_id = 'etz1568638104web' 141 query_response= query_history(HOST, self.terminal_id,142 transaction_id, HTTPS , 'http://xxxxx')141 raw, formvars = query_history(HOST, self.terminal_id, 142 transaction_id, HTTPS) 143 143 # Now eTranzact is redirecting but the response is still useless 144 self.assertTrue('Redirecting...' in raw) 144 145 print query_response 145 self.assertTrue('Redirecting...' in query_response)146 146 return 147 147 … … 177 177 self.browser.getLink("Pay via eTranzact").click() 178 178 self.assertTrue("Pay now" in self.browser.contents) 179 # create an eTranzact transaction.180 logo_url = 'http://xxxx'181 responseurl = self.payment_url + '/receive_etranzact'182 amount = "%.1f" % self.payment.amount_auth183 customer = self.applicant184 hashargs = amount + TERMINAL_ID + self.payment.p_id \185 + responseurl + 'DEMO_KEY'186 hashvalue = hashlib.md5(hashargs).hexdigest()187 post_caller(HOST, HTTPS, TERMINAL_ID,188 self.payment.p_id, responseurl,189 self.payment.amount_auth, customer.email,190 customer.phone,191 customer.display_fullname, hashvalue,192 logo_url)193 self.browser.open(self.payment_url + '/requery_history')194 # Means of testing end here.195 196 #hashargs = amount + TERMINAL_ID + 'etz1568638104web' \197 # + responseurl + 'DEMO_KEY'198 #hashvalue = hashlib.md5(hashargs).hexdigest()199 #self.browser.open(self.payment_url + '/requery_history')200 #self.browser.getControl("Requery now").click()201 #import pdb; pdb.set_trace()202 203 179 204 180 return
Note: See TracChangeset for help on using the changeset viewer.