from http.server import BaseHTTPRequestHandler, HTTPServer
key = "YOUR_API_KEY_HERE"
def payment_transaction_fraud_prev(self, ip: str, vars: dict = {}) -> dict:
"""Method used to lookup Payment & Transaction Fraud Prevention API
vars (dict, optional): Reffer to https://www.ipqualityscore.com/documentation/proxy-detection-api/transaction-scoring for variables.. Defaults to {}.
url = "https://www.ipqualityscore.com/api/json/ip/%s/%s" %(self.key, ip)
x = requests.get(url, params = vars)
return (json.loads(x.text))
class MyServer(BaseHTTPRequestHandler):
"""This is an example basic web server. we limited it to handle "/" path only."""
header_items= dict(self.headers.items())
'user_agent' : header_items['User-Agent'],
'user_language' : header_items['Accept-Language'].split(',')[0],
'allow_public_access_points' : 1,
transaction_parameters = {
'billing_first_name' : 'John',
'billing_last_name' : 'Snow',
All variables below are optional to supplement risk analysis and fraud scoring
transaction_parameters = {
'billing_first_name' : '',
'billing_last_name' : '',
'billing_address_1' : '',
'billing_address_2' : '',
'credit_card_hash' : hashlib.sha256('378734493671000').hexdigest(),
'shipping_first_name' : '',
'shipping_last_name' : '',
'shipping_address_1' : '',
'shipping_address_2' : '',
'password_hash' : hashlib.sha256('password').hexdigest(),
'credit_card_expiration_month' : '',
'credit_card_expiration_year' : '',
result = ipqs.payment_transaction_fraud_prev(self.client_address[0],{**parameters, **transaction_parameters})
if 'success' in result and result['success'] == True:
NOTICE: If you want to use one of the examples below, remove
any lines containing /*, */ and *-, then remove * from any of the
Transaction Scoring Example 1: Block high risk users or fraudulent payments simply based on the Risk Score
if result['transaction_details']['risk_score'] >= 90:
self.send_header('Content-type', 'text/html')
self.send_header('Location','https://www.ipqualityscore.com/disable-your-proxy-vpn-connection')
Transaction Scoring Example 2: We'd like to block users with a risky phone number or invalid physical address
if result['transaction_details']['valid_billing_address'] == False or result['transaction_details']['valid_shipping_address'] == False or result['transaction_details']['valid_billing_phone'] == False or result['transaction_details']['valid_shipping_phone'] == False or result['transaction_details']['risky_billing_phone'] == True or result['transaction_details']['risky_shipping_phone'] == True:
self.send_header('Content-type', 'text/html')
self.send_header('Location','https://www.ipqualityscore.com/disable-your-proxy-vpn-connection')
Transaction Scoring Example 3: We'd like to block users with any occurrence of high risk behavior, invalid user data, or an overall Fraud Score >= 90
if result['fraud_score'] >= 90 or result['transaction_details']['valid_billing_address'] == False or result['transaction_details']['valid_shipping_address'] == False or result['transaction_details']['valid_billing_email'] == False or result['transaction_details']['valid_shipping_email'] == False or result['transaction_details']['risky_billing_phone'] == True or result['transaction_details']['risky_shipping_phone'] == True or result['transaction_details']['valid_billing_phone'] == False or result['transaction_details']['valid_shipping_phone'] == False or result['transaction_details']['risky_username'] == True or result['transaction_details']['fraudulent_behavior'] == True:
self.send_header('Content-type', 'text/html')
self.send_header('Location','https://www.ipqualityscore.com/disable-your-proxy-vpn-connection')
Transaction Scoring Example 4: We'd like to block users with an overall Fraud Score >= 90, or users with tor connections, or users with abusive email addresses
if result['fraud_score'] >= 90 or result['tor'] == True or result['transaction_details']['valid_billing_email'] == False or result['transaction_details']['valid_shipping_email'] == False:
self.send_header('Content-type', 'text/html')
self.send_header('Location','https://www.ipqualityscore.com/disable-your-proxy-vpn-connection')
If you are confused with these examples or simply have a use case
not covered here, please feel free to contact IPQualityScore's support
team. We'll craft a custom piece of code to meet your requirements.
self.send_header("Content-type", "text/html")
self.wfile.write(bytes("<body>", "utf-8"))
if __name__ == "__main__":
webServer = HTTPServer((hostName, serverPort), MyServer)
print("Server started http://%s:%s" % (hostName, serverPort))
webServer.serve_forever()
except KeyboardInterrupt: