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

Commit

Permalink
Merge pull request #2474 from gittip/final-payout
Browse files Browse the repository at this point in the history
Implement bank payout for cancelation
  • Loading branch information
Changaco committed Jun 6, 2014
2 parents f442c52 + 19eb8b9 commit a87dfe5
Show file tree
Hide file tree
Showing 4 changed files with 323 additions and 7 deletions.
6 changes: 3 additions & 3 deletions gittip/billing/payday.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ def charge(self, participant, amount):
)


def ach_credit(self, ts_start, participant, tips, total):
def ach_credit(self, ts_start, participant, tips, total, minimum_credit=MINIMUM_CREDIT):

# Compute the amount to credit them.
# ==================================
Expand All @@ -594,13 +594,13 @@ def ach_credit(self, ts_start, participant, tips, total):
if amount <= 0:
return # Participant not owed anything.

if amount < MINIMUM_CREDIT:
if amount < minimum_credit:
also_log = ""
if total > 0:
also_log = " ($%s balance - $%s in obligations)"
also_log %= (balance, total)
log("Minimum payout is $%s. %s is only due $%s%s."
% (MINIMUM_CREDIT, participant.username, amount, also_log))
% (minimum_credit, participant.username, amount, also_log))
return # Participant owed too little.

if not is_whitelisted(participant):
Expand Down
42 changes: 40 additions & 2 deletions gittip/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,53 @@ def set_as_claimed(self):
# Canceling
# =========

def cancel(self):
class UnknownDisbursementStrategy(Exception): pass

def cancel(self, disbursement_strategy):
"""Cancel the participant's account.
"""
with self.db.get_cursor() as cursor:
self.clear_tips_receiving(cursor)
self.distribute_balance_as_final_gift(cursor)
if disbursement_strategy == 'bank':
self.withdraw_balance_to_bank_account(cursor)
elif disbursement_strategy == 'upstream':
self.refund_to_patrons(cursor)
elif disbursement_strategy == 'downstream':
self.distribute_balance_as_final_gift(cursor)
else:
raise self.UnknownDisbursementStrategy
return self.archive(cursor)


class NotWhitelisted(Exception): pass
class NoBalancedCustomerHref(Exception): pass

def withdraw_balance_to_bank_account(self, cursor):
if self.is_suspicious in (True, None):
raise self.NotWhitelisted
if self.balanced_customer_href is None:
raise self.NoBalancedCustomerHref

from gittip.billing.payday import Payday
hack = Payday(self.db) # Our payout code is on the Payday object. Rather than
# refactor right now, let's just use it from there.

# Monkey-patch a couple methods, coopting them for callbacks, essentially.
hack.mark_ach_failed = lambda cursor: None
hack.mark_ach_success = lambda cursor, amount, fee: self.set_attributes(balance=0)

hack.ach_credit( ts_start=None # not used
, participant=self
, tips=None # not used
, total=Decimal('0.00') # don't withold anything
, minimum_credit=Decimal('0.00') # send it all
) # XXX Records the exchange using a different cursor. :-/


def refund_balance_to_patrons(self, cursor):
raise NotImplementedError


class NoOneToGiveFinalGiftTo(Exception): pass

def distribute_balance_as_final_gift(self, cursor):
Expand Down
Loading

0 comments on commit a87dfe5

Please sign in to comment.