Changeset 15596 for main


Ignore:
Timestamp:
20 Sep 2019, 06:51:47 (5 years ago)
Author:
Henrik Bettermann
Message:

Save modifications. They are completely untested because demo server is offline.

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  
    6262        return self.view.url(self.view.context, self.target)
    6363
     64class 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
    6481class EtranzactPageApplicant(KofaPage):
    6582    """ View which sends a POST request to the eTranzact payment gateway.
     
    94111        if time_delta.days > 7:
    95112            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.
    96118        self.responseurl = self.url(self.context, 'receive_etranzact')
    97119        # Already now it becomes a eTranzact payment
     
    118140    """ View that receives the response from eTrantact payment gateway.
    119141    """
    120     #grok.context(INigeriaApplicantOnlinePayment)
    121142    grok.name('receive_etranzact')
    122     #grok.require('waeup.payApplicant')
    123     #label = _('Response from eTranzact')
    124143
    125144    secret_key = SECRET_KEY
     
    147166        return
    148167
    149 class EtranzactRequeryHistoryApplicant(KofaPage):
    150     """ Request POST redirect from eTranzact
     168class EtranzactRequestPaymentStatusPageApplicant(UtilityView, grok.View):
     169    """ Request webservice view for the eTranzact gateway.
    151170    """
    152 
    153171    grok.context(INigeriaApplicantOnlinePayment)
    154172    grok.name('requery_history')
    155173    grok.require('waeup.payApplicant')
    156     grok.template('requery_etranzact')
    157     label = _('Requery eTranzact history')
    158     submit_button = _('Requery now')
    159174
    160175    host = HOST
     
    164179    logo_url = LOGO_URL
    165180
    166     @property
    167     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 
    172181    def update(self):
    173182        if not module_activated(self.context.__parent__.__parent__.year):
    174183            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  
    2525import hashlib
    2626import json
    27 
    2827from zope.event import notify
     28from waeup.kofa.utils.helpers import extract_formvars
    2929from kofacustom.nigeria.interfaces import MessageFactory as _
    3030
     
    3737        payment.thirdparty_amt))
    3838
    39 def query_history(host, terminal_id, transaction_id, https, responseurl):
     39def query_history(host, terminal_id, transaction_id, https):
    4040    headers={"Content-type": "application/x-www-form-urlencoded",
    4141             "Accept": "text/plain"}
     
    5252    response = h.getresponse()
    5353    if response.status!=200:
    54         return 'Connection error (%s, %s)' % (response.status, response.reason)
    55     resp = response.read()
    56     return resp
     54        return 'Connection error (%s, %s)' % (response.status, response.reason), None
     55    raw = response.read()
     56    return raw, extract_formvars(raw)
    5757
    5858 # A sample caller response sent to the RESPONSE_URL
     
    7878 # CARD_TYPE=null
    7979
    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)
    81116
    82117 # http://salsa:8080/app/applicants/cbt2015/449072/p5686487280654/receive_etranzact?
     
    99134
    100135def 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):
    103137        msg = _('No valid response from eTranzact.')
    104138        log = 'No valid response from eTranzact for payment %s' % payment.p_id
     
    106140        notify(grok.ObjectModifiedEvent(payment))
    107141        return False, msg, log
     142    success = form.get('RESPONSE_CODE', None)
    108143    # Compute final checksum
    109144    transaction_id = payment.p_id
     
    117152        log = 'wrong checksum for %s payment %s: %s' % (
    118153            payment.p_category, payment.p_id, str(form))
     154        payment.p_state = 'failed'
     155        notify(grok.ObjectModifiedEvent(payment))
    119156        return False, msg, log
    120157    payment.r_code = form.get('RESPONSE_CODE', None)
  • main/kofacustom.nigeria/trunk/src/kofacustom/nigeria/etranzact/tests.py

    r15593 r15596  
    113113    def test_query_history(self):
    114114        transaction_id = str(random.randint(100000000, 999999999))
    115         response = 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)
    117117        self.assertTrue(
    118118            'Transaction with the given transaction_id (%s) not found'
    119             % transaction_id in response)
     119            % transaction_id in raw)
    120120        # Okay, let's create a transaction
    121121        caller_response = create_transaction(transaction_id)
     
    123123        # It seems that the transaction has been created but we don't get a
    124124        # 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)
    127127        self.assertTrue(
    128128            '<!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)
    130130        # The same, an 'empty' response obviously means that the transaction
    131131        # was found but no result was  sent to the response_url because the
     
    139139        # Peter has manually created a successful payment. Let's use this one.
    140140        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)
    143143        # Now eTranzact is redirecting but the response is still useless
     144        self.assertTrue('Redirecting...' in raw)
    144145        print query_response
    145         self.assertTrue('Redirecting...' in query_response)
    146146        return
    147147
     
    177177        self.browser.getLink("Pay via eTranzact").click()
    178178        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_auth
    183         customer = self.applicant
    184         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 
    203179
    204180        return
Note: See TracChangeset for help on using the changeset viewer.