From fc5cd4382d7bb44d9cee0b8a47342d155edcc53d Mon Sep 17 00:00:00 2001 From: Changaco Date: Sat, 6 Sep 2014 18:52:23 +0200 Subject: [PATCH] record credit card failures in the DB (closes #364) --- gratipay/billing/exchanges.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/gratipay/billing/exchanges.py b/gratipay/billing/exchanges.py index c7e591cf82..945e489e2e 100644 --- a/gratipay/billing/exchanges.py +++ b/gratipay/billing/exchanges.py @@ -194,7 +194,7 @@ def create_card_hold(db, participant, amount): except Exception as e: error = repr_exception(e) log(msg + "failed: %s" % error) - propagate_exchange(db, participant, 'bill', error, 0) + record_exchange(db, 'bill', amount, fee, participant, 'failed', error) return hold, error @@ -264,7 +264,7 @@ def _prep_hit(unrounded): return cents, amount_str, upcharged, fee -def record_exchange(db, kind, amount, fee, participant, status): +def record_exchange(db, kind, amount, fee, participant, status, error=None): """Given a Bunch of Stuff, return None. Records in the exchanges table have these characteristics: @@ -287,7 +287,9 @@ def record_exchange(db, kind, amount, fee, participant, status): RETURNING id """, (amount, fee, participant.username, status)) - if amount < 0: + if status == 'failed': + propagate_exchange(cursor, participant, kind, error, 0) + elif amount < 0: amount -= fee propagate_exchange(cursor, participant, kind, '', amount)