From 1513e44565d9999a092dd91d66eb0dff5d99add8 Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 4 Oct 2022 14:06:49 -1000 Subject: [PATCH] Remove back-end references to old Premium plans --- .env-dist | 1 - api/urls.py | 2 - api/views/__init__.py | 11 -- emails/models.py | 6 +- privaterelay/context_processors.py | 10 +- privaterelay/settings.py | 127 ------------------------ privaterelay/templatetags/relay_tags.py | 24 ----- privaterelay/tests/utils_tests.py | 36 ------- privaterelay/utils.py | 16 +-- privaterelay/views.py | 1 - 10 files changed, 9 insertions(+), 225 deletions(-) diff --git a/.env-dist b/.env-dist index b72cac72f..20c675e39 100644 --- a/.env-dist +++ b/.env-dist @@ -36,7 +36,6 @@ TWILIO_AUTH_TOKEN= TWILIO_SMS_APPLICATION_SID= TWILIO_MESSAGING_SERVICE_SID= TWILIO_MAIN_NUMBER= -PREMIUM_PROD_ID=prod_K29ULZL9pUR9Fr PERIODICAL_PREMIUM_PROD_ID=prod_KGizMiBqUJdYoY PHONE_PROD_ID=prod_KGizMiBqUJdYoY BUNDLE_PROD_ID=prod_MIex7Q079igFZJ diff --git a/api/urls.py b/api/urls.py index 00c1f5375..76cc2fb0e 100644 --- a/api/urls.py +++ b/api/urls.py @@ -8,7 +8,6 @@ from .views import ( RelayAddressViewSet, ProfileViewSet, UserViewSet, - premium_countries, report_webcompat_issue, runtime_data, schema_view, @@ -36,7 +35,6 @@ api_router.register(r"users", UserViewSet, "user") urlpatterns = [ - path("v1/premium_countries", premium_countries, name="premium_countries"), path("v1/runtime_data", runtime_data, name="runtime_data"), path( "v1/report_webcompat_issue", diff --git a/api/views/__init__.py b/api/views/__init__.py index 48b01c97b..a8b7c5466 100644 --- a/api/views/__init__.py +++ b/api/views/__init__.py @@ -27,7 +27,6 @@ from emails.utils import incr_if_enabled from privaterelay.utils import ( get_countries_info_from_request_and_mapping, - get_premium_countries_info_from_request, ) from emails.models import ( @@ -160,14 +159,6 @@ class UserViewSet(viewsets.ModelViewSet): return User.objects.filter(id=self.request.user.id) -# Deprecated; prefer runtime_data instead. -# (This method isn't deleted yet, because the add-on still calls it.) -@decorators.api_view() -@decorators.permission_classes([permissions.AllowAny]) -def premium_countries(request): - return response.Response(get_premium_countries_info_from_request(request)) - - @decorators.api_view() @decorators.permission_classes([permissions.AllowAny]) def runtime_data(request): @@ -183,9 +174,7 @@ def runtime_data(request): "PERIODICAL_PREMIUM_PRODUCT_ID": settings.PERIODICAL_PREMIUM_PROD_ID, "GOOGLE_ANALYTICS_ID": settings.GOOGLE_ANALYTICS_ID, "BUNDLE_PRODUCT_ID": settings.BUNDLE_PROD_ID, - "PREMIUM_PRODUCT_ID": settings.PREMIUM_PROD_ID, "PHONE_PRODUCT_ID": settings.PHONE_PROD_ID, - "PREMIUM_PLANS": get_premium_countries_info_from_request(request), "PERIODICAL_PREMIUM_PLANS": get_countries_info_from_request_and_mapping( request, settings.PERIODICAL_PREMIUM_PLAN_COUNTRY_LANG_MAPPING ), diff --git a/emails/models.py b/emails/models.py index b6abd1fbe..60819ec5e 100644 --- a/emails/models.py +++ b/emails/models.py @@ -160,7 +160,7 @@ class Profile(models.Model): # This method returns whether the locale associated with the user's Firefox account # includes a country code from a Premium country. This is less accurate than using - # get_premium_countries_info_from_request(), which uses a GeoIP lookup, so prefer + # get_countries_info_from_request_and_mapping(), which uses a GeoIP lookup, so prefer # using that if a request context is available. In other contexts, e.g. when # sending an email, this method can be useful. @property @@ -171,7 +171,7 @@ class Profile(models.Model): len(accept_langs) >= 1 and len(accept_langs[0][0].split("-")) >= 2 and accept_langs[0][0].split("-")[1] - in settings.PREMIUM_PLAN_COUNTRY_LANG_MAPPING.keys() + in settings.PERIODICAL_PREMIUM_PLAN_COUNTRY_LANG_MAPPING.keys() ): return True # If a language but no country is known, check if there's a country @@ -182,7 +182,7 @@ class Profile(models.Model): len(accept_langs) >= 1 and len(accept_langs[0][0].split("-")) == 1 and accept_langs[0][0].split("-")[0] - in settings.PREMIUM_PLAN_COUNTRY_LANG_MAPPING.keys() + in settings.PERIODICAL_PREMIUM_PLAN_COUNTRY_LANG_MAPPING.keys() ): return True return False diff --git a/privaterelay/context_processors.py b/privaterelay/context_processors.py index 103fd8d56..10cc8cfdd 100644 --- a/privaterelay/context_processors.py +++ b/privaterelay/context_processors.py @@ -4,8 +4,7 @@ from functools import lru_cache from django.conf import settings from django.db.models import prefetch_related_objects -from .templatetags.relay_tags import premium_plan_price -from .utils import get_premium_countries_info_from_request +from .utils import get_countries_info_from_request_and_mapping def django_settings(request): @@ -17,7 +16,9 @@ def common(request): avatar = fxa.extra_data["avatar"] if fxa else None accept_language = request.headers.get("Accept-Language", "en-US") country_code = request.headers.get("X-Client-Region", "us").lower() - premium_countries_vars = get_premium_countries_info_from_request(request) + premium_countries_vars = get_countries_info_from_request_and_mapping( + request, settings.PERIODICAL_PREMIUM_PLAN_COUNTRY_LANG_MAPPING + ) csat_dismissal_cookie, reason_to_show_csat_survey = _get_csat_cookie_and_reason( request @@ -35,9 +36,6 @@ def common(request): "country_code": country_code, "show_csat": show_csat, "csat_dismissal_cookie": csat_dismissal_cookie, - "monthly_price": premium_plan_price( - accept_language, premium_countries_vars["country_code"] - ), } return {**common_vars, **premium_countries_vars} diff --git a/privaterelay/settings.py b/privaterelay/settings.py index 0ea1093ae..9e061188b 100644 --- a/privaterelay/settings.py +++ b/privaterelay/settings.py @@ -315,7 +315,6 @@ TEMPLATES = [ RELAY_FIREFOX_DOMAIN = config("RELAY_FIREFOX_DOMAIN", "relay.firefox.com", cast=str) MOZMAIL_DOMAIN = config("MOZMAIL_DOMAIN", "mozmail.com", cast=str) MAX_NUM_FREE_ALIASES = config("MAX_NUM_FREE_ALIASES", 5, cast=int) -PREMIUM_PROD_ID = config("PREMIUM_PROD_ID", "", cast=str) PERIODICAL_PREMIUM_PROD_ID = config("PERIODICAL_PREMIUM_PROD_ID", "", cast=str) PREMIUM_PLAN_ID_US_MONTHLY = config( "PREMIUM_PLAN_ID_US_MONTHLY", "price_1LXUcnJNcmPzuWtRpbNOajYS", cast=str @@ -334,132 +333,6 @@ BUNDLE_PROD_ID = config("BUNDLE_PROD_ID", "", cast=str) BUNDLE_PLAN_ID_US = config( "BUNDLE_PLAN_ID_US", "price_1LwoSDJNcmPzuWtR6wPJZeoh", cast=str ) -PREMIUM_PRICE_ID_OVERRIDE = config("PREMIUM_PRICE_ID_OVERRIDE", "", cast=str) -PREMIUM_PLAN_ID_MATRIX = { - "chf": { - "de": { - "id": "price_1JmRM0JNcmPzuWtRzCJ2LQHP", - "price": "CHF 1.00", - }, - "fr": { - "id": "price_1JmRFrJNcmPzuWtROOs10fKh", - "price": "CHF 1.00", - }, - "it": { - "id": "price_1JmREHJNcmPzuWtRxo7MoT58", - "price": "CHF 1.00", - }, - }, - "euro": { - "at": { - "id": "price_1JmRTDJNcmPzuWtRnJavIXXX", - "price": "0,99 €", - }, - "de": { - "id": "price_1JmRTDJNcmPzuWtRnJavIXXX", - "price": "0,99 €", - }, - "en": { - "id": "price_1JmRCQJNcmPzuWtRprMnmtax", - "price": "0,99 €", - }, - "es": { - "id": "price_1JmRPSJNcmPzuWtRVvkEkVbS", - "price": "0,99 €", - }, - "fr": { - "id": "price_1JmRU4JNcmPzuWtRRhu1FhiQ", - "price": "0,99 €", - }, - "it": { - "id": "price_1JmRQLJNcmPzuWtRGs76IkUY", - "price": "0,99 €", - }, - "nl": { - "id": "price_1JmROfJNcmPzuWtR6od8OfDW", - "price": "0,99 €", - }, - "ie": { - "id": "price_1JmRCQJNcmPzuWtRprMnmtax", - "price": "0,99 €", - }, - "se": { - "id": "price_1KQc1PJNcmPzuWtRsEfb6inB", - "price": "0,99 €", - }, - "fi": { - "id": "price_1KQcA7JNcmPzuWtRPKNacfdn", - "price": "0,99 €", - }, - }, - "usd": {"en": {"id": "price_1JmRSRJNcmPzuWtRN9MG5cBy", "price": "$0.99"}}, -} -PREMIUM_PLAN_COUNTRY_LANG_MAPPING = { - # Austria - "at": {"de": PREMIUM_PLAN_ID_MATRIX["euro"]["de"]}, - # Belgium - "be": { - "fr": PREMIUM_PLAN_ID_MATRIX["euro"]["fr"], - "de": PREMIUM_PLAN_ID_MATRIX["euro"]["de"], - "nl": PREMIUM_PLAN_ID_MATRIX["euro"]["nl"], - }, - # Switzerland - "ch": { - "fr": PREMIUM_PLAN_ID_MATRIX["chf"]["fr"], - "de": PREMIUM_PLAN_ID_MATRIX["chf"]["de"], - "it": PREMIUM_PLAN_ID_MATRIX["chf"]["it"], - }, - # Germany - "de": { - "de": PREMIUM_PLAN_ID_MATRIX["euro"]["de"], - }, - # Spain - "es": { - "es": PREMIUM_PLAN_ID_MATRIX["euro"]["es"], - }, - # France - "fr": { - "fr": PREMIUM_PLAN_ID_MATRIX["euro"]["fr"], - }, - # Ireland - "ie": { - "en": PREMIUM_PLAN_ID_MATRIX["euro"]["en"], - }, - # Italy - "it": { - "it": PREMIUM_PLAN_ID_MATRIX["euro"]["it"], - }, - # Netherlands - "nl": { - "nl": PREMIUM_PLAN_ID_MATRIX["euro"]["nl"], - }, - # Sweden - "se": { - "sv": PREMIUM_PLAN_ID_MATRIX["euro"]["se"], - }, - # Finland - "fi": { - "fi": PREMIUM_PLAN_ID_MATRIX["euro"]["fi"], - }, - "us": { - "en": PREMIUM_PLAN_ID_MATRIX["usd"]["en"], - }, - "gb": { - "en": PREMIUM_PLAN_ID_MATRIX["usd"]["en"], - }, - "ca": { - "en": PREMIUM_PLAN_ID_MATRIX["usd"]["en"], - }, - "nz": { - "en": PREMIUM_PLAN_ID_MATRIX["usd"]["en"], - }, - "my": { - "en": PREMIUM_PLAN_ID_MATRIX["usd"]["en"], - }, - "sg": { - "en": PREMIUM_PLAN_ID_MATRIX["usd"]["en"], - }, -} PERIODICAL_PREMIUM_PLAN_ID_MATRIX = { "chf": { diff --git a/privaterelay/templatetags/relay_tags.py b/privaterelay/templatetags/relay_tags.py index bc7d5a796..9b5c3615c 100644 --- a/privaterelay/templatetags/relay_tags.py +++ b/privaterelay/templatetags/relay_tags.py @@ -30,27 +30,3 @@ def message_in_fluent(message): "error-premium-check-subdomain", ] return message in ftl_messages - - -@register.simple_tag -def premium_plan_id(accept_lang, cc=None): - if settings.PREMIUM_PRICE_ID_OVERRIDE: - return settings.PREMIUM_PRICE_ID_OVERRIDE - cc, lang = get_premium_country_lang(accept_lang, cc) - if cc in settings.PREMIUM_PLAN_COUNTRY_LANG_MAPPING: - return settings.PREMIUM_PLAN_COUNTRY_LANG_MAPPING[cc][lang]["id"] - return "" - - -@register.simple_tag -def premium_plan_price(accept_lang, cc=None): - cc, lang = get_premium_country_lang(accept_lang, cc) - if cc not in settings.PREMIUM_PLAN_COUNTRY_LANG_MAPPING: - cc = "us" - return settings.PREMIUM_PLAN_COUNTRY_LANG_MAPPING[cc][lang]["price"] - - -@register.simple_tag -def premium_subscribe_url(accept_lang=None, cc=None): - plan_id = premium_plan_id(accept_lang, cc) - return f"{settings.FXA_SUBSCRIPTIONS_URL}/products/{settings.PREMIUM_PROD_ID}?plan={plan_id}" diff --git a/privaterelay/tests/utils_tests.py b/privaterelay/tests/utils_tests.py index 3983a0c9a..0058b04b3 100644 --- a/privaterelay/tests/utils_tests.py +++ b/privaterelay/tests/utils_tests.py @@ -1,7 +1,5 @@ -from django.conf import settings from django.test import TestCase -from ..templatetags.relay_tags import premium_plan_id from ..utils import get_premium_country_lang @@ -22,37 +20,3 @@ class GetPremiumCountryLangTest(TestCase): cc, lang = get_premium_country_lang("de-be,", "at") assert cc == "at" assert lang == "de" - - -class PremiumPlanIDTest(TestCase): - def test_premium_plan_id_tag(self): - plans = settings.PREMIUM_PLAN_ID_MATRIX - plan_id = premium_plan_id("en-US", "us") - assert plan_id == plans["usd"]["en"]["id"] - - plan_id = premium_plan_id("de", "de") - assert plan_id == plans["euro"]["de"]["id"] - - plan_id = premium_plan_id("en-ca") - assert plan_id == plans["usd"]["en"]["id"] - - plan_id = premium_plan_id("en-gb") - assert plan_id == plans["usd"]["en"]["id"] - - plan_id = premium_plan_id("fr", "fr") - assert plan_id == plans["euro"]["fr"]["id"] - - plan_id = premium_plan_id("it") - assert plan_id == plans["euro"]["it"]["id"] - - plan_id = premium_plan_id("en-ie") - assert plan_id == plans["euro"]["ie"]["id"] - - plan_id = premium_plan_id("en", "at") - assert plan_id == plans["euro"]["at"]["id"] - - plan_id = premium_plan_id("sv", "se") - assert plan_id == plans["euro"]["se"]["id"] - - plan_id = premium_plan_id("fi", "fi") - assert plan_id == plans["euro"]["fi"]["id"] diff --git a/privaterelay/utils.py b/privaterelay/utils.py index bb3dc6159..0102e6e06 100644 --- a/privaterelay/utils.py +++ b/privaterelay/utils.py @@ -1,18 +1,6 @@ from django.conf import settings -def get_premium_countries_info_from_request(request): - country_code = _get_cc_from_request(request) - premium_countries = settings.PREMIUM_PLAN_COUNTRY_LANG_MAPPING.keys() - premium_available_in_country = country_code in premium_countries - return { - "country_code": country_code, - "premium_countries": premium_countries, - "premium_available_in_country": premium_available_in_country, - "plan_country_lang_mapping": settings.PREMIUM_PLAN_COUNTRY_LANG_MAPPING, - } - - def get_countries_info_from_request_and_mapping(request, mapping): country_code = _get_cc_from_request(request) countries = mapping.keys() @@ -46,8 +34,8 @@ def get_premium_country_lang(accept_lang, cc=None): if cc == "en": cc = "us" - if cc in settings.PREMIUM_PLAN_COUNTRY_LANG_MAPPING.keys(): - languages = settings.PREMIUM_PLAN_COUNTRY_LANG_MAPPING[cc] + if cc in settings.PERIODICAL_PREMIUM_PLAN_COUNTRY_LANG_MAPPING.keys(): + languages = settings.PERIODICAL_PREMIUM_PLAN_COUNTRY_LANG_MAPPING[cc] if lang in languages.keys(): return cc, lang return cc, list(languages.keys())[0] diff --git a/privaterelay/views.py b/privaterelay/views.py index 794e12f71..81abc62e7 100644 --- a/privaterelay/views.py +++ b/privaterelay/views.py @@ -35,7 +35,6 @@ from emails.models import ( valid_available_subdomain, ) from emails.utils import incr_if_enabled -from privaterelay.utils import get_premium_countries_info_from_request FXA_PROFILE_CHANGE_EVENT = "https://schemas.accounts.firefox.com/event/profile-change"