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

notify users of card charges #3301

Merged
merged 16 commits into from
Apr 16, 2015
Merged

notify users of card charges #3301

merged 16 commits into from
Apr 16, 2015

Conversation

chadwhitacre
Copy link
Contributor

Closes #1124.

TODO

  • wire up variables for email
  • implement text/plain content
  • Settings UI
  • review format of received email and tweak as necessary

@chadwhitacre
Copy link
Contributor Author

@chrisdev @citruspi asked for this ahead of PyCon in 10 days.

@chadwhitacre
Copy link
Contributor Author

That's towards the bottom of gratipay/inside.gratipay.com#111 (comment).

@Changaco
Copy link
Contributor

Changaco commented Apr 8, 2015

Ready for review.

@Changaco
Copy link
Contributor

Changaco commented Apr 8, 2015

Actually, I forgot the settings UI.

@rohitpaulk rohitpaulk removed the Review label Apr 8, 2015
@Changaco Changaco added the Review label Apr 8, 2015
@Changaco
Copy link
Contributor

Changaco commented Apr 8, 2015

UI done, ready for review.

@chadwhitacre
Copy link
Contributor Author

UI seems to work as advertised (clicking persists). Testing email ...

@chadwhitacre
Copy link
Contributor Author

I think I'm seeing that we're defaulting to sending notifications for failures but not successes. I think we should default to sending notifications for both.

@chadwhitacre
Copy link
Contributor Author

No tests for notify_participants?

continue
i = 1 if e.status == 'failed' else 2
p = e.participant
if p.notify_charge & i == 0:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I find this code difficult to read. You mentioned (IRC) wanting to refactor how we're doing notifications. Does this point us in that direction? Are you thinking we'll fold all notifications together into one column that we'll work with via bitmasks? Are you expecting that we'll use bitwise operators with ints? I'd find it easier to comprehend bitwise code if it used 0b00 (Python) and B'00' (Postgres). It'd be even easier if we used constants (e.g., NOTIFY_CHARGE_FAILURE).

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this point us in that direction?

Yes.

Are you thinking we'll fold all notifications together into one column that we'll work with via bitmasks?

No, but that may be a better idea than what I had in mind, I'll see if it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Changaco Can we please not use ints for bitmasks? Too clever for me, sorry. :-(

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 on that. Either don't use them at all, or use abstraction so that we don't have to work with bits directly.

@chadwhitacre
Copy link
Contributor Author

I get the following error from payday, on a db with two users, one tipping the other $10 (credit card attached and is_suspicious=False).

pid-47425 thread-140735152444160 (MainThread) Starting a new payday.
pid-47425 thread-140735152444160 (MainThread) Payday started at 2015-04-08 22:21:03.751296+00:00.
pid-47425 thread-140735152444160 (MainThread) Greetings, program! It's PAYDAY!!!!
pid-47425 thread-140735152444160 (MainThread) Prepared the DB.
pid-47425 thread-4368371712 (Thread-1) Holding 1061 cents ($10.00 + $0.61 fee = $10.61) on Balanced for whit537 ... succeeded.
pid-47425 thread-4368371712 (Thread-9) Captured 1000 cents ($9.41 [rounded up from $2.59] + $0.59 fee = $10.00) on Balanced for whit537
pid-47425 thread-140735152444160 (MainThread) Captured 1 card holds.
pid-47425 thread-140735152444160 (MainThread) Canceled 0 card holds.
pid-47425 thread-140735152444160 (MainThread) Updated the balances of 2 participants.
pid-47425 thread-140735152444160 (MainThread) Starting payout loop.
pid-47425 thread-140735152444160 (MainThread) Did payout for 0 participants.
pid-47425 thread-140735152444160 (MainThread) Checked the DB.
pid-47425 thread-140735152444160 (MainThread) Updated payday stats.
pid-47425 thread-140735152444160 (MainThread) Updated receiving amounts.
pid-47425 thread-140735152444160 (MainThread) Traceback (most recent call last):
pid-47425 thread-140735152444160 (MainThread)   File "/Users/whit537/personal/gratipay/gratipay.com/gratipay/cli.py", line 27, in payday
pid-47425 thread-140735152444160 (MainThread)     Payday.start().run()
pid-47425 thread-140735152444160 (MainThread)   File "/Users/whit537/personal/gratipay/gratipay.com/gratipay/billing/payday.py", line 144, in run
pid-47425 thread-140735152444160 (MainThread)     self.notify_participants()
pid-47425 thread-140735152444160 (MainThread)   File "/Users/whit537/personal/gratipay/gratipay.com/gratipay/billing/payday.py", line 751, in notify_participants
pid-47425 thread-140735152444160 (MainThread)     """, locals())
pid-47425 thread-140735152444160 (MainThread)   File "/Users/whit537/personal/gratipay/gratipay.com/env/lib/python2.7/site-packages/postgres/__init__.py", line 463, in one
pid-47425 thread-140735152444160 (MainThread)     return cursor.one(sql, parameters, default)
pid-47425 thread-140735152444160 (MainThread)   File "/Users/whit537/personal/gratipay/gratipay.com/env/lib/python2.7/site-packages/postgres/cursors.py", line 105, in one
pid-47425 thread-140735152444160 (MainThread)     out = self._some(sql, parameters, lo=0, hi=1)
pid-47425 thread-140735152444160 (MainThread)   File "/Users/whit537/personal/gratipay/gratipay.com/env/lib/python2.7/site-packages/postgres/cursors.py", line 127, in _some
pid-47425 thread-140735152444160 (MainThread)     self.execute(sql, parameters)
pid-47425 thread-140735152444160 (MainThread)   File "/Users/whit537/personal/gratipay/gratipay.com/env/lib/python2.7/site-packages/psycopg2/extras.py", line 288, in execute
pid-47425 thread-140735152444160 (MainThread)     return super(NamedTupleCursor, self).execute(query, vars)
pid-47425 thread-140735152444160 (MainThread) ProgrammingError: subquery in FROM must have an alias
pid-47425 thread-140735152444160 (MainThread) LINE 4:                            FROM ( SELECT DISTINCT ON (tippee...
pid-47425 thread-140735152444160 (MainThread)                                         ^
pid-47425 thread-140735152444160 (MainThread) HINT:  For example, FROM (SELECT ...) [AS] foo.
pid-47425 thread-140735152444160 (MainThread) 

@chadwhitacre
Copy link
Contributor Author

Interesting. Travis shows a failure but it's a js failure, not the failure I'm seeing locally.

@chadwhitacre
Copy link
Contributor Author

I force-pushed a cleaner test. It still fails for me in the way noted above. Let's see about Travis.

@chadwhitacre
Copy link
Contributor Author

There we go, Travis is showing the failure now. Out of time for now.

@Changaco
Copy link
Contributor

Changaco commented Apr 9, 2015

Ready for more review.

@Changaco
Copy link
Contributor

Changaco commented Apr 9, 2015

I think I'm seeing that we're defaulting to sending notifications for failures but not successes. I think we should default to sending notifications for both.

You think the percentage of users who want to receive success notifications is high enough to turn them on by default?

@kaguillera
Copy link
Contributor

+1 For default notifications of success since most site that you use your credit card for sends you a email when they charge you.

@chadwhitacre
Copy link
Contributor Author

Also, my educated guess (haven't verified) is that we have a large number of users that tip a small amount so they get charged once initially and then a second time two months later, after they've forgotten about us. I think it's good practice to notify on success by default so that they're notified of that second charge and it doesn't become something they're confused about a year later.

@Changaco
Copy link
Contributor

Changaco commented Apr 9, 2015

Default changed.

@chadwhitacre
Copy link
Contributor Author

Tests pass for me now.

@chadwhitacre
Copy link
Contributor Author

Email received:

screen shot 2015-04-13 at 5 03 54 pm

@chadwhitacre
Copy link
Contributor Author

Needs some tweaks ...

@chadwhitacre
Copy link
Contributor Author

@Changaco We're trying to pull the failure message from exchanges.note, but that field is null and the error message is in exchange_routes.error. Is the error ending up in the wrong field or are we trying to pull it from the wrong location?

@chadwhitacre
Copy link
Contributor Author

We should link to the receipt for successful charges.

@chadwhitacre
Copy link
Contributor Author

@Changaco Last two things I'm seeing are:

chadwhitacre added a commit that referenced this pull request Apr 16, 2015
@chadwhitacre chadwhitacre merged commit 8a6d93e into master Apr 16, 2015
@chadwhitacre chadwhitacre deleted the charge-notifications branch April 16, 2015 18:45
@chadwhitacre
Copy link
Contributor Author

We'll deal with bitmasks separately, I guess.

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.

Email me whenever you bill my credit card
4 participants