def payin(self): """The first stage of payday where we charge credit cards and transfer money internally between participants. """ with self.db.get_cursor() as cursor: self.prepare(cursor, self.ts_start) holds = self.create_card_holds(cursor) self.transfer_tips(cursor) self.transfer_takes(cursor, self.ts_start) transfers = cursor.all(""" SELECT * FROM transfers WHERE "timestamp" > %s """, (self.ts_start,)) try: self.settle_card_holds(cursor, holds) self.update_balances(cursor) check_db(cursor) except: # Dump transfers for debugging import csv from time import time with open('%s_transfers.csv' % time(), 'wb') as f: csv.writer(f).writerows(transfers) raise self.take_over_balances() # Clean up leftover functions self.db.run(""" DROP FUNCTION process_take(); DROP FUNCTION process_tip(); DROP FUNCTION settle_tip_graph(); DROP FUNCTION transfer(text, text, numeric, context_type); """)
def payin(self): """The first stage of payday where we charge credit cards and transfer money internally between participants. """ with self.db.get_cursor() as cursor: self.prepare(cursor, self.ts_start) holds = self.create_card_holds(cursor) self.process_payment_instructions(cursor) self.transfer_takes(cursor, self.ts_start) self.process_draws(cursor) payments = cursor.all( """ SELECT * FROM payments WHERE "timestamp" > %s """, (self.ts_start, )) try: self.settle_card_holds(cursor, holds) self.update_balances(cursor) check_db(cursor) except: # Dump payments for debugging import csv from time import time with open('%s_payments.csv' % time(), 'wb') as f: csv.writer(f).writerows(payments) raise self.take_over_balances()
def payin(self): """The first stage of payday where we charge credit cards and transfer money internally between participants. """ with self.db.get_cursor() as cursor: self.prepare(cursor) holds = self.create_card_holds(cursor) self.process_payment_instructions(cursor) self.transfer_takes(cursor, self.ts_start) self.process_draws(cursor) payments = cursor.all(""" SELECT * FROM payments WHERE "timestamp" > %s """, (self.ts_start,)) try: self.settle_card_holds(cursor, holds) self.update_balances(cursor) check_db(cursor) except: # Dump payments for debugging import csv from time import time with open('%s_payments.csv' % time(), 'wb') as f: csv.writer(f).writerows(payments) raise self.take_over_balances()
def main(db=None, *a, **kw): db = db or wireup.db(wireup.env()) clean_db(db) prep_db(db) populate_db(db, *a, **kw) clean_db(db) check_db(db)
def sync_with_balanced(db): """We can get out of sync with Balanced if record_exchange_result was interrupted or wasn't called. This is where we fix that. """ check_db(db) exchanges = db.all(""" SELECT * FROM exchanges WHERE status = 'pre' """) meta_exchange_id = balanced.Transaction.f.meta.exchange_id for e in exchanges: p = Participant.from_username(e.participant) cls = balanced.Debit if e.amount > 0 else balanced.Credit transactions = cls.query.filter(meta_exchange_id == e.id).all() assert len(transactions) < 2 if transactions: t = transactions[0] error = t.failure_reason status = t.status assert (not error) ^ (status == 'failed') record_exchange_result(db, e.id, status, error, p) else: # The exchange didn't happen, remove it db.run("DELETE FROM exchanges WHERE id=%s", (e.id,)) # and restore the participant's balance if it was a credit if e.amount < 0: db.run(""" UPDATE participants SET balance=(balance + %s) WHERE id=%s """, (-e.amount + e.fee, p.id)) check_db(db)
def payin(self): """The first stage of payday where we charge credit cards and transfer money internally between participants. """ with self.db.get_cursor() as cursor: self.prepare(cursor, self.ts_start) holds = self.create_card_holds(cursor) self.transfer_tips(cursor) self.transfer_takes(cursor, self.ts_start) transfers = cursor.all( """ SELECT * FROM transfers WHERE "timestamp" > %s """, (self.ts_start, )) try: self.settle_card_holds(cursor, holds) self.update_balances(cursor) check_db(cursor) except: # Dump transfers for debugging import csv from time import time with open('%s_transfers.csv' % time(), 'wb') as f: csv.writer(f).writerows(transfers) raise self.take_over_balances() # Clean up leftover functions self.db.run(""" DROP FUNCTION process_take(); DROP FUNCTION process_tip(); DROP FUNCTION transfer(text, text, numeric, context_type); """)
def main(db=None, *a, **kw): db = db or _wireup() clean_db(db) prep_db(db) populate_db(db, *a, **kw) clean_db(db) check_db(db)
def main(db=None, *a, **kw): db = db or _wireup() fake_data.clean_db(db) fake_data.prep_db(db) fake_data.populate_db(db, *a, **kw) fake_data.clean_db(db) check_db(db)
def main(): db = wireup.db(wireup.env()) prep_db(db) populate_db(db) clean_db(db) check_db(db)