stripe payment processor
This commit is contained in:
@ -23,7 +23,7 @@ class DBModel:
|
||||
return token
|
||||
|
||||
def consume_token(self, token):
|
||||
self.cursor.execute("SELECT email FROM login_tokens WHERE token = %s", (token, ))
|
||||
self.cursor.execute("SELECT email FROM login_tokens WHERE token = %s and created > (NOW() - INTERVAL '20 min')", (token, ))
|
||||
rows = self.cursor.fetchall()
|
||||
if len(rows) > 0:
|
||||
email = rows[0][0]
|
||||
@ -150,4 +150,35 @@ class DBModel:
|
||||
lambda x: dict(dollars=x[0], created=x[1]),
|
||||
self.cursor.fetchall()
|
||||
))
|
||||
|
||||
def create_stripe_checkout_session(self, id, email, dollars):
|
||||
self.cursor.execute("""
|
||||
INSERT INTO stripe_checkout_sessions (id, email, dollars)
|
||||
VALUES (%s, %s, %d)
|
||||
""",
|
||||
(id, email, dollars)
|
||||
)
|
||||
self.connection.commit()
|
||||
|
||||
def consume_stripe_checkout_session(self, id, dollars):
|
||||
self.cursor.execute("SELECT email, dollars FROM stripe_checkout_sessions WHERE id = %s", (id,))
|
||||
rows = self.cursor.fetchall()
|
||||
if len(rows) > 0:
|
||||
if int(rows[0][1]) != int(dollars):
|
||||
print(f"""
|
||||
Stripe sent us a completed checkout session with a different dollar amount than what we had recorded!!
|
||||
stripe_checkout_session_id: {id}
|
||||
account: {rows[0][0]}
|
||||
Recorded amount: {int(rows[0][1])}
|
||||
Stripe sent: {int(dollars)}
|
||||
""")
|
||||
# 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.connection.commit()
|
||||
return rows[0][0]
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user