/
routes.py
138 lines (108 loc) · 3.75 KB
/
routes.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
from flask import Flask, render_template, request, flash, session
from forms import ContactForm
from flask.ext.mail import Message, Mail
from flask_sslify import SSLify
import stripe
stripe_keys = {
'secret_key' : '',
'publishable_key' : ''
}
stripe.api_key = stripe_keys['secret_key']
mail = Mail()
app = Flask(__name__)
sslify = SSLify(app)
app.secret_key = ""
app.config["MAIL_SERVER"] = "smtp.mailgun.org"
app.config["MAIL_PORT"] = 465
app.config["MAIL_USE_SSL"] = True
app.config["MAIL_USERNAME"] = ""
app.config["MAIL_PASSWORD"] = ""
mail.init_app(app)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/contact', methods=['GET','POST'])
def contact():
form = ContactForm()
if request.method == 'POST':
if form.validate() == False:
flash("All fields are required.")
return render_template('contact.html', form=form)
else:
gdict = { True : "(Associate/non-member)", False : "" }
ticket_count = (form.mg1.data + form.mg2.data + form.mg3.data
+ form.mg4.data + form.mg5.data + form.wg1.data + form.wg2.data
+ form.wg3.data + form.wg4.data + form.wg5.data)
memdict = {'yesod' : 0, 'chai' : 0, 'chesed' : 5000, 'member' : 10000,
'assoc' : 10000, 'non-member' : 12000}
seat_number = ticket_count
bill = memdict[form.membership.data] * seat_number
#dollar value of bill
bill_in_dollars = bill / 100.00
session['email'] = form.email.data
session['bill'] = bill
session['bill_in_dollars'] = bill_in_dollars
session['msg'] = """
\nFrom: %s <%s>
\nPhone #: %s
\nMen's Section:
\n 1) %s %s\n 2) %s %s\n 3) %s %s\n 4) %s %s\n 5) %s %s\n
\nWomen's Section:
\n 1) %s %s\n 2) %s %s\n 3) %s %s\n 4) %s %s\n 5) %s %s\n
\nSame Seats? %s
\nComments: %s
\nGuest count: %d
\nMembership: %s
\nPayment: $%d
""" % (form.name.data, form.email.data, form.phone.data, form.mname1.data,
gdict[form.mg1.data], form.mname2.data, gdict[form.mg2.data],
form.mname3.data, gdict[form.mg3.data], form.mname4.data,
gdict[form.mg4.data], form.mname5.data, gdict[form.mg5.data],
form.wname1.data, gdict[form.wg1.data], form.wname2.data,
gdict[form.wg2.data], form.wname3.data, gdict[form.wg3.data],
form.wname4.data, gdict[form.wg4.data], form.wname5.data,
gdict[form.wg5.data], form.same_seats.data,
form.comments.data, ticket_count, form.membership.data, bill_in_dollars)
if bill == 0:
msg = Message("High Holy Days Seating Preferences",
sender='', recipients=[''])
msg.body = session['msg']
mail.send(msg)
return render_template('contact.html', success=True)
else:
return render_template('checkout.html', key=stripe_keys['publishable_key'], amount=bill)
elif request.method == 'GET':
return render_template('contact.html', form=form)
@app.route('/checkout')
def checkout():
return render_template('checkout.html', key=stripe_keys['publishable_key'])
@app.route('/charge', methods=['POST'])
def charge():
#amount in cents
amount = session['bill']
customer = stripe.Customer.create(
email=session['email'],
card=request.form['stripeToken']
)
charge = stripe.Charge.create(
customer=customer.id,
amount=amount,
currency='usd',
description='Flask Charge'
)
msg = Message("",
sender='', recipients=[''])
msg.body = session['msg']
mail.send(msg)
receipt = Message("Thank you for reserving your seats!",
sender='postmaster@app16794441.mailgun.org', recipients=[session['email']])
receipt.body = """
We've received for your payment of $%d for your High Holiday seats at Shaare Torah.
""" % (session['bill_in_dollars'])
mail.send(receipt)
return render_template('charge.html', amount=amount)
if __name__ == '__main__':
app.run()