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

Commit

Permalink
Honor restofworld for other regions (bug 1143119)
Browse files Browse the repository at this point in the history
When a user tries to pay from a region that the app
does not explicitly support, allow the user to pay
if restofworld payments are accepted.
  • Loading branch information
kumar303 authored and chuckharmston committed Mar 17, 2015
1 parent 39f5697 commit b8258d5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
15 changes: 15 additions & 0 deletions mkt/webpay/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ def test_anon(self):
eq_(res.json,
{'detail': 'Authentication credentials were not provided.'})

def test_unsupported_region(self):
with patch('mkt.webapps.models.Webapp.get_price_region_ids') as r:
# Make this app support the wrong region and disable worldwide.
r.return_value = [mkt.regions.CHN.id]
res = self._post()
eq_(res.status_code, 403)
eq_(res.json, {'reason': 'Payments are restricted for this region'})

def test_unsupported_region_but_worldwide_allowed(self):
with patch('mkt.webapps.models.Webapp.get_price_region_ids') as r:
# Make this app support the wrong region but enable worldwide.
r.return_value = [mkt.regions.CHN.id, mkt.regions.RESTOFWORLD.id]
res = self._post()
eq_(res.status_code, 201)

def test_get_jwt(self, client=None, extra_headers=None):
res = self._post(client=client, extra_headers=extra_headers)
eq_(res.status_code, 201, res.content)
Expand Down
18 changes: 13 additions & 5 deletions mkt/webpay/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
RestSharedSecretAuthentication)
from mkt.api.authorization import AllowReadOnly, AnyOf, GroupPermission
from mkt.api.base import CORSMixin, MarketplaceView
from mkt.constants.regions import RESTOFWORLD
from mkt.purchase.models import Contribution
from mkt.receipts.utils import create_inapp_receipt
from mkt.site.mail import send_mail_jinja
Expand Down Expand Up @@ -57,11 +58,18 @@ def post(self, request, *args, **kwargs):
app = form.cleaned_data['app']

region = getattr(request, 'REGION', None)
if region and region.id not in app.get_price_region_ids():
log.info('Region {0} is not in {1}'
.format(region.id, app.get_price_region_ids()))
return Response('Payments are limited and flag not enabled',
status=status.HTTP_403_FORBIDDEN)
if region:
enabled_regions = app.get_price_region_ids()
region_can_purchase = region.id in enabled_regions
restofworld_can_purchase = RESTOFWORLD.id in enabled_regions

if not region_can_purchase and not restofworld_can_purchase:
log.info('Region {0} is not in {1}; '
'restofworld purchases are inactive'
.format(region.id, enabled_regions))
return Response(
{'reason': 'Payments are restricted for this region'},
status=status.HTTP_403_FORBIDDEN)

if app.is_premium() and app.has_purchased(request._request.user):
log.info('Already purchased: {0}'.format(app.pk))
Expand Down

0 comments on commit b8258d5

Please sign in to comment.