-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.py
142 lines (116 loc) · 3.67 KB
/
index.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from flask import Flask, request, render_template
from flask_restful import Resource, Api
from copy import deepcopy
from uuid import uuid4
from pathlib import Path
import sys
from flask import json
from flask_cors import CORS
path_root = Path(__file__).parents[2]
sys.path.append(str(path_root))
print(sys.path)
from culqi import __version__
from culqi.client import Culqi
from culqi.resources import Card, Order
from culqi.resources import Customer
from culqi.resources import Charge
app = Flask(__name__)
api = Api(app)
CORS(app)
public_key = "pk_test_e94078b9b248675d"
private_key = "sk_test_c2267b5b262745f0"
rsa_id = "de35e120-e297-4b96-97ef-10a43423ddec"
rsa_public_key = "-----BEGIN PUBLIC KEY-----\n"+\
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDswQycch0x/7GZ0oFojkWCYv+g\n"+\
"r5CyfBKXc3Izq+btIEMCrkDrIsz4Lnl5E3FSD7/htFn1oE84SaDKl5DgbNoev3pM\n"+\
"C7MDDgdCFrHODOp7aXwjG8NaiCbiymyBglXyEN28hLvgHpvZmAn6KFo0lMGuKnz8\n"+\
"HiuTfpBl6HpD6+02SQIDAQAB\n"+\
"-----END PUBLIC KEY-----"
port = 5100
if sys.argv.__len__() > 1:
port = sys.argv[1]
print("Api running on port : {} ".format(port))
@app.route('/', methods=['GET', 'POST'])
def home():
return render_template('index.html')
@app.route('/card')
def card():
return render_template('index-card.html')
@app.route('/culqi/createCard', methods=['POST'])
def generatecard():
body = request.json
version = __version__
culqi = Culqi(public_key, private_key)
card = Card(client=culqi)
card = card.create(body)
response = app.response_class(
response=json.dumps(card["data"]),
status=json.dumps(card["status"]),
mimetype='application/json'
)
return response
@app.route('/culqi/createCustomer', methods=['POST'])
def generatecutomer():
body = request.json
version = __version__
culqi = Culqi(public_key, private_key)
customer = Customer(client=culqi)
data = {
"first_name": body["first_name"],
"last_name": body["last_name"],
"email": body["email"],
"address": body["address"],
"address_city": body["address_city"],
"country_code": body["country_code"],
"phone_number": body["phone_number"],
}
card = customer.create(data)
response = app.response_class(
response=json.dumps(card["data"]),
status=json.dumps(card["status"]),
mimetype='application/json'
)
return response
@app.route('/culqi/generateCharge', methods=['POST'])
def generatecharge():
body = request.json
version = __version__
culqi = Culqi(public_key, private_key)
charge = Charge(client=culqi)
print (rsa_public_key)
print (rsa_id)
options = {}
options["rsa_public_key"] = rsa_public_key
options["rsa_id"] = rsa_id
if len(rsa_id) == 0:
card = charge.create(body)
else:
card = charge.create(body, **options)
print(card)
response = app.response_class(
response=json.dumps(card["data"]),
status=json.dumps(card["status"]),
mimetype='application/json'
)
return response
@app.route('/culqi/generateOrder', methods=['POST'])
def generateorder():
body = request.json
version = __version__
culqi = Culqi(public_key, private_key)
order = Order(client=culqi)
card = order.create(body)
print(card)
response = app.response_class(
response=json.dumps(card["data"]),
status=json.dumps(card["status"]),
mimetype='application/json'
)
return response
if __name__ == '__main__':
app.run(host="0.0.0.0", port=port)
@app.route('/')
def home():
return render_template('index.html')
if __name__ == '__main__':
app.run(host="0.0.0.0", port=port)