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

Commit

Permalink
Stop user from restarting a completed/failed transaction (bug 829750)
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithan committed Jan 28, 2013
1 parent aa0c318 commit f22d4ca
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/solitude/constants.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
STATUS_COMPLETED = 1 STATUS_COMPLETED = 1
STATUS_CHECKED = 2 STATUS_CHECKED = 2
STATUS_RECEIVED = 3 STATUS_RECEIVED = 3
STATUS_FAILED = 4
STATUS_CANCELLED = 5

STATUS_ENDED = (STATUS_COMPLETED, STATUS_FAILED, STATUS_CANCELLED)
15 changes: 15 additions & 0 deletions webpay/pay/tests/test_views.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -335,6 +335,21 @@ def test_start_not_ready(self, get_transaction):
eq_(data['url'], None) eq_(data['url'], None)
eq_(data['status'], constants.STATUS_RECEIVED) eq_(data['status'], constants.STATUS_RECEIVED)


def wait_ended_transaction(self, get_transaction, status):
with self.settings(VERBOSE_LOGGING=True):
get_transaction.return_value = {
'status': status,
'uid_pay': 123,
}
res = self.client.get(self.wait)
self.assertContains(res,
'Transaction has already ended.',
status_code=400)

def test_wait_ended_transaction(self, get_transaction):
for status in constants.STATUS_ENDED:
self.wait_ended_transaction(get_transaction, status)

def test_wait(self, get_transaction): def test_wait(self, get_transaction):
res = self.client.get(self.wait) res = self.client.get(self.wait)
eq_(res.status_code, 200) eq_(res.status_code, 200)
Expand Down
8 changes: 5 additions & 3 deletions webpay/pay/views.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ def wait_to_start(request):
trans = solitude.get_transaction(request.session['trans_id']) trans = solitude.get_transaction(request.session['trans_id'])
except ValueError: except ValueError:
trans = {'status': None} trans = {'status': None}

if trans['status'] in constants.STATUS_ENDED:
log.exception('Attempt to restart finished transaction.')
return _error(request, msg=_('Transaction has already ended.'))

if trans['status'] == constants.STATUS_PENDING: if trans['status'] == constants.STATUS_PENDING:
# The transaction is ready; no need to wait for it. # The transaction is ready; no need to wait for it.
return http.HttpResponseRedirect( return http.HttpResponseRedirect(
Expand All @@ -160,7 +165,4 @@ def trans_start_url(request):
data = {'url': None, 'status': trans['status']} data = {'url': None, 'status': trans['status']}
if trans['status'] == constants.STATUS_PENDING: if trans['status'] == constants.STATUS_PENDING:
data['url'] = settings.BANGO_PAY_URL % trans['uid_pay'] data['url'] = settings.BANGO_PAY_URL % trans['uid_pay']
# TODO(Wraithan): We should catch if a user is trying to restart an expired
# or completed transaction. (bug 829750).
# This will timeout in the client until then.
return data return data

0 comments on commit f22d4ca

Please sign in to comment.