1919 #Send SMS Verification for authentication and get Verification result.
2020"""
2121class 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