Skip to content

Instantly share code, notes, and snippets.

@rana-ahmed
Created December 4, 2017 10:27
Show Gist options
  • Save rana-ahmed/e47d1208ac16deb94a257a7eb9d557e4 to your computer and use it in GitHub Desktop.
Save rana-ahmed/e47d1208ac16deb94a257a7eb9d557e4 to your computer and use it in GitHub Desktop.
import datetime
import requests
import xml.etree.ElementTree as ET
POST_URI = 'http://116.212.108.236:802/PaymentServices.asmx?op=PaymentRequestFromECom'
user_id = 'ecomauser'
password = 'itreus#7102'
vendor_code = 'GP'
phone_number = '01989782605'
post_or_pre = 1
current_month = datetime.datetime.today().month
account_no = '37150442'
transfer_ref = '32423'
amount = str(10*10)
terminal_name = 'CODERO'
terminal_type = 'APPS'
xml_post_data = f"""<?xml version="1.0" encoding="utf-8"?>
<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/">
<soap:Body>
<PaymentRequestFromECom xmlns="http://tempuri.org/">
<UserId>{user_id}</UserId>
<Password>{password}</Password>
<VendorCode>{vendor_code}</VendorCode>
<Payaccno>{phone_number}</Payaccno>
<Accounttype>{post_or_pre}</Accounttype>
<Billmonth>{current_month}</Billmonth>
<CardNo>{account_no}</CardNo>
<ApprovalCode>{transfer_ref}</ApprovalCode>
<Amount>{amount}</Amount>
<Terminalname>{terminal_name}</Terminalname>
<Terminaltype>{terminal_type}</Terminaltype>
</PaymentRequestFromECom>
</soap:Body>
</soap:Envelope>"""
response = requests.post(POST_URI, data=xml_post_data, headers={'Content-Type': 'text/xml'})
BASE_URI = '{http://schemas.xmlsoap.org/soap/envelope/}Body/{http://tempuri.org/}' \
'PaymentRequestFromEComResponse/{http://tempuri.org/}PaymentRequestFromEComResult'
TRANSACTIONID_URI = '{http://tempuri.org/}TransId'
RESPONSECODE_URI = '{http://tempuri.org/}ResponseCode'
RESPONSETEXT_URI = '{http://tempuri.org/}ResponseText'
# Create your tests here.
xml_data = """<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<PaymentRequestFromEComResponse xmlns="http://tempuri.org/">
<PaymentRequestFromEComResult>
<TransId>713621</TransId>
<ResponseCode>201</ResponseCode>
<ResponseText>Processing</ResponseText>
</PaymentRequestFromEComResult>
</PaymentRequestFromEComResponse>
</soap:Body>
</soap:Envelope>"""
root = ET.fromstring(response.text).find(BASE_URI)
transaction_id = root.find(TRANSACTIONID_URI).text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment