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

sync our database with braintree #3473

Closed
wants to merge 18 commits into from
Closed
Changes from 4 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
32 changes: 32 additions & 0 deletions bin/branch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python
from __future__ import print_function

import csv
import sys
from gratipay.wireup import db, env
from gratipay.models.exchange_route import ExchangeRoute


DETAILS = 4
NAME = 7
CUSTOMER_ID = 1
CARD_ID = -1
CHECK = 6
db = db(env())

for row in csv.reader(sys.stdin):
if row[DETAILS] != 'customer':
continue
assert row[CUSTOMER_ID] == row[CHECK], row

customer_id = row[CUSTOMER_ID]
card_id = row[CARD_ID]

p = db.one( "SELECT p.*::participants FROM participants p WHERE balanced_customer_href=%s"
, ("/customers/{}".format(customer_id),)
)

er = ExchangeRoute.insert(p, 'braintree-cc', card_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before we do this, we should check whether a route exists for braintree-cc. If so, the user had updated his card, and we should just leave the participant as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

db.run("UPDATE participants SET braintree_customer_id=%s", (customer_id,))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WHERE 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

;-)

Still commented out tbh.


print("{} -> {} ({}) {}".format(p.balanced_customer_href, customer_id, card_id, p.username))