-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessing_server.py
More file actions
48 lines (38 loc) · 1.68 KB
/
processing_server.py
File metadata and controls
48 lines (38 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from flask import Flask, request, jsonify
app = Flask(__name__)
# Define a mock endpoint for processing payment authorization
@app.route('/make-payment', methods=['POST'])
def make_payment():
try:
print("Received POST request to /make-payment")
# Parse JSON data from the request
payment_data = request.get_json()
card_number = payment_data["card_number"]
expiration_date = payment_data["expiration_date"]
cvv = payment_data["cvv"]
amount = float(payment_data["amount"])
# Simulate a failure when the payment amount is above a certain limit
failure_limit = 1000 # Set your failure limit (e.g., $1000)
if amount > failure_limit:
error_response = {
"status": "Error",
"message": "Payment authorization failed. Payment amount exceeds the limit."
}
return jsonify(error_response), 400 # Return JSON error response with HTTP status 400 (Bad Request)
# Payment authorization logic
authorization_code = "AUTH12345" # Simulated authorization code
response_data = {
"status": "Success",
"message": "Payment authorized successfully.",
"authorization_code": authorization_code
}
return jsonify(response_data), 200 # Return JSON response with HTTP status 200 (OK)
except Exception as e:
error_response = {
"status": "Error",
"message": str(e)
}
print("Error:", e)
return jsonify(error_response), 400 # Return JSON error response with HTTP status 400 (Bad Request)
if __name__ == '__main__':
app.run(host='localhost', port=5000)