20160124 Python script monitor failed transaction in DPS payment manager

System Blog

Python script monitor failed transaction in DPS payment manager

 

DPS or Payment Express, this company breaks me!

"Everything is working fine" is the only dame fucking thing they tell you.

 

If unfortunately you have to work with them, my two cents would be

1 don't make phone call, drop P1 email to their technician and the response time mostly are OK.

2 Ask your business to create a full privileged account in DPS Payment manager, setup this python monitoring script, and you are all set, because you now have full visibilities of what you are supporting!

 

Basically, this script will run every minutes, to get the last 20 transactions by the time the script running, and if more than 8 transaction are failed transactions, then the script will assume that DPS has significant issue or they having an issue with their uplink, for instance a BANK. and you and your team mates are now supposed to receive an email which have a html page which has all information about those failed transaction including the root cause.

 

import requests
import os
import time
from bs4 import BeautifulSoup
http_proxy = 'your_proxy_name_if_you_have_one'
https_proxy = 'your_https_proxy_name_if_you_have_one '
URL = 'https://sec.paymentexpress.com/pxmi/logon'
proxyDict = { "http" : http_proxy,"https" : https_proxy}
payload = {'LogonButton' : 'Log On','_Pass' : 'your_password','_Usr' : 'your_username'}
s = requests.session()
r = s.post(URL,data=payload,allow_redirects=True,proxies=proxyDict)

soup = BeautifulSoup(r.text,"html.parser")
#get transaction search url
url1='https://sec.paymentexpress.com/pxmi/'+soup.find(attrs={"id":"mainMenu_5"})['href'];

while (True):

r = s.get(url1,proxies=proxyDict)
f = open('failed.html','w')
f.write('''<table border="0" cellpadding="4" cellspacing="1" class="dpsHtmlTable" style="background-color:#cccccc"><tr class="dpsHtmlTableHeader"><td class="dpsHtmlTableHeaderText" style="width:10px;"></td><td class="dpsHtmlTableHeaderText" style="width:130px;">Date</td><td class="dpsHtmlTableHeaderText" style="width:100px;">Card Number</td><td class="dpsHtmlTableHeaderText" style="width:30px;">Cur</td><td class="dpsHtmlTableHeaderText" style="width:70px;">Amount</td><td class="dpsHtmlTableHeaderText" style="width:150px;">Card Holder</td><td class="dpsHtmlTableHeaderText" style="width:150px;">Merchant Ref</td><td class="dpsHtmlTableHeaderText" style="width:150px;">TxnRef</td><td class="dpsHtmlTableHeaderText" style="width:40px;">Type</td><td class="dpsHtmlTableHeaderText" style="width:10px;">Void</td><td class="dpsHtmlTableHeaderText" style="width:50px;">Detail</td></tr>''')
f.close()
soup1 = BeautifulSoup(r.text,"html.parser")
table = soup1.findAll(attrs={'class':'dpsHtmlTable'})[1]

soup2 = BeautifulSoup(str(table),"html.parser")
trs = soup2.findAll(attrs={'style':'background-color:white'})
count = 0
for tr in trs:
if tr.td.img['src'] == 'images/n1.gif':
tr.td.img['src'] = 'https://sec.paymentexpress.com/pxmi/images/n1.gif'
#print tr.contents
tr.contents[19].img['src'] = 'https://sec.paymentexpress.com/pxmi/images/n1.gif'
#tr.contents[21].a['href'] = 'https://sec.paymentexpress.com/pxmi/'+tr.contents[21].a['href']
detailURL = 'https://sec.paymentexpress.com/pxmi/'+tr.contents[21].a['href']
detailR = s.get(detailURL,proxies=proxyDict)
#print detailR.text
detailSoup = BeautifulSoup(detailR.text,"html.parser")
#print detailSoup
result1 = detailSoup.find(attrs={'id':'lblTxnResponseText'})
#print result1.text
result2 = detailSoup.find(attrs={'id':'lblAcquirerResponseText'})
result3 = result1.text.strip()+" : "+result2.text.strip()
#print result3
#print tr.contents[21].a.text
tr.contents[21].a.string = result3
f = open('failed.html','a')
f.write(str(tr))
f.close()
count = count+1
print count
if count > 7:
os.system("echo 'DO NOT REPLY this email,Detail See Attachment'|mail -s 'DPS too many failed transactions' -a 'failed.html' someones_email@your_org.com")
time.sleep(60)

 

In the code above, as you can see, there is no exception handling, if it breaks it breaks, who cares, just setup another nanny process to relaunch if it breaks as follow

 

#!/bin/bash
cd /where_you_run_your_python_script

result=""
result=`ps -ef|grep dps|grep -v grep`
trimmed=`echo $result`
if [[ $trimmed = "" ]]
then
echo "DpsCheck stopped"|mail -s "DpsCheck stopped" youself@your_org.com
sh -c "nohup python dpsCheck1.py&"
else
echo "gaga"
fi

 

 

you can act proactively as a super hero now~

 

 

 

Posted by: leaonow on: Jan 24, 2016

 

Your Name:

OneTime Password:



Pic of the day