Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Record credit card failures in the DB #3011

Merged
merged 3 commits into from
Dec 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions gratipay/billing/exchanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions tests/py/test_billing_exchanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ def test_create_card_hold_failure(self, Customer):
hold, error = create_card_hold(self.db, self.janet, D('1.00'))
assert hold is None
assert error == "Foobar()"
exchange = self.db.one("SELECT * FROM exchanges")
assert exchange
assert exchange.amount
assert exchange.status == 'failed'
janet = Participant.from_id(self.janet.id)
assert self.janet.last_bill_result == 'Foobar()'
assert self.janet.balance == janet.balance == 0

def test_create_card_hold_success(self):
hold, error = create_card_hold(self.db, self.janet, D('1.00'))
Expand Down