-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
59 lines (49 loc) · 1.63 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
47
48
49
50
51
52
53
54
55
56
57
58
from flask import Flask, request, send_file, current_app
import qrcode
import requests
import stripe
app = Flask(__name__)
@app.route('/')
def index():
return "<p> Base </p>"
@app.route('/register', methods=['POST', 'GET'])
def register():
args = request.args.to_dict()
stripe.api_key = args['stripe_key']
return 'OK', 200
@app.route('/add-product')
def add_product():
args = request.args.to_dict()
if 'name' not in args:
return 'Bad Request', 400
try:
product = stripe.Product.create(name=args['name'])
return product
except:
return 'Error', 500
@app.route('/create-price')
def create_price():
args = request.args.to_dict()
if 'currency' not in args and 'unit_amount' not in args and 'id' not in args:
return 'Bad Request', 400
currency = 'usd' if 'currency' not in args else args['currency']
unit_amount = 1000 if 'unit_amount' not in args else args['unit_amount']
id = args['id']
try:
price = stripe.Price.create(currency=currency, unit_amount=unit_amount, product=id)
return price
except:
return 'Error', 500
@app.route('/qr/<priceid>')
def generate_qrcode(priceid):
args = request.args.to_dict()
# stripe token must be present
payment_link = stripe.PaymentLink.create(line_items=[{"price": priceid, "quantity": 1}])
payment_link_id = payment_link['id']
url = payment_link['url']
img = qrcode.make(url)
img.save(f'./static/{payment_link_id}.png')
return payment_link_id
@app.route('/view/<plink_id>')
def view_qr(plink_id):
return current_app.send_static_file(f'{plink_id}.png')