From f46ba0e3737f500877ae9fde0e71c74f06381836 Mon Sep 17 00:00:00 2001 From: Stuart Colville Date: Thu, 20 Jun 2013 16:31:14 +0000 Subject: [PATCH] Show price/method data for all available payment regions (bug 884443) --- media/js/devreg/payments.js | 61 +++++++++++-------- .../developers/payments/premium.html | 5 +- mkt/developers/tests/test_views_payments.py | 12 +++- mkt/developers/views_payments.py | 10 ++- 4 files changed, 59 insertions(+), 29 deletions(-) diff --git a/media/js/devreg/payments.js b/media/js/devreg/payments.js index 2de32ed649..5c073ce773 100644 --- a/media/js/devreg/payments.js +++ b/media/js/devreg/payments.js @@ -2,8 +2,13 @@ define('payments', [], function() { 'use strict'; var currentPrice; - var $regions = $('.regions'); + var $regions = $('#region-list'); var $regionsIsland = $('#regions'); + + var apiErrorMsg = $regions.data('apiErrorMsg'); + var disabledRegions = $regions.data('disabledRegions'); + var freeWithInAppId = $regions.data('freeWithInappId'); + var paymentMethods = $regions.data('paymentMethods') || {}; var pricesApiEndpoint = $regions.data('pricelistApiUrl') + '{0}/'; function getOverlay(opts) { @@ -77,29 +82,24 @@ define('payments', [], function() { /*jshint validthis:true */ var $this = $(this); var selectedPrice = $this.val() || ''; - var apiUrl = format(pricesApiEndpoint, parseInt(selectedPrice, 10)); - var disabledRegions = $regions.data('disabledRegions'); - var freeWithInAppId = $regions.data('freeWithInappId'); - var apiErrorMsg = $regions.data('apiErrorMsg'); + var apiUrl = format(pricesApiEndpoint, +selectedPrice); 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 free with in-app is selected, check "Yes" then make the 'No' radio + // disabled and hide it. if (selectedPrice == freeWithInAppId) { - $('input[name=allow_inapp][value=True]').attr('type', 'hidden'); + $('input[name=allow_inapp][value=True]').prop('checked', true); $('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(''); $.ajax({ url: apiUrl, @@ -114,25 +114,41 @@ define('payments', [], function() { for (var i=0, j=prices.length; i -1) { continue; } // Enable checkboxes for those that we have price info for. $chkbox.prop('disabled', false) - .parent('label').removeClass('disabled') - .closest('tr').find('.local-retail') - .text(price.price +' '+ price.currency) - .toggle($chkbox.prop('checked')); + .closest('label').removeClass('disabled'); + + var $tr = $chkbox.closest('tr'); + + // Display local currency for price. + $tr.find('.local-retail') + .text(price.price + ' ' + price.currency); + + // Display local billing method. + $tr.find('.local-method') + .text(billingMethodText); + seen.push($chkbox[0]); } // Disable everything else. - $regions.find('input[type=checkbox]').not(seen) - .prop('checked', false) - .prop('disabled', true) - .parent('label').addClass('disabled') - .trigger('change'); + $regions.find('input[type=checkbox]').not(seen).each(function() { + var $this = $(this); + var $tr = $this.closest('tr'); + + $this.prop('checked', false) + .prop('disabled', true) + .closest('label').addClass('disabled'); + + // Remove the text, where it shouldn't be displayed. + $tr.find('.local-retail, .local-method').text(''); + }); }, dataType: "json" }).fail(function() { @@ -144,12 +160,6 @@ define('payments', [], function() { currentPrice = selectedPrice; } - function handleCheckboxChange() { - /*jshint validthis:true */ - var $this = $(this); - $this.closest('tr').find('.local-retail').toggle($this.prop('checked')); - } - function init() { $('#regions').trigger('editLoaded'); @@ -167,7 +177,6 @@ define('payments', [], function() { $('#id_price').on('change', updatePrices) .each(updatePrices); - $('.regions').on('change', 'input[type=checkbox]', handleCheckboxChange); } return { diff --git a/mkt/developers/templates/developers/payments/premium.html b/mkt/developers/templates/developers/payments/premium.html index 9e0bc0126b..e8a1c6a3f5 100644 --- a/mkt/developers/templates/developers/payments/premium.html +++ b/mkt/developers/templates/developers/payments/premium.html @@ -173,10 +173,11 @@ -
{{ region_form.regions.errors }} @@ -185,6 +186,7 @@ + @@ -198,6 +200,7 @@ name="regions" value="{{ value }}">{{ text }} + {% endif %} {% endfor %} diff --git a/mkt/developers/tests/test_views_payments.py b/mkt/developers/tests/test_views_payments.py index f325052873..4b214541ae 100644 --- a/mkt/developers/tests/test_views_payments.py +++ b/mkt/developers/tests/test_views_payments.py @@ -12,6 +12,9 @@ import amo.tests from amo.urlresolvers import reverse from addons.models import (Addon, AddonCategory, AddonDeviceType, AddonUser, Category) +from constants.payments import (PAYMENT_METHOD_ALL, + PAYMENT_METHOD_CARD, + PAYMENT_METHOD_OPERATOR) from mkt.constants.payments import ACCESS_PURCHASE, ACCESS_SIMULATE from market.models import Price from users.models import UserProfile @@ -293,7 +296,7 @@ class TestPayments(amo.tests.TestCase): eq_(len(pqr('#regions-island')), 0), eq_(len(pqr('#paid-regions-island')), 1), - def test_free_with_in_app_tier_id_in_context(self): + def test_free_with_in_app_tier_id_in_content(self): free_tier = Price.objects.create(price='0.00') self.webapp.update(premium_type=amo.ADDON_PREMIUM) res = self.client.get(self.url) @@ -301,6 +304,13 @@ class TestPayments(amo.tests.TestCase): 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_pay_method_ids_in_context(self): + self.webapp.update(premium_type=amo.ADDON_PREMIUM) + res = self.client.get(self.url) + self.assertSetEqual(res.context['payment_methods'].keys(), + [PAYMENT_METHOD_ALL, PAYMENT_METHOD_CARD, + PAYMENT_METHOD_OPERATOR]) + def test_premium_in_app_passes(self): self.webapp.update(premium_type=amo.ADDON_FREE) res = self.client.post( diff --git a/mkt/developers/views_payments.py b/mkt/developers/views_payments.py index eb3721fe84..535199e10e 100644 --- a/mkt/developers/views_payments.py +++ b/mkt/developers/views_payments.py @@ -19,6 +19,9 @@ from access import acl from amo import messages from amo.decorators import json_view, login_required, post_required, write from amo.urlresolvers import reverse +from constants.payments import (PAYMENT_METHOD_ALL, + PAYMENT_METHOD_CARD, + PAYMENT_METHOD_OPERATOR) from lib.crypto import generate_key from lib.pay_server import client @@ -145,7 +148,12 @@ def payments(request, addon_id, addon, webapp=False): not waffle.switch_is_active('disabled-payments'), 'api_pricelist_url': reverse('api_dispatch_list', kwargs={'resource_name': 'prices', - 'api_name': 'webpay'})}) + 'api_name': 'webpay'}), + 'payment_methods': { + PAYMENT_METHOD_ALL: _('All'), + PAYMENT_METHOD_CARD: _('Credit card'), + PAYMENT_METHOD_OPERATOR: _('Carrier'), + }}) @login_required
{{ _('Region') }} {{ _('Retail price') }} ({{ _('local currency') }}){{ _('Billing method') }}