Skip to content

Commit c3b9e20

Browse files
committed
Added Payment Feedback API
1 parent 88ce028 commit c3b9e20

7 files changed

Lines changed: 154 additions & 25 deletions

File tree

docs/source/code.md

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Retrieve an existing transaction from FraudLabs Pro fraud detection system.
1414
1515
| Parameter Name | Parameter Type | Description |
1616
| -------------- | -------------- | ------------------------------------------------------------ |
17-
| id | string | FraudLabs Pro transaction ID or Order ID. |
17+
| id | string | FraudLabs Pro transaction ID or Order ID. |
1818
1919
:return: Returns the details about the transaction in JSON object.
2020
:rtype: Object
@@ -85,9 +85,9 @@ Approve, reject or ignore a transaction.
8585
8686
| Parameter | Type | Description |
8787
|--------------|---------|---------------------|
88-
| id | string | (required) Unique transaction Id generated by Fraud Check API. |
89-
| action | string | (required) Perform APPROVE, REJECT, or REJECT_BLACKLIST action to transaction.<br/>• APPROVE: Approve a transaction<br/>• REJECT: Reject a transaction<br/>• REJECT_BLACKLIST: Reject and blacklist the transaction<br/>When a transaction was blacklisted, the information will be recorded into the system for future blacklist validation check. |
90-
| note | integer | (optional) Notes for the feedback request. |
88+
| id | string | (required) Unique transaction Id generated by Fraud Check API. |
89+
| action | string | (required) Perform APPROVE, REJECT, or REJECT_BLACKLIST action to transaction.<br/>• APPROVE: Approve a transaction<br/>• REJECT: Reject a transaction<br/>• REJECT_BLACKLIST: Reject and blacklist the transaction<br/>When a transaction was blacklisted, the information will be recorded into the system for future blacklist validation check. |
90+
| note | integer | (optional) Notes for the feedback request. |
9191
```
9292

9393
```{py:function} validate(params)
@@ -104,6 +104,7 @@ Retrieve geolocation information for an IP address.
104104
| billing->password | string | (optional) User's password. |
105105
| billing->email | string | (optional) User's email address. |
106106
| billing->phone | string | (optional) User's phone number. |
107+
| billing->billto | string | (optional) Billing details such as company name. |
107108
| billing->address | string | (optional) Street address of billing address. |
108109
| billing->city | string | (optional) City of billing address. |
109110
| billing->state | string | (optional) State of billing address. It supports state codes, e.g. NY (New York), for state or province of United States or Canada.|
@@ -195,7 +196,7 @@ Retrieve geolocation information for an IP address.
195196

196197
## SMSVerification Class
197198
```{py:class} SMSVerification(api_key)
198-
Initiate FraudValidation class with FraudLabs Pro API key.
199+
Initiate SMSVerification class with FraudLabs Pro API key.
199200
200201
:param str api_key: (Required) FraudLabs Pro API key.
201202
```
@@ -231,12 +232,40 @@ Get SMS Verification result.
231232
| Parameter | Type | Description |
232233
|-------------------|--------|-------------|
233234
| tran_id | string | (required) Unique ID (20 characters) for this particular API call. |
234-
| otp | string | (required) The OTP that was sent to the recipient’s phone. |
235+
| otp | string | (required) The OTP that was sent to the recipient’s phone. |
235236
236237
:return: Returns the details about the transaction in JSON object.
237238
:rtype: Object
238239
239240
| Parameter | Type | Description |
240241
|-------------------|--------|-------------|
241-
| result | string | Indicates if the input parameters matched a valid OTP. Y if a valid OTP is found and N if no valid OTP found. |
242+
| result | string | Indicates if the input parameters matched a valid OTP. Y if a valid OTP is found and N if no valid OTP found. |
243+
```
244+
245+
## Payment Class
246+
```{py:class} Payment(api_key)
247+
Initiate Payment class with FraudLabs Pro API key.
248+
249+
:param str api_key: (Required) FraudLabs Pro API key.
250+
```
251+
252+
```{py:function} feedback(params)
253+
Report the final payment status back to the system.
254+
255+
:param array params: (Required) The parameters of order details.
256+
257+
| Parameter | Type | Description |
258+
|------------------|---------|---------------------|
259+
| email | string | (required) Email address of the payment order. |
260+
| status | string | (required) Status of the payment order. |
261+
| message | string | (required) Message returned from the payment gateway for the payment order. |
262+
| fraudlabspro_id | string | (optional) Unique transaction Id generated by Fraud Check API. |
263+
264+
265+
:return: Returns the details about the transaction in map object.
266+
:rtype: Object
267+
268+
| Parameter | Type | Description |
269+
|-------------------|--------|-------------|
270+
| result | string | Indicates if submission is successful. |
242271
```

docs/source/quickstart.md

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ pip install fraudlabspro-python
1919
You can validate your order as below:
2020

2121
```python
22-
# import SDK to use the function
22+
# import SDK to use the function
2323
from fraudlabspro.fraudvalidation import FraudValidation
2424

25-
# Configure your API key
25+
# Configure your API key
2626
api_key = 'YOUR_API_KEY'
2727
fraud_validation = FraudValidation(api_key)
2828

29-
# Order Details
29+
# Order Details
3030
dict1 = {
3131
'ip': '146.112.62.105',
3232
'order': {
@@ -62,7 +62,7 @@ dict1 = {
6262
}
6363
}
6464

65-
# Sends the order details to FraudLabs Pro
65+
# Sends the order details to FraudLabs Pro
6666
result = fraud_validation.validate(dict1)
6767
```
6868

@@ -71,35 +71,35 @@ result = fraud_validation.validate(dict1)
7171
You can get the details of a transaction as below:
7272

7373
```python
74-
# import SDK to use the function
74+
# import SDK to use the function
7575
from fraudlabspro.fraudvalidation import FraudValidation
7676

77-
# Configure your API key
77+
# Configure your API key
7878
api_key = 'YOUR_API_KEY'
7979
fraud_validation = FraudValidation(api_key)
8080

81-
# Values to get transaction details
81+
# Values to get transaction details
8282
get_transaction_variables = {
8383
'id': '20180705-WISXW2',
8484
}
8585

86-
# Send the values to FraudLabs Pro
86+
# Send the values to FraudLabs Pro
8787
result = fraud_validation.get_transaction(get_transaction_variables)
8888
```
8989

90-
### Feedback
90+
### Feedback an order
9191

9292
You can approve, reject or ignore a transaction as below:
9393

9494
```python
9595
# import SDK to use the function
9696
from fraudlabspro.fraudvalidation import FraudValidation
9797

98-
# Configure your API key
98+
# Configure your API key
9999
api_key = 'YOUR_API_KEY'
100100
fraud_validation = FraudValidation(api_key)
101101

102-
# Set feedback of the particular order
102+
# Set feedback of the particular order
103103
feedback_variables = {
104104
'id': '20180705-WISXW2',
105105
# Three actions available: APPROVE, REJECT, REJECT_BLACKLIST
@@ -118,11 +118,11 @@ You can send SMS verification for authentication purpose as below:
118118
# import SDK to use the function
119119
from fraudlabspro.smsverification import SMSVerification
120120

121-
# Configure your API key
121+
# Configure your API key
122122
api_key = 'YOUR_API_KEY'
123123
sms_validation = SMSVerification(api_key)
124124

125-
# Send SMS verification
125+
# Send SMS verification
126126
sms_verification_variables = {
127127
'tel': '+123456789',
128128
'country_code': 'US',
@@ -137,17 +137,41 @@ result = sms_validation.send_sms(sms_verification_variables)
137137
You can verify the OTP sent by Fraudlabs Pro SMS verification API as below:
138138

139139
```python
140-
# import SDK to use the function
140+
# import SDK to use the function
141141
from fraudlabspro.smsverification import SMSVerification
142142

143143
# Configure your API key
144144
api_key = 'YOUR_API_KEY'
145145
sms_validation = SMSVerification(api_key)
146146

147-
# Get SMS verification result
147+
# Get SMS verification result
148148
verify_sms_variables = {
149149
'tran_id': 'UNIQUE_TRANS_ID',
150150
'otp': 'OTP_RECEIVED',
151151
}
152152
result = sms_validation.verify_sms(verify_sms_variables)
153+
```
154+
155+
### Report Payment Gateway Feedback
156+
157+
You can report payment gateway feedback as below:
158+
159+
```python
160+
# import SDK to use the function
161+
from fraudlabspro.payment import Payment
162+
163+
# Configure your API key
164+
api_key = 'YOUR_API_KEY'
165+
payment_cls = Payment(api_key)
166+
167+
# Set feedback of the particular order
168+
feedback_variables = {
169+
'email': 'aaa@mailinator.com',
170+
'status': '-',
171+
'message': 'This is a test.'
172+
}
173+
174+
result = payment_cls.feedback(feedback_variables)
175+
176+
print(result)
153177
```

example.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# import SDK to use the function
22
from fraudlabspro.fraudvalidation import FraudValidation
33
from fraudlabspro.smsverification import SMSVerification
4+
from fraudlabspro.payment import Payment
45

56
# Configure your API key
67
api_key = 'YOUR_API_KEY'
78

8-
# validation = fraudlabspro.fraudvalidation.FraudValidation(api_key)
9-
# validation = fraudlabspro.FraudValidation(api_key)
109
fraud_validation = FraudValidation(api_key)
1110

1211
"""
@@ -94,4 +93,17 @@
9493
}
9594
print(sms_validation.verify_sms(verify_sms_variables))
9695

96+
payment_cls = Payment(api_key)
9797

98+
"""
99+
# Here is example of report the final payment status of an order.
100+
"""
101+
feedback_variables = {
102+
'email': 'aaa@mailinator.com',
103+
'status': '-',
104+
'message': 'This is a test.'
105+
}
106+
107+
result = payment_cls.feedback(feedback_variables)
108+
109+
print(result)

fraudlabspro/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Constants that will be use across various classes
2+
3+
BASE_URL = 'https://api.fraudlabspro.com/v2/'
4+
MODULE_VERSION = '3.1.0'

fraudlabspro/fraudvalidation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ def validate(self, dictionary):
171171
user_phone = re.sub(r'\D','',phone)
172172
else:
173173
user_phone = ''
174+
if 'billto' in dictionary['billing']:
175+
bill_to = dictionary['billing']['billto']
176+
else:
177+
bill_to = ''
174178
if 'address' in dictionary['billing']:
175179
bill_addr = dictionary['billing']['address']
176180
else:
@@ -200,6 +204,7 @@ def validate(self, dictionary):
200204
email_domain = ''
201205
email_hash = ''
202206
user_phone = ''
207+
bill_to = ''
203208
bill_addr = ''
204209
bill_city = ''
205210
bill_state = ''
@@ -274,6 +279,7 @@ def validate(self, dictionary):
274279
'email_hash': email_hash,
275280
'email_domain': email_domain,
276281
'user_phone': user_phone,
282+
'bill_to': bill_to,
277283
'bill_addr': bill_addr,
278284
'bill_city': bill_city,
279285
'bill_state': bill_state,

fraudlabspro/payment.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import json
2+
import urllib.parse
3+
import urllib.request
4+
from urllib.parse import urljoin
5+
6+
from .constants import BASE_URL, MODULE_VERSION
7+
8+
9+
class Payment:
10+
"""
11+
FraudLabsPro Payment module.
12+
13+
Allows merchants to report the final payment status back to the system,
14+
helping improve fraud detection and risk assessment.
15+
"""
16+
17+
def __init__(self, api_key):
18+
self.api_key = api_key
19+
20+
def feedback(self, feedback_variables):
21+
# Validate required fields
22+
required_fields = ['email', 'status', 'message']
23+
for field in required_fields:
24+
if field not in feedback_variables:
25+
return json.dumps({"error": f"{field} is required"})
26+
27+
# Prepare payload
28+
payload = {
29+
'key': self.api_key,
30+
'source_version': MODULE_VERSION,
31+
'email': feedback_variables['email'],
32+
'status': feedback_variables['status'],
33+
'message': feedback_variables['message'],
34+
}
35+
36+
# Handle optional fraudlabspro_id
37+
if 'fraudlabspro_id' in feedback_variables:
38+
payload['id'] = feedback_variables['fraudlabspro_id']
39+
40+
url = urljoin(BASE_URL, 'payment/feedback')
41+
data = urllib.parse.urlencode(payload).encode('utf-8')
42+
43+
try:
44+
request = urllib.request.Request(url, data=data)
45+
with urllib.request.urlopen(request) as response:
46+
raw_data = response.read().decode('utf-8')
47+
json_obj = json.loads(raw_data)
48+
except urllib.error.HTTPError as http_error:
49+
error_data = http_error.read().decode('utf-8')
50+
json_obj = json.loads(error_data)
51+
except Exception as e:
52+
return json.dumps({"error": str(e)})
53+
54+
return json.dumps(json_obj, indent=4)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="fraudlabspro-python",
8-
version="3.0.3",
8+
version="3.1.0",
99
author="FraudLabs Pro",
1010
author_email="support@fraudlabspro.com",
1111
description="A Python module enables user to easily implement fraud detection feature into their solution using the API from https://www.fraudlabspro.com.",

0 commit comments

Comments
 (0)