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

Commit

Permalink
Merge pull request #823 from muffinresearch/require-in-app-for-free-8…
Browse files Browse the repository at this point in the history
…84680

Require in-app payment for free paid (bug 884680)
  • Loading branch information
muffinresearch committed Jun 20, 2013
2 parents 0b268df + e78bbe8 commit bba7ad9
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 11 deletions.
13 changes: 13 additions & 0 deletions media/js/devreg/payments.js
Expand Up @@ -78,11 +78,24 @@ define('payments', [], function() {
var selectedPrice = $this.val() || '';
var apiUrl = format(pricesApiEndpoint, parseInt(selectedPrice, 10));
var disabledRegions = $regions.data('disabledRegions');
var freeWithInAppId = $regions.data('freeWithInappId');

if (currentPrice == selectedPrice) {
return;
}

// If free with in-app is selected then make the 'No' radio disabled
// and hide it and make the allow_inapp a hidden field.
if (selectedPrice == freeWithInAppId) {
$('input[name=allow_inapp][value=True]').attr('type', 'hidden');
$('input[name=allow_inapp][value=False]').prop('disabled', true)
.parent('label').hide();
} else {
$('input[name=allow_inapp][value=True]').attr('type', 'radio');
$('input[name=allow_inapp][value=False]').prop('disabled', false)
.parent('label').show();
}

// Clear out existing price data.
$regions.find('.local-retail').text('');

Expand Down
10 changes: 8 additions & 2 deletions mkt/developers/forms_payments.py
Expand Up @@ -108,7 +108,8 @@ def group_tier_choices(self):
choice = (price.pk, unicode(price))
# Special case zero priced tier.
if price.price == Decimal('0.00'):
price_choices.append((price.pk, _lazy('Free')))
price_choices.append((price.pk,
_lazy('Free with in-app payments')))
# Tiers that can only be operator billed.
elif price.method == PAYMENT_METHOD_OPERATOR:
operator_billed.append(choice)
Expand All @@ -128,7 +129,7 @@ def group_tier_choices(self):
card_billed))
if card_and_operator_billed:
price_choices.append(
(_lazy('Supports carrier billing and credit cards'),
(_lazy('Supports all billing methods'),
card_and_operator_billed))

return price_choices
Expand Down Expand Up @@ -200,6 +201,11 @@ def clean_price(self):
raise ValidationError(
self.fields['price'].error_messages['invalid_choice'])

if (price and price.price == Decimal('0.00')
and self.cleaned_data.get('allow_inapp') != 'True'):
raise ValidationError(_('If app is Free, '
'in-app payments must be enabled'))

return price

def save(self):
Expand Down
7 changes: 4 additions & 3 deletions mkt/developers/templates/developers/payments/premium.html
Expand Up @@ -175,7 +175,8 @@ <h2>{{ _('Prices and countries') }}</h2>
<td colspan="2" class="region-container">
<div class="checkbox-choices regions"
data-disabled-regions="{{ region_form.disabled_regions|json }}"
data-pricelist-api-url="{{ api_pricelist_url }}">
data-pricelist-api-url="{{ api_pricelist_url }}"
data-free-with-inapp-id="{{ free_with_in_app_id }}">
{{ region_form.regions.errors }}
<table>
<thead>
Expand All @@ -190,8 +191,8 @@ <h2>{{ _('Prices and countries') }}</h2>
<td>
<label class="disabled">
<input type="checkbox" disabled
{% if value in region_form.initial.regions %}checked{% endif %}
name="regions" value="{{ value }}" />{{ text }}</label>
{%- if value in region_form.initial.regions %} checked {% endif -%}
name="regions" value="{{ value }}">{{ text }}</label>
</td>
<td><span class="local-retail"></span></td>
</tr>
Expand Down
14 changes: 14 additions & 0 deletions mkt/developers/tests/test_forms_payments.py
Expand Up @@ -61,6 +61,20 @@ def test_free_to_premium_pending(self):
form.save()
eq_(RereviewQueue.objects.count(), 0)

def test_free_with_in_app_requires_in_app(self):
self.make_premium(self.addon)
price = Price.objects.create(price='0.00')
self.platforms.update(price=price.pk, allow_inapp='False')
form = forms_payments.PremiumForm(self.platforms, **self.kwargs)
assert not form.is_valid()

def test_paid_free_with_in_app(self):
self.make_premium(self.addon)
price = Price.objects.create(price='0.00')
self.platforms.update(price=price.pk, allow_inapp='True')
form = forms_payments.PremiumForm(self.platforms, **self.kwargs)
assert form.is_valid()

def test_premium_to_free(self):
# Premium to Free is ok for public apps.
self.make_premium(self.addon)
Expand Down
22 changes: 16 additions & 6 deletions mkt/developers/tests/test_views_payments.py
Expand Up @@ -281,15 +281,25 @@ def test_check_api_url_in_context(self):

def test_regions_display_free(self):
self.webapp.update(premium_type=amo.ADDON_FREE)
r = self.client.get(self.url)
eq_(len(pq(r.content)('#regions-island')), 1),
eq_(len(pq(r.content)('#paid-regions-island')), 0),
res = self.client.get(self.url)
pqr = pq(res.content)
eq_(len(pqr('#regions-island')), 1),
eq_(len(pqr('#paid-regions-island')), 0),

def test_regions_display_premium(self):
self.webapp.update(premium_type=amo.ADDON_PREMIUM)
r = self.client.get(self.url)
eq_(len(pq(r.content)('#regions-island')), 0),
eq_(len(pq(r.content)('#paid-regions-island')), 1),
res = self.client.get(self.url)
pqr = pq(res.content)
eq_(len(pqr('#regions-island')), 0),
eq_(len(pqr('#paid-regions-island')), 1),

def test_free_with_in_app_tier_id_in_context(self):
free_tier = Price.objects.create(price='0.00')
self.webapp.update(premium_type=amo.ADDON_PREMIUM)
res = self.client.get(self.url)
pqr = pq(res.content)
eq_(len(pqr('.regions[data-free-with-inapp-id]')), 1),
eq_(int(pqr('.regions').attr('data-free-with-inapp-id')), free_tier.pk)

def test_premium_in_app_passes(self):
self.webapp.update(premium_type=amo.ADDON_FREE)
Expand Down
8 changes: 8 additions & 0 deletions mkt/developers/views_payments.py
Expand Up @@ -22,6 +22,7 @@
from lib.crypto import generate_key
from lib.pay_server import client

from market.models import Price
from mkt.constants import DEVICE_LOOKUP
from mkt.developers.decorators import dev_required
from mkt.developers.models import (AddonPaymentAccount, PaymentAccount,
Expand Down Expand Up @@ -118,10 +119,17 @@ def payments(request, addon_id, addon, webapp=False):
[('android-mobile', True), ('android-tablet', True),
('desktop', True), ('firefoxos', False)]))

try:
free_with_in_app_id = Price.objects.get(price='0.00',
active=True).pk
except Price.DoesNotExist:
free_with_in_app_id = ''

return jingo.render(
request, 'developers/payments/premium.html',
{'addon': addon, 'webapp': webapp, 'premium': addon.premium,
'form': premium_form, 'upsell_form': upsell_form,
'free_with_in_app_id': free_with_in_app_id,
'region_form': region_form,
'DEVICE_LOOKUP': DEVICE_LOOKUP,
'is_paid': addon.premium_type in amo.ADDON_PREMIUMS,
Expand Down

0 comments on commit bba7ad9

Please sign in to comment.