Skip to content

Commit 8cdf454

Browse files
Updates on code structure.
1 parent 062a279 commit 8cdf454

File tree

8 files changed

+155
-138
lines changed

8 files changed

+155
-138
lines changed

example.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# import SDK to use the function
2-
from fraudlabspro.order import Order
2+
from fraudlabspro.fraudvalidation import FraudValidation
33
from fraudlabspro.smsverification import SMSVerification
44

55
# Configure your API key
66
api_key = 'YOUR_API_KEY'
77

8+
# validation = fraudlabspro.fraudvalidation.FraudValidation(api_key)
9+
# validation = fraudlabspro.FraudValidation(api_key)
10+
fraud_validation = FraudValidation(api_key)
811

912
"""
1013
# Here is an example to validate order details.
1114
# Set your variables here and then pass the values through the Python library.
1215
"""
1316
order_details_variables = {
14-
'key': api_key,
1517
'ip': '146.112.62.105',
1618
'order': {
1719
'order_id': '67398',
@@ -42,8 +44,7 @@
4244
'country': 'US',
4345
}
4446
}
45-
print(Order.validate(order_details_variables))
46-
47+
print(fraud_validation.validate(order_details_variables))
4748

4849
"""
4950
# Here is an example to get transaction details.
@@ -52,44 +53,42 @@
5253
# type is id type, which define either the id is FraudLabsPrp::FLP_ID or FraudLabsPro::ORDER_ID.
5354
"""
5455
get_transaction_variables = {
55-
'key': api_key,
5656
'id': '20180705-WISXW2',
5757
'id_type': 'FraudLabsPro::FLP_ID'
5858
}
59-
print(Order.get_transaction(get_transaction_variables))
59+
print(fraud_validation.get_transaction(get_transaction_variables))
6060

6161
"""
6262
# Here is example of send feecback of either approve or reject this particular order.
6363
"""
6464
feedback_variables = {
65-
'key': api_key,
6665
'id': '20180705-WISXW2',
6766
# Three actions available: APPROVE, REJECT, REJECT_BLACKLIST
6867
'action': 'APPROVE',
6968
'notes': 'This is for testing purpose.',
7069
}
71-
print(Order.feedback(feedback_variables))
70+
print(fraud_validation.feedback(feedback_variables))
71+
72+
sms_validation = SMSVerification(api_key)
7273

7374
"""
7475
# Here is example of verify the valid order by send the SMS to customer.
7576
"""
7677
sms_verification_variables = {
77-
'key': api_key,
7878
'tel': '+15616288674',
7979
'country_code': 'US',
8080
'mesg': 'Your OTP for the transaction is <otp>.',
8181
'otp_timeout': 3600,
8282
}
83-
print(SMSVerification.send_sms(sms_verification_variables))
83+
print(sms_validation.send_sms(sms_verification_variables))
8484

8585
"""
8686
# Here is example of check the SMS verification result of the particular order.
8787
"""
8888
verify_sms_variables = {
89-
'key': api_key,
9089
'tran_id': 'UNIQUE_TRANS_ID',
9190
'otp': 'OTP_RECEIVED',
9291
}
93-
print(SMSVerification.verify_sms(verify_sms_variables))
92+
print(sms_validation.verify_sms(verify_sms_variables))
9493

9594

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,20 @@ def hash_function(value):
3131
# Validates order for possible fraud and feedback user decision.
3232
"""
3333

34-
class Order:
34+
class FraudValidation:
35+
def __init__(self, apikey):
36+
self.apikey = apikey
3537
"""
3638
# Validate order for possible fraud. Return the result in json format.
3739
#
3840
# Result will be return in json format.
3941
"""
40-
def validate(dictionary):
42+
def validate(self, dictionary):
4143
# Capture variable and store in local variable
42-
if 'key' in dictionary:
43-
api_key = dictionary['key']
44-
else:
45-
return ('The API key is required. Please obtain through here: https://www.fraudlabspro.com/pricing')
44+
# if 'key' in dictionary:
45+
# api_key = dictionary['key']
46+
# else:
47+
# return ('The API key is required. Please obtain through here: https://www.fraudlabspro.com/pricing')
4648
# The IP address.
4749
if 'ip' in dictionary:
4850
ipaddr = dictionary['ip']
@@ -228,7 +230,7 @@ def validate(dictionary):
228230
ship_country = ''
229231
# Put all the variables into the array before send to the API
230232
validate_variable_list = {
231-
'key': api_key,
233+
'key': self.apikey,
232234
'ip': ipaddr,
233235
'format': 'json',
234236
'source': 'FraudLabsPro Python SDK',
@@ -284,11 +286,11 @@ def validate(dictionary):
284286
#
285287
# Result will be return in json format.
286288
"""
287-
def feedback(feedback_variables):
288-
if 'key' in feedback_variables:
289-
apikey = feedback_variables['key']
290-
else:
291-
return 'The API key is required. Please obtain through here: https://www.fraudlabspro.com/pricing'
289+
def feedback(self, feedback_variables):
290+
# if 'key' in feedback_variables:
291+
# apikey = feedback_variables['key']
292+
# else:
293+
# return 'The API key is required. Please obtain through here: https://www.fraudlabspro.com/pricing'
292294
if 'id' in feedback_variables:
293295
transaction_id = feedback_variables['id']
294296
else:
@@ -302,7 +304,7 @@ def feedback(feedback_variables):
302304
else:
303305
notes = ''
304306
feedback_variables_list = {
305-
'key': apikey,
307+
'key': self.apikey,
306308
'format': 'json',
307309
'id': transaction_id,
308310
'action': action,
@@ -325,11 +327,11 @@ def feedback(feedback_variables):
325327
#
326328
# Result will be return in json format.
327329
"""
328-
def get_transaction(get_transaction_variables):
329-
if 'key' in get_transaction_variables:
330-
api_key = get_transaction_variables['key']
331-
else:
332-
return('The API key is required. Please obtain through here: https://www.fraudlabspro.com/pricing')
330+
def get_transaction(self, get_transaction_variables):
331+
# if 'key' in get_transaction_variables:
332+
# api_key = get_transaction_variables['key']
333+
# else:
334+
# return('The API key is required. Please obtain through here: https://www.fraudlabspro.com/pricing')
333335
if 'id' in get_transaction_variables:
334336
fraud_labs_pro_id = get_transaction_variables['id']
335337
else:
@@ -339,7 +341,7 @@ def get_transaction(get_transaction_variables):
339341
else:
340342
return "Your ID type is empty!"
341343
get_transaction_variable_list = {
342-
'key': api_key,
344+
'key': self.apikey,
343345
'format': 'json',
344346
'id': fraud_labs_pro_id,
345347
'id_type': id_type,

fraudlabspro/smsverification.py

Lines changed: 79 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -19,80 +19,82 @@
1919
#Send SMS Verification for authentication and get Verification result.
2020
"""
2121
class SMSVerification:
22-
"""
23-
# Send SMS Verification for authentication.
24-
#
25-
# Result will be return in json format.
26-
"""
27-
def send_sms(send_sms_variables):
28-
if 'key' in send_sms_variables:
29-
apikey = send_sms_variables['key']
30-
else:
31-
return 'The API key is required. Please obtain through here: https://www.fraudlabspro.com/pricing'
32-
if 'tel' in send_sms_variables:
33-
tel_no = send_sms_variables['tel']
34-
else:
35-
return 'Telephone number is required.'
36-
if 'country_code' in send_sms_variables:
37-
country_code = send_sms_variables['country_code']
38-
else:
39-
country_code = ''
40-
if 'mesg' in send_sms_variables:
41-
message = send_sms_variables['mesg']
42-
else:
43-
return 'Message is required.'
44-
if 'otp_timeout' in send_sms_variables:
45-
otp_timeout = send_sms_variables['otp_timeout']
46-
else:
47-
otp_timeout = 3600
48-
send_sms_variables_list = {
49-
'key': apikey,
50-
'format': 'json',
51-
'tel': tel_no,
52-
'country_code': country_code,
53-
'mesg': message,
54-
'otp_timeout': otp_timeout,
55-
}
56-
url = 'https://api.fraudlabspro.com/v1/verification/send'
57-
data = urllib.parse.urlencode(send_sms_variables_list)
58-
data = data.encode('utf-8')
59-
request = urllib.request.Request(url, data)
60-
with urllib.request.urlopen(request) as response:
61-
string = response.read().decode('utf-8')
62-
json_obj = json.loads(string)
63-
result = json.dumps(json_obj, indent=4)
64-
return(result)
65-
66-
"""
67-
# Get Verification result.
68-
#
69-
#Result will be return in json format.
70-
"""
71-
def verify_sms(verify_sms_variables):
72-
if 'key' in verify_sms_variables:
73-
apikey = verify_sms_variables['key']
74-
else:
75-
return 'The API key is required. Please obtain through here: https://www.fraudlabspro.com/pricing'
76-
77-
if 'tran_id' in verify_sms_variables:
78-
transaction_id = verify_sms_variables['tran_id']
79-
else:
80-
return 'Transaction id is required.'
81-
if 'otp' in verify_sms_variables:
82-
otp = verify_sms_variables['otp']
83-
else:
84-
return 'OTP is required.'
85-
verify_sms_variables_list = {
86-
'key': apikey,
87-
'format': 'json',
88-
'tran_id': transaction_id,
89-
'otp': otp,
90-
}
91-
url = 'https://api.fraudlabspro.com/v1/verification/result'
92-
url_values = urllib.parse.urlencode(verify_sms_variables_list)
93-
full_url = url + '?' + url_values
94-
data = urllib.request.urlopen(full_url)
95-
string = data.read().decode('utf-8')
96-
json_obj = json.loads(string)
97-
result = json.dumps(json_obj, indent=4)
98-
return(result)
22+
def __init__(self, apikey):
23+
self.apikey = apikey
24+
"""
25+
# Send SMS Verification for authentication.
26+
#
27+
# Result will be return in json format.
28+
"""
29+
def send_sms(self, send_sms_variables):
30+
# if 'key' in send_sms_variables:
31+
# apikey = send_sms_variables['key']
32+
# else:
33+
# return 'The API key is required. Please obtain through here: https://www.fraudlabspro.com/pricing'
34+
if 'tel' in send_sms_variables:
35+
tel_no = send_sms_variables['tel']
36+
else:
37+
return 'Telephone number is required.'
38+
if 'country_code' in send_sms_variables:
39+
country_code = send_sms_variables['country_code']
40+
else:
41+
country_code = ''
42+
if 'mesg' in send_sms_variables:
43+
message = send_sms_variables['mesg']
44+
else:
45+
return 'Message is required.'
46+
if 'otp_timeout' in send_sms_variables:
47+
otp_timeout = send_sms_variables['otp_timeout']
48+
else:
49+
otp_timeout = 3600
50+
send_sms_variables_list = {
51+
'key': self.apikey,
52+
'format': 'json',
53+
'tel': tel_no,
54+
'country_code': country_code,
55+
'mesg': message,
56+
'otp_timeout': otp_timeout,
57+
}
58+
url = 'https://api.fraudlabspro.com/v1/verification/send'
59+
data = urllib.parse.urlencode(send_sms_variables_list)
60+
data = data.encode('utf-8')
61+
request = urllib.request.Request(url, data)
62+
with urllib.request.urlopen(request) as response:
63+
string = response.read().decode('utf-8')
64+
json_obj = json.loads(string)
65+
result = json.dumps(json_obj, indent=4)
66+
return(result)
67+
68+
"""
69+
# Get Verification result.
70+
#
71+
#Result will be return in json format.
72+
"""
73+
def verify_sms(self, verify_sms_variables):
74+
# if 'key' in verify_sms_variables:
75+
# apikey = verify_sms_variables['key']
76+
# else:
77+
# return 'The API key is required. Please obtain through here: https://www.fraudlabspro.com/pricing'
78+
79+
if 'tran_id' in verify_sms_variables:
80+
transaction_id = verify_sms_variables['tran_id']
81+
else:
82+
return 'Transaction id is required.'
83+
if 'otp' in verify_sms_variables:
84+
otp = verify_sms_variables['otp']
85+
else:
86+
return 'OTP is required.'
87+
verify_sms_variables_list = {
88+
'key': self.apikey,
89+
'format': 'json',
90+
'tran_id': transaction_id,
91+
'otp': otp,
92+
}
93+
url = 'https://api.fraudlabspro.com/v1/verification/result'
94+
url_values = urllib.parse.urlencode(verify_sms_variables_list)
95+
full_url = url + '?' + url_values
96+
data = urllib.request.urlopen(full_url)
97+
string = data.read().decode('utf-8')
98+
json_obj = json.loads(string)
99+
result = json.dumps(json_obj, indent=4)
100+
return(result)

0 commit comments

Comments
 (0)