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

Commit

Permalink
Modify payday to allow transfers for maybes (#354)
Browse files Browse the repository at this point in the history
We're going to allow intra-Gittip transfers for people with
is_suspicious=NULL. The thing we're restricting to is_suspicious=false
is exchanging money with the outside world (credit card and bank
deposit).
  • Loading branch information
chadwhitacre committed Nov 8, 2012
1 parent 0191be6 commit b8fd8ef
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
17 changes: 10 additions & 7 deletions gittip/billing/payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ def skim_credit(amount):

def whitelist(participant):
"""Given a dict, return bool, possibly logging.
We only perform credit card charges and bank deposits for whitelisted
participants. We don't even include is_suspicious participants in the
initial SELECT, so we should never see one here.
"""
if participant['is_suspicious'] is True:
log("SUSPICIOUS: %s" % participant['id'])
return False
elif participant['is_suspicious'] is None:
assert participant['is_suspicious'] is not True, participant['id']
if participant['is_suspicious'] is None:
log("UNREVIEWED: %s" % participant['id'])
return False
return True
Expand Down Expand Up @@ -204,6 +207,7 @@ def get_participants(self, ts_start):
FROM participants
WHERE claimed_time IS NOT NULL
AND claimed_time < %s
AND is_suspicious IS NOT true
ORDER BY claimed_time ASC
"""
participants = self.db.fetchall(PARTICIPANTS, (ts_start,))
Expand All @@ -219,8 +223,7 @@ def payin(self, ts_start, participants):
for i, (participant, tips, total) in enumerate(participants, start=1):
if i % 100 == 0:
log("Payin done for %d participants." % i)
if whitelist(participant):
self.charge_and_or_transfer(ts_start, participant, tips, total)
self.charge_and_or_transfer(ts_start, participant, tips, total)
log("Did payin for %d participants." % i)


Expand All @@ -245,7 +248,7 @@ def charge_and_or_transfer(self, ts_start, participant, tips, total):
"""
short = total - participant['balance']
if short > 0:
if short > 0 and whitelist(participant):

# The participant's Gittip account is short the amount needed to
# fund all their tips. Let's try pulling in money from their credit
Expand Down
44 changes: 25 additions & 19 deletions tests/test_billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,33 +703,39 @@ def _get_payday(self):
'''
return self.db.fetchone(SELECT_PAYDAY)

@staticmethod
def genparticipants():
for i in range(100):
yield { 'is_suspicious': False
, 'id': 'something'
, 'balance': Decimal('0.00')
, 'balanced_account_uri': ''
, 'stripe_customer_id': ''
}, [], Decimal('2.00')
yield { 'is_suspicious': None
, 'id': 'something'
, 'balance': Decimal('0.00')
, 'balanced_account_uri': ''
, 'stripe_customer_id': ''
}, [], Decimal('2.00')

@mock.patch('gittip.billing.payday.log')
@mock.patch('gittip.billing.payday.Payday.charge_and_or_transfer')
def test_payin(self, charge_and_or_transfer, log):
def participants():
for i in range(100):
yield {'is_suspicious': False, 'id': 'something'}, [], None
yield {'is_suspicious': True, 'id': 'something'}, [], None
yield {'is_suspicious': None, 'id': 'something'}, [], None
@mock.patch('gittip.billing.payday.Payday.charge')
@mock.patch('gittip.billing.payday.Payday.tip')
def test_payin(self, tip, charge, log):
start = mock.Mock()
self.payday.payin(start, participants())

self.assertEqual(log.call_count, 5)
self.assertEqual(charge_and_or_transfer.call_count, 100)
self.assertTrue(charge_and_or_transfer.called_with(start))
self.payday.payin(start, self.genparticipants())
self.assertEqual(log.call_count, 4)
self.assertEqual(charge.call_count, 100)
self.assertTrue(charge.called_with(start))

@mock.patch('gittip.billing.payday.log')
@mock.patch('gittip.billing.payday.Payday.ach_credit')
def test_payout(self, ach_credit, log):
def participants():
for i in range(100):
yield {'is_suspicious': False, 'id': 'something'}, [], None
yield {'is_suspicious': True, 'id': 'something'}, [], None
yield {'is_suspicious': None, 'id': 'something'}, [], None
start = mock.Mock()
self.payday.payout(start, participants())
self.payday.payout(start, self.genparticipants())

self.assertEqual(log.call_count, 5)
self.assertEqual(log.call_count, 4)
self.assertEqual(ach_credit.call_count, 100)
self.assertTrue(ach_credit.called_with(start))

Expand Down

0 comments on commit b8fd8ef

Please sign in to comment.