-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
46 lines (35 loc) · 1.35 KB
/
app.py
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
from flask import Flask, jsonify, request
import json
from .payment.paymentservices import CreditCard, ExternalServices
app = Flask(__name__)
@app.route("/processpayment", methods=['POST'])
def payment():
if request.method == 'POST':
data = request.get_json()
# if there is no input is loaded
if not data:
return {"status code": 400}, 400
#Now it is the time to validate
credit_card = CreditCard()
try:
if not credit_card.cardValidation(**data):
print('Credit Card information is not valid!')
return {"status code": 400}, 400
except:
print("Internal Error related to credit card section")
return {"status code": 500}, 500
#Checking hte external payment ExternalServices
try:
services = ExternalServices(credit_card.amount)
payment_type = services.gatewayType(credit_card.cardInfoDic)
if payment_type:
return {"status code": 200}, 200
print('Payment process is failed!!')
return {"status code": 400}, 400
except:
print("Internal Error related to External Payment section")
return {"status code": 500}, 500
else:
return {"status code": 400}, 400
if __name__ == '__main__':
app.run(debug=True)