Ignore:
Timestamp:
16 Mar 2012, 10:06:59 (13 years ago)
Author:
Henrik Bettermann
Message:

Add webservice functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.custom/trunk/src/waeup/custom/interswitch/browser.py

    r7897 r7898  
    1717##
    1818from datetime import datetime
    19 from urllib import urlencode
     19import httplib
     20import urllib
     21from xml.dom.minidom import parseString
    2022import grok
    2123from waeup.kofa.browser.layout import KofaPage, UtilityView
     
    3941POST_ACTION = 'https://testwebpay.interswitchng.com/test_paydirect/webpay/pay.aspx'
    4042
     43HOST = 'testwebpay.interswitchng.com'
     44URL = '/test_paydirect/services/TransactionQueryWs.asmx'
     45httplib.HTTPConnection.debuglevel = 0
     46
     47def SOAP_post(soap_action,xml):
     48    """Handles making the SOAP request.
     49
     50    Further reading:
     51    http://testwebpay.interswitchng.com/test_paydirect/services/TransactionQueryWs.asmx?op=getTransactionData
     52    """
     53    h = httplib.HTTPConnection(HOST)
     54    headers={
     55        'Host':HOST,
     56        'Content-Type':'text/xml; charset=utf-8',
     57        'Content-Length':len(xml),
     58        'SOAPAction':'"%s"' % soap_action,
     59    }
     60    h.request('POST', URL, body=xml,headers=headers)
     61    r = h.getresponse()
     62    d = r.read()
     63    if r.status!=200:
     64        raise ValueError('Error connecting: %s, %s' % (r.status, r.reason))
     65    return d
     66
     67def get_SOAP_response(product_id, transref):
     68    xml="""\
     69<?xml version="1.0" encoding="utf-8"?>
     70<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
     71  <soap:Body>
     72    <getTransactionData xmlns="http://tempuri.org/">
     73      <product_id>%s</product_id>
     74      <trans_ref>%s</trans_ref>
     75    </getTransactionData>
     76  </soap:Body>
     77</soap:Envelope>""" % (product_id, transref)
     78    result_xml=SOAP_post("http://tempuri.org/getTransactionData",xml)
     79    doc=parseString(result_xml)
     80    response=doc.getElementsByTagName('getTransactionDataResult')[0].firstChild.data
     81    return response
     82
    4183class InterswitchActionButton(RequestCallbackActionButton):
    4284    grok.order(2)
     
    64106            'prodID':PRODUCT_ID,
    65107            'redirectURL':site_redirect_url}
    66         return QUERY_URL + '?%s' % urlencode(args)
     108        return QUERY_URL + '?%s' % urllib.urlencode(args)
    67109
    68110class InterswitchPage(KofaPage):
     
    160202
    161203        # Add webservice validation
    162 
     204        validation_list = get_SOAP_response(
     205            PRODUCT_ID, self.context.p_id).split(':')
     206        # Validation does not make sense yet since the query string
     207        # formats are conflicting.
     208        print validation_list
    163209
    164210        write_log_message(self,'valid callback: %s' % self.context.p_id)
Note: See TracChangeset for help on using the changeset viewer.