-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdonation.py
33 lines (26 loc) · 984 Bytes
/
donation.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
from flask import Flask, redirect, jsonify
import stripe
from flask_cors import CORS, cross_origin
port = 50
servername = 'localhost' + ':' + str(port)
domain = 'http://' + servername
app = Flask(__name__)
CORS(app, resources={r"/create-checkout-session": {"origins": domain}})
@app.route('/create-checkout-session', methods=['POST'])
@cross_origin(origin='localhost', headers=['Content-Type', 'application/json'])
def create_checkout_session():
try:
intent = stripe.PaymentIntent.create(
amount=200,
currency='usd',
api_key='sk_test_51Jhf7CCOIWLLuzJ63rseG0KMZPQDG3rLdUPJpIEANRrYZTL7nuXxtqzYMdd7V3ftOFRKhKy4L4JY5CQjC6dt4UcN00xrwDEaWo'
)
return jsonify({
'clientSecret': intent['client_secret']
})
except Exception as e:
return jsonify(error=str(e)), 403
if __name__ == '__main__':
app.config['SERVER_NAME'] = servername
app.config['DOMAIN'] = domain
app.run(port=port)