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

sync our database with braintree #3473

wants to merge 18 commits into from

Conversation

chadwhitacre
Copy link
Contributor

Closes #3287. Braintree has received data from Balanced. Now we need to knit the customer records in Braintree with our participants table.

@chadwhitacre chadwhitacre added this to the Balanced shutdown milestone May 21, 2015
@@ -0,0 +1,5 @@
BEGIN;

ALTER TABLE participant ADD COLUMN braintree_id text NOT NULL DEFAULT '';
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a braintree_customer_id field already, is that what you were looking for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, cool. :-)

This was referenced May 27, 2015
@chadwhitacre
Copy link
Contributor Author

I'm seeing a handful of cases where an absorbed account has a balanced_customer_href, and the account that absorbed it has the same one.

@chadwhitacre
Copy link
Contributor Author

I also see the seven customers that Braintree knows about that we don't.

, ("/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.

@chadwhitacre
Copy link
Contributor Author

We want a clean slate with Braintree going forward. We want exactly one Braintree customer per open account. I'm not sure yet about how cards should sync up.

@rohitpaulk
Copy link
Contributor

We want exactly one Braintree customer per open account.

That's something I can handle next week as cleanup. As of now, we should be focusing on linking whatever braintree_customer_ids we have for people with valid cards.

@rohitpaulk
Copy link
Contributor

One case where I see us having two braintree customers for one open account is #3473 (comment). It's safe to delete the 'migrated' customer.

@chadwhitacre
Copy link
Contributor Author

I'm seeing a number of closed and a few suspicious accounts with a balanced_customer_href that matches customer_id in the Braintree import log.

@chadwhitacre
Copy link
Contributor Author

I also want to see which cards are status: removed at Balanced. :-(

@chadwhitacre
Copy link
Contributor Author

It would be Bad™ if we started charging users on cards that they had disconnected. Kind of a wtf to even have those in the export from Balanced, or at least not being invalidated at Braintree, if indeed that is what is happening.

@chadwhitacre
Copy link
Contributor Author

Results using 8c34500 with the import log and the production database:

status participants
ready 4,201
closed 247
suspicious 55
archived 48
already migrated 9
unknown 7
failed 0
total 4,567

@chadwhitacre
Copy link
Contributor Author

So now for each card_id in the ready set, we want to find out the status of that card on Balanced.

@chadwhitacre
Copy link
Contributor Author

I'm not seeing status in the Balanced API, either the docs or live.

@chadwhitacre
Copy link
Contributor Author

The closest I'm seeing is can_{credit,debit}.

@rohitpaulk
Copy link
Contributor

Aren't cards deleted entirely when we call unstore on them?

@chadwhitacre
Copy link
Contributor Author

    status: function() {
        return this.get('can_debit') ? 'active' : 'removed';
    }.property('can_debit')

src

@chadwhitacre
Copy link
Contributor Author

Aren't cards deleted entirely when we call unstore on them?

Is unstore a Balanced or Braintree API? I don't remember it from Balanced.

@chadwhitacre
Copy link
Contributor Author

@chadwhitacre
Copy link
Contributor Author

I just satisfied myself that the SQL in get_participant_from_card_id does work.

@rohitpaulk
Copy link
Contributor

🚀

@chadwhitacre
Copy link
Contributor Author

👀

@chadwhitacre
Copy link
Contributor Author

I'm testing a single sync. Then I'm ready to run it for real!

@chadwhitacre
Copy link
Contributor Author

Okay! I'm seeing participant_id set properly at Braintree, and the braintree_customer_id and exchange route in Gratipay. Ready for lift off ...

@chadwhitacre
Copy link
Contributor Author

Last chance for review ...

@chadwhitacre
Copy link
Contributor Author

/me waits for Travis on principle ...

@chadwhitacre
Copy link
Contributor Author

I'm expecting this script to run for 15 or 20 minutes, since there's more network traffic with the additional API and database calls.

@chadwhitacre
Copy link
Contributor Author

Okay! 🚦

@chadwhitacre
Copy link
Contributor Author

Script started.

@chadwhitacre
Copy link
Contributor Author

Traceback (most recent call last):
  File "/Users/whit537/personal/gratipay/gratipay.com/gratipay/billing/payday.py", line 44, in g
    return func(*a, **kw)
  File "bin/sync-with-braintree.py", line 120, in process_record
    braintree.PaymentMethod.delete(card_id)
  File "/Users/whit537/personal/gratipay/gratipay.com/env/lib/python2.7/site-packages/braintree/payment_method
    return Configuration.gateway().payment_method.delete(payment_method_token)
  File "/Users/whit537/personal/gratipay/gratipay.com/env/lib/python2.7/site-packages/braintree/payment_method
    self.config.http().delete("/payment_methods/any/" + payment_method_token)
  File "/Users/whit537/personal/gratipay/gratipay.com/env/lib/python2.7/site-packages/braintree/util/http.py",
    return self.__http_do("DELETE", path)
  File "/Users/whit537/personal/gratipay/gratipay.com/env/lib/python2.7/site-packages/braintree/util/http.py",
    Http.raise_exception_from_status(status)
  File "/Users/whit537/personal/gratipay/gratipay.com/env/lib/python2.7/site-packages/braintree/util/http.py",
    raise NotFoundError()
NotFoundError

@rohitpaulk
Copy link
Contributor

Hmm, only delete if the card exists? We'll also have to patch up all the other inserts/deletes to not repeat themselves if this wasn't the first record or so.

@chadwhitacre
Copy link
Contributor Author

@rohitpaulk There was only one sync but a few deletes. Fortunately deletes are easier to work around.

@chadwhitacre
Copy link
Contributor Author

Script restarted ...

@chadwhitacre
Copy link
Contributor Author

At the end of this script, whit537 should have 0 cards attached at Braintree, though the customer should still exist.

@chadwhitacre
Copy link
Contributor Author

Down from 26 to 12 so far. :-)

@chadwhitacre
Copy link
Contributor Author

💇

@chadwhitacre
Copy link
Contributor Author

2 left!

@chadwhitacre
Copy link
Contributor Author

Okaaaaaay, more than 20 minutes. 🕝

@chadwhitacre
Copy link
Contributor Author

No more 💳 for whit537.

@chadwhitacre
Copy link
Contributor Author

real    25m32.430s
user    5m18.790s
sys     0m33.644s

@chadwhitacre
Copy link
Contributor Author

So now a Customers & Payment Methods export from Braintree should have 3,619 records, right?

@chadwhitacre
Copy link
Contributor Author

Sigh. 3,618. :-/

Oh well, close enough!

!m @rohitpaulk

@chadwhitacre chadwhitacre deleted the sync-braintree branch May 29, 2015 06:13
@rohitpaulk
Copy link
Contributor

!m @whit537

@chadwhitacre
Copy link
Contributor Author

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

migrate to Braintree
2 participants