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

Payday rewrite, part 5 #2579

Merged
merged 98 commits into from
Aug 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
ce91e7e
use temporary tables instead of making lots of expensive queries
Changaco Jun 20, 2014
ba6f4f7
replace `get_tips_and_total()` and `get_takes()`
Changaco May 18, 2014
466eb46
remove unused arguments
Changaco Jun 21, 2014
d2d2009
factor record_charge and record_credit
Changaco Jun 20, 2014
e092267
remove monkey-patching
Changaco Jun 21, 2014
645c41a
rename argument
Changaco Jun 21, 2014
60ab724
move exceptions from withdraw_balance_to_bank_account to ach_credit
Changaco Jun 21, 2014
fd5176c
use the same exceptions in charge()
Changaco Jun 22, 2014
59a65b4
create new module gittip.billing.exchanges
Changaco Jun 22, 2014
d2345c3
update and move tests
Changaco Jun 22, 2014
19e8a54
update test fixtures
Changaco Jun 22, 2014
98d5ed7
modify Payday.start() to be a class method
Changaco Jun 22, 2014
e77c1b8
update tests
Changaco Jun 22, 2014
0b736b0
move constructor to the top
Changaco Jun 23, 2014
ee23156
implement creating and capturing a card hold
Changaco Jun 8, 2014
7b1db71
modify DB self checks to work on cursors
Changaco Jun 19, 2014
69c06c8
we want to be able to run that check during payday
Changaco Jun 19, 2014
7031932
update comments
Changaco Jun 18, 2014
9a16cc4
add a `stage` column to the `paydays` table
Changaco Jun 23, 2014
6570951
rewrite the payin loop in SQL
Changaco Jun 24, 2014
9a43793
after a crash don't rerun the stages that were successfully completed
Changaco Jun 24, 2014
064fae3
add some log messages
Changaco Jun 24, 2014
cca5cd2
run a DB check at the end of the payout loop
Changaco Jun 24, 2014
34d5d00
drop the `pending` column
Changaco Jun 26, 2014
91f7bb8
update tests
Changaco Jun 26, 2014
336d9d6
improve test coverage of gittip.billing.exchanges
Changaco Jun 26, 2014
2936f1a
remove PaydayHarness class
Changaco Jul 14, 2014
9ca940c
remove a log message
Changaco Jul 15, 2014
f6e0868
trick the coverage measurement
Changaco Jul 15, 2014
623f594
upgrade balanced
Changaco Jul 15, 2014
3b5ed71
100% test coverage for gittip.billing.payday
Changaco Jul 15, 2014
be2ffee
reduce the number of Balanced API requests
Changaco Jul 16, 2014
70336b3
fix test
Changaco Jul 16, 2014
23733eb
make participant IDs stable across test runs
Changaco Jul 16, 2014
74633e4
update test fixtures
Changaco Jul 15, 2014
9fb5797
failing test for #916
Changaco Jul 16, 2014
ac1decd
don't transfer tips to participants who don't want to receive them
Changaco Jul 16, 2014
618a38b
small refactor
Changaco Jul 26, 2014
b0fd116
update balance *before* a withdrawal
Changaco Jul 25, 2014
06d66e0
update DB self check
Changaco Jul 25, 2014
8fd9a11
update tests
Changaco Jul 25, 2014
0fe101e
sync with Balanced before starting payday (fixes #213)
Changaco Jul 28, 2014
8d36bfb
add tests for `sync_with_balanced()`
Changaco Jul 28, 2014
d14bbaf
add test fixture
Changaco Jul 29, 2014
2f44b90
failing test for #1853
Changaco Jul 29, 2014
82b1012
fix #1853
Changaco Jul 29, 2014
b6a55ad
fix missing argument
Changaco Jul 30, 2014
606ee2e
Document the call structure of Payday.run
chadwhitacre Jul 30, 2014
0dad838
fix query to exclude participants who aren't whitelisted
Changaco Jul 30, 2014
772b5b3
Fix log message at end of payday script
chadwhitacre Jul 30, 2014
e4a198a
remove the `database_maxconn` restriction from `payday()`
Changaco Jul 30, 2014
d20081f
also remove our meddling with `statement_timeout`
Changaco Jul 30, 2014
cd2e901
rewrite query in `payout()` to better filter participants
Changaco Jul 30, 2014
b8c37d7
fix test
Changaco Jul 30, 2014
bcb43bf
improve error message of DB self check
Changaco Jul 31, 2014
8c93e68
add helper function for making exchanges in tests
Changaco Jul 31, 2014
dc85043
check DB before and after `sync_with_balanced()`
Changaco Jul 31, 2014
3bc3b5c
failing test for `sync_with_balanced()`
Changaco Jul 31, 2014
3529329
fix `sync_with_balanced()`
Changaco Jul 31, 2014
0e7a1a3
update test fixture
Changaco Jul 31, 2014
85f2f70
wrap `sync_with_balanced()` in a DB transaction
Changaco Jul 31, 2014
177b6aa
add missing test
Changaco Aug 1, 2014
ea5bc5b
show status of exchanges on history page
Changaco Aug 1, 2014
4f25806
don't rely on the presence of an error message
Changaco Aug 1, 2014
51a4036
failing test for `iter_payday_events()`
Changaco Aug 1, 2014
09c7986
fix `iter_payday_events()`
Changaco Aug 1, 2014
4eadf87
remove unused function
Changaco Aug 1, 2014
90e3780
remove unnecessary and erroneous assertion
Changaco Aug 5, 2014
f8bc65f
dump transfers for debugging when payin fails
Changaco Aug 6, 2014
899c9cb
failing test for null transfers
Changaco Aug 6, 2014
5f4c3a6
don't make null transfers
Changaco Aug 6, 2014
f18f0ae
failing test for negative transfers
Changaco Aug 6, 2014
954ffba
don't make negative transfers
Changaco Aug 6, 2014
d00549a
don't fetch the `Customer` when we don't actually need it
Changaco Aug 6, 2014
2b6ecc0
update tests
Changaco Aug 6, 2014
5f142f0
update test fixtures
Changaco Aug 6, 2014
6e6cc51
add log message for debugging
Changaco Aug 7, 2014
207c7f9
failing test for `transfer_tips()`
Changaco Aug 7, 2014
445c228
fix `transfer_tips()`
Changaco Aug 7, 2014
334f765
replace foreman with honcho
Changaco Aug 7, 2014
445ee78
add `./env/bin` to `$PATH`
Changaco Aug 7, 2014
3d73eb5
refactor
Changaco Aug 7, 2014
a899e57
run payday in the background and tail the log
Changaco Aug 7, 2014
c494868
better error message when exchange fails
Changaco Aug 7, 2014
7c610ff
fix test
Changaco Aug 7, 2014
24db90b
update test to detect another bug
Changaco Aug 7, 2014
8297378
fix `payin()` to flag which participants we actually have card holds for
Changaco Aug 7, 2014
1e0a0a7
fix minor bug in `update_stats()`
Changaco Aug 7, 2014
e8ce300
Let's put the populate-balanced.py script in git
chadwhitacre Aug 7, 2014
1672083
fix `UPDATE` query in `prepare()`
Changaco Aug 8, 2014
b7b6046
failing tests for `NoResultFound()`
Changaco Aug 8, 2014
e952383
get rid of `NoResultFound()`
Changaco Aug 8, 2014
a6d6cff
Update branch.py to work with a cache
chadwhitacre Aug 8, 2014
9a28447
rename SQL tables `pay_*` → `payday_*`
Changaco Aug 9, 2014
f27a952
replace `DROP TABLE IF EXISTS` by `ON COMMIT DROP`
Changaco Aug 9, 2014
4b61dbd
zero out known anomalous tip
Changaco Aug 1, 2014
26ea085
optimize DB check
Changaco Aug 1, 2014
5c42c57
Merge pull request #2610 from gittip/optimize-db-check
chadwhitacre Aug 12, 2014
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
9 changes: 9 additions & 0 deletions balanced.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/customers/CU2AeM9eNm4xOlzMf2giQLSM
/customers/CU2AB9rAnNMIk2WVUYzTM5bO
/customers/CU2AXHbONP7DZ2icdaC2SKod
/customers/CU2C8JIiShKQwRsfx1lApiCN
/customers/CU2CykeO7fm4GdldRFL9gvEF
/customers/CU2CVUDM4bDUxbDiFQdCFrJS
/customers/CU2DhhxA0V2thT9S8ycuMff7
/customers/CU2DJQgKRESgGP12GHikqsla
/customers/CU2E60G2l5ekRRlIQK6CMHch
2 changes: 1 addition & 1 deletion bin/masspay.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def compute_input_csv():
print_rule(88)
total_gross = 0
for participant in participants:
tips, total = participant.get_tips_and_total(for_payday=False)
total = participant.giving + participant.pledging
amount = participant.balance - total
if amount < 0.50:
# Minimum payout of 50 cents. I think that otherwise PayPal upcharges to a penny.
Expand Down
127 changes: 127 additions & 0 deletions branch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
"""Populate a Balanced test marketplace per a db.
"""
import balanced
from gittip import wireup
from gittip.billing.exchanges import customer_from_href


print "Wiring up ..."

env = wireup.env()
wireup.billing(env)
db = wireup.db(env)


try:
cache = open('balanced.cache').read().splitlines()
import pdb; pdb.set_trace()
print "Populating Balanced from cache ..."

no_card_no_bank = customer_from_href(cache[0])
no_card_good_bank = customer_from_href(cache[1])
no_card_bad_bank = customer_from_href(cache[2])
good_card_no_bank = customer_from_href(cache[3])
good_card_good_bank = customer_from_href(cache[4])
good_card_bad_bank = customer_from_href(cache[5])
bad_card_no_bank = customer_from_href(cache[6])
bad_card_good_bank = customer_from_href(cache[7])
bad_card_bad_bank = customer_from_href(cache[8])

except IOError:
print "Populating Balanced ..."

no_card_no_bank = balanced.Customer(email='[email protected]').save()
no_card_good_bank = balanced.Customer(email='[email protected]').save()
no_card_bad_bank = balanced.Customer(email='[email protected]').save()
good_card_no_bank = balanced.Customer(email='[email protected]').save()
good_card_good_bank = balanced.Customer(email='[email protected]').save()
good_card_bad_bank = balanced.Customer(email='[email protected]').save()
bad_card_no_bank = balanced.Customer(email='[email protected]').save()
bad_card_good_bank = balanced.Customer(email='[email protected]').save()
bad_card_bad_bank = balanced.Customer(email='[email protected]').save()


# https://docs.balancedpayments.com/1.1/overview/resources/#test-credit-card-numbers
good_card = lambda: balanced.Card( number="4111111111111111"
, expiration_month="12"
, expiration_year="2015").save()
bad_card = lambda: balanced.Card( number="4444444444444448"
, expiration_month="12"
, expiration_year="2015").save()

# https://docs.balancedpayments.com/1.1/overview/resources/#test-bank-account-numbers
good_bank = lambda: balanced.BankAccount( account_number="9900000002"
, routing_number="021000021"
, name="Foo").save()
bad_bank = lambda: balanced.BankAccount( account_number="9900000004"
, routing_number="021000021"
, name="Foo").save()

good_card().associate_to_customer(good_card_no_bank)
good_card().associate_to_customer(good_card_good_bank)
good_card().associate_to_customer(good_card_bad_bank)

bad_card().associate_to_customer(bad_card_no_bank)
bad_card().associate_to_customer(bad_card_good_bank)
bad_card().associate_to_customer(bad_card_bad_bank)

good_bank().associate_to_customer(no_card_good_bank)
good_bank().associate_to_customer(good_card_good_bank)
good_bank().associate_to_customer(bad_card_good_bank)

bad_bank().associate_to_customer(no_card_bad_bank)
bad_bank().associate_to_customer(good_card_bad_bank)
bad_bank().associate_to_customer(bad_card_bad_bank)

customers = [ no_card_no_bank
, no_card_good_bank
, no_card_bad_bank
, good_card_no_bank
, good_card_good_bank
, good_card_bad_bank
, bad_card_no_bank
, bad_card_good_bank
, bad_card_bad_bank
]
open('balanced.cache', 'w+').write('\n'.join([customer.href for customer in customers]))


print "Updating DB ..."

participants = db.all("SELECT p.*::participants from participants p "
"WHERE balanced_customer_href IS NOT NULL")

for participant in participants:

customer = None
card = participant.last_bill_result
bank = participant.last_ach_result

if card is None:
if bank is None:
customer = no_card_no_bank
elif bank == '':
customer = no_card_good_bank
elif bank > '':
customer = no_card_bad_bank
elif card == '':
if bank is None:
customer = good_card_no_bank
elif bank == '':
customer = good_card_good_bank
elif bank > '':
customer = good_card_bad_bank
elif card > '':
if bank is None:
customer = bad_card_no_bank
elif bank == '':
customer = bad_card_good_bank
elif bank > '':
customer = bad_card_bad_bank

print customer.href

db.run( "UPDATE participants SET balanced_customer_href=%s WHERE id=%s"
, (customer.href, participant.id))

print len(participants)
19 changes: 19 additions & 0 deletions branch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
BEGIN;

ALTER TABLE paydays ADD COLUMN stage integer DEFAULT 0;
ALTER TABLE participants DROP COLUMN pending;

CREATE TYPE exchange_status AS ENUM ('pre', 'pending', 'failed', 'succeeded');
ALTER TABLE exchanges ADD COLUMN status exchange_status;

UPDATE participants
SET last_ach_result = NULL
WHERE last_ach_result = 'NoResultFound()';
UPDATE participants
SET last_bill_result = NULL
WHERE last_bill_result = 'NoResultFound()';

INSERT INTO tips (ctime, tipper, tippee, amount)
SELECT ctime, tipper, tippee, 0 FROM tips WHERE id = 46266;

END;
Loading