Index: /main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/applicantsbrowser.py
===================================================================
--- /main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/applicantsbrowser.py	(revision 15595)
+++ /main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/applicantsbrowser.py	(revision 15596)
@@ -62,4 +62,21 @@
         return self.view.url(self.view.context, self.target)
 
+class EtranzactRequeryActionButtonApplicant(ManageActionButton):
+    grok.order(2)
+    grok.context(INigeriaOnlinePayment)
+    grok.view(OPDPApplicant)
+    grok.require('waeup.payApplicant')
+    icon = 'actionicon_call.png'
+    text = _('Requery eTranzact History')
+    target = 'requery_history'
+
+    @property
+    def target_url(self):
+        if not module_activated(self.context.__parent__.__parent__.year):
+            return ''
+        if self.context.p_state in ('paid', 'waived'):
+            return ''
+        return self.view.url(self.view.context, self.target)
+
 class EtranzactPageApplicant(KofaPage):
     """ View which sends a POST request to the eTranzact payment gateway.
@@ -94,4 +111,9 @@
         if time_delta.days > 7:
             return _("This payment ticket is too old. Please create a new ticket.")
+        # In contrast to the procedure in the Remita and Interswitch modules,
+        # we do not call requery_history but receive and evaluate
+        # the response form from eTranzact directly. This is possible
+        # because eTranzact provides the FINAL_CHECKSUM hash value
+        # which authenticates the response.
         self.responseurl = self.url(self.context, 'receive_etranzact')
         # Already now it becomes a eTranzact payment
@@ -118,8 +140,5 @@
     """ View that receives the response from eTrantact payment gateway.
     """
-    #grok.context(INigeriaApplicantOnlinePayment)
     grok.name('receive_etranzact')
-    #grok.require('waeup.payApplicant')
-    #label = _('Response from eTranzact')
 
     secret_key = SECRET_KEY
@@ -147,14 +166,10 @@
         return
 
-class EtranzactRequeryHistoryApplicant(KofaPage):
-    """ Request POST redirect from eTranzact
+class EtranzactRequestPaymentStatusPageApplicant(UtilityView, grok.View):
+    """ Request webservice view for the eTranzact gateway.
     """
-
     grok.context(INigeriaApplicantOnlinePayment)
     grok.name('requery_history')
     grok.require('waeup.payApplicant')
-    grok.template('requery_etranzact')
-    label = _('Requery eTranzact history')
-    submit_button = _('Requery now')
 
     host = HOST
@@ -164,14 +179,27 @@
     logo_url = LOGO_URL
 
-    @property
-    def action(self):
-        if self.https:
-            return 'https://' + self.host + '/webconnect/v3/query.jsp'
-        return 'http://' + self.host + '/webconnect/v3/query.jsp'
-
     def update(self):
         if not module_activated(self.context.__parent__.__parent__.year):
             return
-        self.responseurl = self.url(self.context, 'receive_etranzact')
-        self.transaction_id = self.context.p_id
-        return
+        if self.context.p_state in ('paid', 'waived'):
+            self.flash(_('This ticket has already been paid.'), type='danger')
+            return
+        applicant = self.context.__parent__
+        verify = False
+        raw, form = query_history(self.host, self.terminal_id,
+                                  self.context.p_id, self.https)
+        success, msg, log = process_response(self.context, form, self, verify)
+        applicant.writeLogMessage(self, log)
+        if not success:
+            self.flash(msg, type='danger')
+            return
+        write_payments_log(applicant.applicant_id, self.context)
+        flashtype, msg, log = self.context.doAfterApplicantPayment()
+        if log is not None:
+            applicant.writeLogMessage(self, log)
+        self.flash(msg, type=flashtype)
+        return
+
+    def render(self):
+        self.redirect(self.url(self.context.__parent__, 'edit'))
+        return
Index: in/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/browser_templates/requery_etranzact.pt
===================================================================
--- /main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/browser_templates/requery_etranzact.pt	(revision 15595)
+++ 	(revision )
@@ -1,23 +1,0 @@
-<form i18n:domain="kofacustom.nigeria"
-  tal:attributes="action view/action" method="POST">
-
-  <input type=hidden name="TERMINAL_ID" tal:attributes="value view/terminal_id">
-  <input type=hidden name="RESPONSE_URL" tal:attributes="value view/responseurl">
-  <input type=hidden name="TRANSACTION_ID" tal:attributes="value view/transaction_id">
-
-  <table class="form-table" i18n:domain="waeup.kofa">
-    <tbody>
-      <tr>
-        <td i18n:translate="" class="fieldname">
-          Transaction Id:</td>
-        <td>
-          <span tal:replace="view/transaction_id">TRANSID</span>
-        </td>
-      </tr>
-    </tbody>
-  </table>
-  <br />
-  <input type="submit" class="btn btn-primary" tal:attributes="value view/submit_button"/>
-  <br /><br />
-  <img src="/static/img/etzLogo.png" /><img src="/static/img/webconnectLogo.png" />
-</form>
Index: /main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/helpers.py
===================================================================
--- /main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/helpers.py	(revision 15595)
+++ /main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/helpers.py	(revision 15596)
@@ -25,6 +25,6 @@
 import hashlib
 import json
-
 from zope.event import notify
+from waeup.kofa.utils.helpers import extract_formvars
 from kofacustom.nigeria.interfaces import MessageFactory as _
 
@@ -37,5 +37,5 @@
         payment.thirdparty_amt))
 
-def query_history(host, terminal_id, transaction_id, https, responseurl):
+def query_history(host, terminal_id, transaction_id, https):
     headers={"Content-type": "application/x-www-form-urlencoded",
              "Accept": "text/plain"}
@@ -52,7 +52,7 @@
     response = h.getresponse()
     if response.status!=200:
-        return 'Connection error (%s, %s)' % (response.status, response.reason)
-    resp = response.read()
-    return resp
+        return 'Connection error (%s, %s)' % (response.status, response.reason), None
+    raw = response.read()
+    return raw, extract_formvars(raw)
 
  # A sample caller response sent to the RESPONSE_URL
@@ -78,5 +78,40 @@
  # CARD_TYPE=null
 
-  # A sample query response sent to the RESPONSE_URL
+ # A sample query response
+
+ # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ #     "http://www.w3.org/TR/html4/loose.dtd">
+ # <script language='javascript'>
+ # var spanId = document.getElementById("message_container");
+ # spanId.textContent = 'Redirecting...';</script>
+ # <form method="GET" id="redirect_form" name="redirect_form"
+ # action="http://localhost:81/projects/Webconnect/response.php" target="_top">
+ # <input type="hidden" name = "LOGO_URL"
+ # value="http://localhost:81/projects/Webconnect/images/elogo.fw.png">
+ # <input type="hidden" name = "RESPONSE_URL"
+ # value="http://localhost:81/projects/Webconnect/response.php">
+ # <input type="hidden" name = "CURRENCY_CODE" value="NGN">
+ # <input type="hidden" name = "TERMINAL_ID" value="0000000001">
+ # <input type="hidden" name = "TRANSACTION_ID" value="etz1568638104web">
+ # <input type="hidden" name = "AMOUNT" value="100">
+ # <input type="hidden" name = "DESCRIPTION" value="Payment Description">
+ # <input type="hidden" name = "CHECKSUM"
+ # value="5be04064f4bb250f73650059a8e921cc">
+ # <input type="hidden" name = "MERCHANT_CODE" value="0339990001">
+ # <input type="hidden" name = "EMAIL" value="xyz@yahoo.com">
+ # <input type="hidden" name = "SUCCESS" value="0">
+ # <input type="hidden" name = "FINAL_CHECKSUM"
+ # value="FD67A4CCC39E2C8DEEEC78D6C64A61FE">
+ # <input type="hidden" name = "STATUS_REASON" value="Approved">
+ # <input type="hidden" name = "TRANS_NUM" value="01ESA20190916134824YA3YJ8">
+ # <input type="hidden" name = "CARD_NO" value="506066XXXXXXXXX6666">
+ # <input type="hidden" name = "CARD_TYPE" value="Verve">
+ # </form>
+ # <script language='javascript'>
+ # var fom = document.forms["redirect_form"];
+ # fom.submit();</script>
+
+ # A sample query response sent to the RESPONSE_URL after the browser has
+ # automatically executed the Javascript above (we don't use this response)
 
  # http://salsa:8080/app/applicants/cbt2015/449072/p5686487280654/receive_etranzact?
@@ -99,6 +134,5 @@
 
 def process_response(payment, form, view, verify):
-    success = form.get('RESPONSE_CODE', None)
-    if not success:
+    if not form or not form.get('RESPONSE_CODE', None):
         msg = _('No valid response from eTranzact.')
         log = 'No valid response from eTranzact for payment %s' % payment.p_id
@@ -106,4 +140,5 @@
         notify(grok.ObjectModifiedEvent(payment))
         return False, msg, log
+    success = form.get('RESPONSE_CODE', None)
     # Compute final checksum
     transaction_id = payment.p_id
@@ -117,4 +152,6 @@
         log = 'wrong checksum for %s payment %s: %s' % (
             payment.p_category, payment.p_id, str(form))
+        payment.p_state = 'failed'
+        notify(grok.ObjectModifiedEvent(payment))
         return False, msg, log
     payment.r_code = form.get('RESPONSE_CODE', None)
Index: /main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/tests.py
===================================================================
--- /main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/tests.py	(revision 15595)
+++ /main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/tests.py	(revision 15596)
@@ -113,9 +113,9 @@
     def test_query_history(self):
         transaction_id = str(random.randint(100000000, 999999999))
-        response = query_history(HOST, self.terminal_id,
-                                transaction_id, HTTPS, 'http://xxxxx')
+        raw, formvars = query_history(HOST, self.terminal_id,
+                                transaction_id, HTTPS)
         self.assertTrue(
             'Transaction with the given transaction_id (%s) not found'
-            % transaction_id in response)
+            % transaction_id in raw)
         # Okay, let's create a transaction
         caller_response = create_transaction(transaction_id)
@@ -123,9 +123,9 @@
         # It seems that the transaction has been created but we don't get a
         # useful response
-        query_response = query_history(HOST, self.terminal_id,
-                                transaction_id, HTTPS, 'http://xxxxx')
+        raw, formvars = query_history(HOST, self.terminal_id,
+                                transaction_id, HTTPS)
         self.assertTrue(
             '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\r\n    '
-            '"http://www.w3.org/TR/html4/loose.dtd">' in query_response)
+            '"http://www.w3.org/TR/html4/loose.dtd">' in raw)
         # The same, an 'empty' response obviously means that the transaction
         # was found but no result was  sent to the response_url because the
@@ -139,9 +139,9 @@
         # Peter has manually created a successful payment. Let's use this one.
         transaction_id = 'etz1568638104web'
-        query_response = query_history(HOST, self.terminal_id,
-                                transaction_id, HTTPS, 'http://xxxxx')
+        raw, formvars = query_history(HOST, self.terminal_id,
+                                transaction_id, HTTPS)
         # Now eTranzact is redirecting but the response is still useless
+        self.assertTrue('Redirecting...' in raw)
         print query_response
-        self.assertTrue('Redirecting...' in query_response)
         return
 
@@ -177,28 +177,4 @@
         self.browser.getLink("Pay via eTranzact").click()
         self.assertTrue("Pay now" in self.browser.contents)
-        # create an eTranzact transaction.
-        logo_url = 'http://xxxx'
-        responseurl = self.payment_url + '/receive_etranzact'
-        amount = "%.1f" % self.payment.amount_auth
-        customer = self.applicant
-        hashargs = 	amount + TERMINAL_ID + self.payment.p_id \
-            + responseurl + 'DEMO_KEY'
-        hashvalue = hashlib.md5(hashargs).hexdigest()
-        post_caller(HOST, HTTPS, TERMINAL_ID,
-                   self.payment.p_id, responseurl,
-                   self.payment.amount_auth, customer.email,
-                   customer.phone,
-                   customer.display_fullname, hashvalue,
-                   logo_url)
-        self.browser.open(self.payment_url + '/requery_history')
-        # Means of testing end here.
-
-        #hashargs = 	amount + TERMINAL_ID + 'etz1568638104web' \
-        #    + responseurl + 'DEMO_KEY'
-        #hashvalue = hashlib.md5(hashargs).hexdigest()
-        #self.browser.open(self.payment_url + '/requery_history')
-        #self.browser.getControl("Requery now").click()
-        #import pdb; pdb.set_trace()
-
 
         return
