forked from 3wordchant/capsul-flask
btcpay generating invoices and payments can be invalidated
This commit is contained in:
@ -146,38 +146,38 @@ class DBModel:
|
||||
|
||||
def list_payments_for_account(self, email):
|
||||
self.cursor.execute("""
|
||||
SELECT payments.dollars, payments.created
|
||||
SELECT dollars, invalidated, created
|
||||
FROM payments WHERE payments.email = %s""",
|
||||
(email, )
|
||||
)
|
||||
return list(map(
|
||||
lambda x: dict(dollars=x[0], created=x[1]),
|
||||
lambda x: dict(dollars=x[0], invalidated=x[1], created=x[2]),
|
||||
self.cursor.fetchall()
|
||||
))
|
||||
|
||||
def create_stripe_checkout_session(self, id, email, dollars):
|
||||
def create_payment_session(self, payment_type, id, email, dollars):
|
||||
self.cursor.execute("""
|
||||
INSERT INTO stripe_checkout_sessions (id, email, dollars)
|
||||
VALUES (%s, %s, %s)
|
||||
INSERT INTO payment_sessions (id, type, email, dollars)
|
||||
VALUES (%s, %s, %s, %s)
|
||||
""",
|
||||
(id, email, dollars)
|
||||
(id, payment_type, 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,))
|
||||
def consume_payment_session(self, payment_type, id, dollars):
|
||||
self.cursor.execute("SELECT email, dollars FROM payment_sessions WHERE id = %s AND type = %s", (id, payment_type))
|
||||
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}
|
||||
{payment_type} gave us a completed payment session with a different dollar amount than what we had recorded!!
|
||||
id: {id}
|
||||
account: {rows[0][0]}
|
||||
Recorded amount: {int(rows[0][1])}
|
||||
Stripe sent: {int(dollars)}
|
||||
{payment_type} 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( "DELETE FROM payment_sessions WHERE id = %s AND type = %s", (id, payment_type) )
|
||||
self.cursor.execute( "INSERT INTO payments (email, dollars) VALUES (%s, %s)", (rows[0][0], rows[0][1]) )
|
||||
self.connection.commit()
|
||||
return rows[0][0]
|
||||
|
Reference in New Issue
Block a user