-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
115 lines (97 loc) · 3.63 KB
/
server.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
#! /usr/bin/env python3.6
"""
server.py
Stripe Sample.
Python 3.6 or newer required.
"""
import os
from flask import Flask, redirect, request
import stripe
# This is your test secret API key.
stripe.api_key = 'sk_test_51NtAH4AhTNodXMLTUprAYl9SP6l79qP7pt0mniY1PSwgBSHRhzdBbsuXMDqU3D3kTiKUbzVn9fA7alhMv4XwQ1zf002p36eBdK'
app = Flask(__name__,
static_url_path='',
static_folder='')
YOUR_DOMAIN = 'https://andrewgithb.github.io/shopping-demo/'
@app.route('/hoodie-buy', methods=['POST'])
#@app.route('/create-checkout-session', methods=['POST'])
def create_checkout_session():
try:
checkout_session = stripe.checkout.Session.create(
line_items=[
{
# Provide the exact Price ID (for example, pr_1234) of the product you want to sell
'price': 'price_1NtAOLAhTNodXMLT9JfmgVO1',
'quantity': 1,
},
],
mode='payment',
success_url=YOUR_DOMAIN + '/success.html',
cancel_url=YOUR_DOMAIN + '/cancel.html',
)
except Exception as e:
return str(e)
return redirect(checkout_session.url, code=303)
@app.route('/tee-buy', methods=['POST'])
#@app.route('/create-checkout-session', methods=['POST'])
def tee_checkout_session():
try:
checkout_session = stripe.checkout.Session.create(
line_items=[
{
# Provide the exact Price ID (for example, pr_1234) of the product you want to sell
'price': 'price_1NtBYkAhTNodXMLTkGifzmWc',
'quantity': 1,
},
],
mode='payment',
success_url=YOUR_DOMAIN + '/success.html',
cancel_url=YOUR_DOMAIN + '/cancel.html',
)
except Exception as e:
return str(e)
return redirect(checkout_session.url, code=303)
@app.route('/short-buy', methods=['POST'])
#@app.route('/create-checkout-session', methods=['POST'])
def short_checkout_session():
try:
checkout_session = stripe.checkout.Session.create(
line_items=[
{
# Provide the exact Price ID (for example, pr_1234) of the product you want to sell
'price': 'price_1NtC5cAhTNodXMLTTdonUZsC',
'quantity': 1,
},
],
mode='payment',
success_url=YOUR_DOMAIN + '/success.html',
cancel_url=YOUR_DOMAIN + '/cancel.html',
)
except Exception as e:
return str(e)
return redirect(checkout_session.url, code=303)
# @app.route('/create-checkout-session', methods=['POST'])
# def create_checkout_session():
# try:
# checkout_session = stripe.checkout.Session.create(
# line_items=[
# {
# # Provide the exact Price ID (for example, pr_1234) of the product you want to sell
# 'price': 'price_1NtAOLAhTNodXMLT9JfmgVO1',
# 'quantity': 1,
# },
# {
# 'price': 'price_1NtBYkAhTNodXMLTkGifzmWc',
# 'quantity': 1,
# },
# ],
# mode='payment',
# success_url=YOUR_DOMAIN + '/success.html',
# cancel_url=YOUR_DOMAIN + '/cancel.html',
# )
# except Exception as e:
# return str(e)
# return redirect(checkout_session.url, code=303)
if __name__ == '__main__':
app.run(port=4242)
#app.run(host="andrewgithb.github.io")