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

Commit

Permalink
Merge pull request #75 from kumar303/disable
Browse files Browse the repository at this point in the history
Disable real payments, allow sim. (bug 844301)
  • Loading branch information
kumar303 committed Mar 5, 2013
2 parents 5330b84 + 388dfad commit d809fb5
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions settings_test.py
Expand Up @@ -24,3 +24,4 @@
BROWSERID_DOMAIN = 'nowhereatall.org'
BROWSERID_UNVERIFIED_ISSUER = BROWSERID_DOMAIN
BROWSERID_VERIFICATION_URL = 'https://%s/verify' % BROWSERID_DOMAIN
ONLY_SIMULATIONS = False
2 changes: 1 addition & 1 deletion webpay/base/templates/error.html
@@ -1,7 +1,7 @@
{% extends "base.html" %}

{% block content %}
<h1>{{ _('Error') }}</h1>
<h2>{{ _('Error') }}</h2>
<p class="centered">{{ error }}</p>
<p class="centered">
<a class="button cancel-button" href="#">
Expand Down
15 changes: 15 additions & 0 deletions webpay/pay/tests/test_views.py
Expand Up @@ -200,6 +200,11 @@ def test_not_debug(self):
# Output should show a generic error message without details.
self.assertContains(res, 'There was an error', status_code=400)

def test_only_simulations(self):
with self.settings(ONLY_SIMULATIONS=True):
res = self.get(self.request())
self.assertContains(res, 'temporarily disabled', status_code=503)

@mock.patch('webpay.pay.views.tasks.start_pay')
def test_begin_simulation(self, start_pay):
payjwt = self.payload()
Expand All @@ -212,6 +217,16 @@ def test_begin_simulation(self, start_pay):
assert not start_pay.delay.called, (
'start_pay should not be called when simulating')

@mock.patch('webpay.pay.views.tasks.start_pay')
def test_begin_simulation_when_payments_disabled(self, start_pay):
payjwt = self.payload()
payjwt['request']['simulate'] = {'result': 'postback'}
payload = self.request(payload=payjwt)
with self.settings(ONLY_SIMULATIONS=True):
res = self.get(payload)
eq_(res.status_code, 200)
eq_(self.client.session['is_simulation'], True)

def test_unknown_simulation(self):
payjwt = self.payload()
payjwt['request']['simulate'] = {'result': '<script>alert()</script>'}
Expand Down
7 changes: 7 additions & 0 deletions webpay/pay/views.py
Expand Up @@ -36,6 +36,13 @@ def process_pay_req(request):
return _error(request, msg=form.errors.as_text(),
is_simulation=form.is_simulation)

if settings.ONLY_SIMULATIONS and not form.is_simulation:
# Real payments are currently disabled.
# Only simulated payments are allowed.
return render(request, 'error.html',
{'error': _('Payments are temporarily disabled.')},
status=503)

try:
pay_req = verify_jwt(
form.cleaned_data['req'],
Expand Down
4 changes: 4 additions & 0 deletions webpay/settings/base.py
Expand Up @@ -272,3 +272,7 @@
# a JWT. You can create/enter PINs but it won't let you get very far beyond
# that.
TEST_PIN_UI = False

# If True, only simulated payments can be processed. All other requests will
# result in an error.
ONLY_SIMULATIONS = False
3 changes: 3 additions & 0 deletions webpay/settings/sites/prod/settings_base.py
Expand Up @@ -84,3 +84,6 @@
BANGO_BASE_URL = 'https://mozilla.bango.net'
BANGO_PAY_URL = BANGO_BASE_URL + '/mozpayments/?bcid=%s'
BANGO_LOGOUT_URL = '%s/mozpayments/logout/' % BANGO_BASE_URL

# Temporarily only accept simulations while we work to get Bango online.
ONLY_SIMULATIONS = True

0 comments on commit d809fb5

Please sign in to comment.