stripe tested and working
This commit is contained in:
parent
55d8d8a9a6
commit
7337375ae8
@ -154,7 +154,7 @@ class DBModel:
|
||||
def create_stripe_checkout_session(self, id, email, dollars):
|
||||
self.cursor.execute("""
|
||||
INSERT INTO stripe_checkout_sessions (id, email, dollars)
|
||||
VALUES (%s, %s, %d)
|
||||
VALUES (%s, %s, %s)
|
||||
""",
|
||||
(id, email, dollars)
|
||||
)
|
||||
@ -174,7 +174,7 @@ class DBModel:
|
||||
""")
|
||||
# not sure what to do here. For now just log and do nothing.
|
||||
self.cursor.execute( "DELETE FROM stripe_checkout_sessions WHERE id = %s", (id,) )
|
||||
self.cursor.execute( "INSERT INTO payments (email, dollars) VALUES (%s, %d)", (rows[0][0], rows[0][1]) )
|
||||
self.cursor.execute( "INSERT INTO payments (email, dollars) VALUES (%s, %s)", (rows[0][0], rows[0][1]) )
|
||||
self.connection.commit()
|
||||
return rows[0][0]
|
||||
else:
|
||||
|
@ -25,12 +25,18 @@ bp = Blueprint("stripe", __name__, url_prefix="/stripe")
|
||||
def index():
|
||||
|
||||
stripe_checkout_session_id=None
|
||||
errors = list()
|
||||
|
||||
if request.method == "POST":
|
||||
errors = list()
|
||||
if "dollars" not in request.form:
|
||||
errors.append("dollars is required")
|
||||
elif decimal.Decimal(request.form["dollars"]) < decimal.Decimal(1):
|
||||
dollars = None
|
||||
try:
|
||||
dollars = decimal.Decimal(request.form["dollars"])
|
||||
except:
|
||||
errors.append("dollars must be a number")
|
||||
|
||||
if dollars and dollars < decimal.Decimal(1):
|
||||
errors.append("dollars must be >= 1")
|
||||
|
||||
if len(errors) == 0:
|
||||
@ -48,7 +54,7 @@ def index():
|
||||
"images": [current_app.config['BASE_URL']+"/static/capsul-product-image.png"],
|
||||
"quantity": 1,
|
||||
"currency": "usd",
|
||||
"amount": request.form["dollars"]
|
||||
"amount": int(dollars*100)
|
||||
}
|
||||
]
|
||||
)
|
||||
@ -76,7 +82,8 @@ def success():
|
||||
else:
|
||||
checkout_session = stripe.checkout.Session.retrieve(stripe_checkout_session_id)
|
||||
if checkout_session and 'display_items' in checkout_session:
|
||||
dollars = checkout_session['display_items'][0]['amount']
|
||||
cents = checkout_session['display_items'][0]['amount']
|
||||
dollars = decimal.Decimal(cents)/100
|
||||
|
||||
#consume_stripe_checkout_session deletes the checkout session row and inserts a payment row
|
||||
# its ok to call consume_stripe_checkout_session more than once because it only takes an action if the session exists
|
||||
|
@ -11,8 +11,8 @@
|
||||
<div class="row half-margin">
|
||||
<form method="post">
|
||||
<div class="row justify-start">
|
||||
<label for="content">$</label>
|
||||
<input type="number" id="name" name="name"></input>
|
||||
<label for="dollars">$</label>
|
||||
<input type="number" id="dollars" name="dollars"></input>
|
||||
</div>
|
||||
<div class="row justify-end">
|
||||
<input type="submit" value="Pay With Stripe">
|
||||
|
Loading…
Reference in New Issue
Block a user