Created
October 28, 2016 02:41
-
-
Save radzhome/0dd788c2951a7d8e15fe61ebda65678b to your computer and use it in GitHub Desktop.
minfraud chargeback api python example function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import json | |
import requests | |
FRAUD_SCORES = ('not_fraud', 'suspected_fraud', 'known_fraud') | |
def minfraud_submit_chargeback(license_key, user_id, chargeback_code, fraud_score, ip_address, transaction_id, force_prod=False): | |
""" | |
Submit a chargeback request to minFrauds chargeback API | |
""" | |
if fraud_score not in FRAUD_SCORES: | |
return False, "Invalid fraud score" | |
url = "https://minfraud.maxmind.com/minfraud/chargeback" # TODO: put in params | |
auth = base64.b64encode("{}:{}".format(user_id, license_key)) | |
headers = {'Content-Type': 'application/json', | |
'Authorization': "Basic {}".format(auth)} | |
payload = {'chargeback_code': chargeback_code, | |
'fraud_score': fraud_score, | |
'ip_address': ip_address, | |
'transaction_id': transaction_id} | |
# See response.text or response.data | |
response = requests.post(url, data=json.dumps(payload), headers=headers, timeout=5) | |
return response.status_code == 204 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment