From 8cd0cb0d07f65ebbd4db9e1cbf65ea02703972ef Mon Sep 17 00:00:00 2001 From: Nawfal Ahmed <111358247+NawfalAhmed@users.noreply.github.com> Date: Tue, 18 Jul 2023 17:43:39 +0500 Subject: [PATCH] feat: get subscription upsell values from env (#32770) --- lms/djangoapps/learner_dashboard/programs.py | 16 +++++++++++----- lms/envs/common.py | 2 ++ lms/envs/devstack.py | 2 ++ lms/envs/test.py | 2 ++ .../models/program_subscription_model.js | 3 +-- .../learner_dashboard/spec/sidebar_view_spec.js | 8 ++++++-- .../js/learner_dashboard/views/sidebar_view.js | 2 +- .../views/subscription_upsell_view.js | 11 +++++------ .../program_details_fragment.html | 1 + .../learner_dashboard/programs_fragment.html | 2 +- .../subscription_upsell_view.underscore | 7 +++++-- 11 files changed, 37 insertions(+), 19 deletions(-) diff --git a/lms/djangoapps/learner_dashboard/programs.py b/lms/djangoapps/learner_dashboard/programs.py index 2db218ef6d..d567a4b9a3 100644 --- a/lms/djangoapps/learner_dashboard/programs.py +++ b/lms/djangoapps/learner_dashboard/programs.py @@ -6,6 +6,7 @@ import json from abc import ABC, abstractmethod from urllib.parse import quote +from django.conf import settings from django.contrib.sites.shortcuts import get_current_site from django.http import Http404 from django.template.loader import render_to_string @@ -65,18 +66,22 @@ class ProgramsFragmentView(EdxFragmentView): if is_user_b2c_subscriptions_enabled else [] ) - subscriptions_marketing_url = ( - get_program_subscriptions_marketing_url() + subscription_upsell_data = ( + { + 'marketing_url': get_program_subscriptions_marketing_url(), + 'minimum_price': settings.SUBSCRIPTIONS_MINIMUM_PRICE, + 'trial_length': settings.SUBSCRIPTIONS_TRIAL_LENGTH, + } if is_user_b2c_subscriptions_enabled - else '' + else {} ) context = { 'marketing_url': get_program_marketing_url(programs_config, mobile_only), - 'subscriptions_marketing_url': subscriptions_marketing_url, 'programs': meter.engaged_programs, 'progress': meter.progress(), 'programs_subscription_data': programs_subscription_data, + 'subscription_upsell_data': subscription_upsell_data, 'user_preferences': get_user_preferences(user), 'is_user_b2c_subscriptions_enabled': is_user_b2c_subscriptions_enabled, 'mobile_only': bool(mobile_only) @@ -152,12 +157,13 @@ class ProgramDetailsFragmentView(EdxFragmentView): 'user_preferences': get_user_preferences(user), 'program_data': program_data, 'program_subscription_data': program_subscription_data, - 'is_user_b2c_subscriptions_enabled': is_user_b2c_subscriptions_enabled, 'course_data': course_data, 'certificate_data': certificate_data, 'industry_pathways': industry_pathways, 'credit_pathways': credit_pathways, 'program_tab_view_enabled': program_tab_view_enabled(), + 'is_user_b2c_subscriptions_enabled': is_user_b2c_subscriptions_enabled, + 'subscriptions_trial_length': settings.SUBSCRIPTIONS_TRIAL_LENGTH, 'discussion_fragment': { 'configured': program_discussion_lti.is_configured, 'iframe': program_discussion_lti.render_iframe() diff --git a/lms/envs/common.py b/lms/envs/common.py index 23b6138ba8..cc953d355e 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -5338,6 +5338,8 @@ SUBSCRIPTIONS_API_PATH = f"{SUBSCRIPTIONS_ROOT_URL}/api/v1/stripe-subscription/" SUBSCRIPTIONS_LEARNER_HELP_CENTER_URL = None SUBSCRIPTIONS_BUY_SUBSCRIPTION_URL = f"{SUBSCRIPTIONS_ROOT_URL}/api/v1/stripe-subscribe/" SUBSCRIPTIONS_MANAGE_SUBSCRIPTION_URL = None +SUBSCRIPTIONS_MINIMUM_PRICE = '$39' +SUBSCRIPTIONS_TRIAL_LENGTH = 7 SUBSCRIPTIONS_SERVICE_WORKER_USERNAME = 'subscriptions_worker' ############## NOTIFICATIONS EXPIRY ############## diff --git a/lms/envs/devstack.py b/lms/envs/devstack.py index 856e9ef9c1..6e4498a200 100644 --- a/lms/envs/devstack.py +++ b/lms/envs/devstack.py @@ -509,6 +509,8 @@ SUBSCRIPTIONS_API_PATH = f"{SUBSCRIPTIONS_ROOT_URL}/api/v1/stripe-subscription/" SUBSCRIPTIONS_LEARNER_HELP_CENTER_URL = None SUBSCRIPTIONS_BUY_SUBSCRIPTION_URL = f"{SUBSCRIPTIONS_ROOT_URL}/api/v1/stripe-subscribe/" SUBSCRIPTIONS_MANAGE_SUBSCRIPTION_URL = None +SUBSCRIPTIONS_MINIMUM_PRICE = '$39' +SUBSCRIPTIONS_TRIAL_LENGTH = 7 # API access management API_ACCESS_MANAGER_EMAIL = 'api-access@example.com' diff --git a/lms/envs/test.py b/lms/envs/test.py index 932f00fdef..18cdcb7f14 100644 --- a/lms/envs/test.py +++ b/lms/envs/test.py @@ -677,3 +677,5 @@ SUBSCRIPTIONS_API_PATH = f"{SUBSCRIPTIONS_ROOT_URL}/api/v1/stripe-subscription/" SUBSCRIPTIONS_LEARNER_HELP_CENTER_URL = None SUBSCRIPTIONS_BUY_SUBSCRIPTION_URL = f"{SUBSCRIPTIONS_ROOT_URL}/api/v1/stripe-subscribe/" SUBSCRIPTIONS_MANAGE_SUBSCRIPTION_URL = None +SUBSCRIPTIONS_MINIMUM_PRICE = '$39' +SUBSCRIPTIONS_TRIAL_LENGTH = 7 diff --git a/lms/static/js/learner_dashboard/models/program_subscription_model.js b/lms/static/js/learner_dashboard/models/program_subscription_model.js index f907b8938c..5d80eaf831 100644 --- a/lms/static/js/learner_dashboard/models/program_subscription_model.js +++ b/lms/static/js/learner_dashboard/models/program_subscription_model.js @@ -15,6 +15,7 @@ class ProgramSubscriptionModel extends Backbone.Model { programData: { subscription_prices }, urls = {}, userPreferences = {}, + subscriptionsTrialLength: trialLength = 7, } = context; const priceInUSD = subscription_prices?.find(({ currency }) => currency === 'USD'); @@ -56,8 +57,6 @@ class ProgramSubscriptionModel extends Backbone.Model { userPreferences ); - const trialLength = 7; - super( { hasActiveTrial, diff --git a/lms/static/js/learner_dashboard/spec/sidebar_view_spec.js b/lms/static/js/learner_dashboard/spec/sidebar_view_spec.js index c3714b2f7a..40e1a707cd 100644 --- a/lms/static/js/learner_dashboard/spec/sidebar_view_spec.js +++ b/lms/static/js/learner_dashboard/spec/sidebar_view_spec.js @@ -6,7 +6,11 @@ describe('Sidebar View', () => { let view = null; const context = { marketingUrl: 'https://www.example.org/programs', - subscriptionsMarketingUrl: 'https://www.example.org/program-subscriptions', + subscriptionUpsellData: { + marketing_url: 'https://www.example.org/program-subscriptions', + minimum_price: '$39', + trial_length: 7, + }, isUserB2CSubscriptionsEnabled: true, }; @@ -72,7 +76,7 @@ describe('Sidebar View', () => { el: '.sidebar', context: { isUserB2CSubscriptionsEnabled: true, - subscriptionsMarketingUrl: '', + subscriptionUpsellData: context.subscriptionUpsellData, }, }); view.render(); diff --git a/lms/static/js/learner_dashboard/views/sidebar_view.js b/lms/static/js/learner_dashboard/views/sidebar_view.js index 8f4a75c166..c092e707b0 100644 --- a/lms/static/js/learner_dashboard/views/sidebar_view.js +++ b/lms/static/js/learner_dashboard/views/sidebar_view.js @@ -31,7 +31,7 @@ class SidebarView extends Backbone.View { postRender() { if (this.context.isUserB2CSubscriptionsEnabled) { this.subscriptionUpsellView = new SubscriptionUpsellView({ - context: this.context, + subscriptionUpsellData: this.context.subscriptionUpsellData, }); } diff --git a/lms/static/js/learner_dashboard/views/subscription_upsell_view.js b/lms/static/js/learner_dashboard/views/subscription_upsell_view.js index 06235c2a47..c7e8c89c7c 100644 --- a/lms/static/js/learner_dashboard/views/subscription_upsell_view.js +++ b/lms/static/js/learner_dashboard/views/subscription_upsell_view.js @@ -12,17 +12,16 @@ class SubscriptionUpsellView extends Backbone.View { super(Object.assign({}, defaults, options)); } - initialize({ context }) { + initialize(options) { this.tpl = HtmlUtils.template(subscriptionUpsellTpl); - this.context = context; + this.subscriptionUpsellModel = new Backbone.Model( + options.subscriptionUpsellData, + ); this.render(); } render() { - const data = $.extend({}, this.context, { - minSubscriptionPrice: '$39', - trialLength: 7, - }); + const data = this.subscriptionUpsellModel.toJSON(); HtmlUtils.setHtml(this.$el, this.tpl(data)); } } diff --git a/lms/templates/learner_dashboard/program_details_fragment.html b/lms/templates/learner_dashboard/program_details_fragment.html index d27b5e4467..7aff07a6a3 100644 --- a/lms/templates/learner_dashboard/program_details_fragment.html +++ b/lms/templates/learner_dashboard/program_details_fragment.html @@ -23,6 +23,7 @@ ProgramDetailsFactory({ creditPathways: ${credit_pathways | n, dump_js_escaped_json}, programTabViewEnabled: ${program_tab_view_enabled | n, dump_js_escaped_json}, isUserB2CSubscriptionsEnabled: ${is_user_b2c_subscriptions_enabled | n, dump_js_escaped_json}, + subscriptionsTrialLength: ${subscriptions_trial_length | n, dump_js_escaped_json}, discussionFragment: ${discussion_fragment, | n, dump_js_escaped_json}, live_fragment: ${live_fragment, | n, dump_js_escaped_json} }); diff --git a/lms/templates/learner_dashboard/programs_fragment.html b/lms/templates/learner_dashboard/programs_fragment.html index 0bf18cfaec..d3e9f3d8ef 100644 --- a/lms/templates/learner_dashboard/programs_fragment.html +++ b/lms/templates/learner_dashboard/programs_fragment.html @@ -30,9 +30,9 @@ from openedx.core.djangolib.js_utils import ( <%static:webpack entry="ProgramListFactory"> ProgramListFactory({ marketingUrl: '${marketing_url | n, js_escaped_string}', - subscriptionsMarketingUrl: '${subscriptions_marketing_url | n, js_escaped_string}', programsData: ${programs | n, dump_js_escaped_json}, programsSubscriptionData: ${programs_subscription_data | n, dump_js_escaped_json}, + subscriptionUpsellData: ${subscription_upsell_data | n, dump_js_escaped_json}, userProgress: ${progress | n, dump_js_escaped_json}, userPreferences: ${user_preferences | n, dump_js_escaped_json}, isUserB2CSubscriptionsEnabled: ${is_user_b2c_subscriptions_enabled | n, dump_js_escaped_json}, diff --git a/lms/templates/learner_dashboard/subscription_upsell_view.underscore b/lms/templates/learner_dashboard/subscription_upsell_view.underscore index ef765da17b..cc01d47c81 100644 --- a/lms/templates/learner_dashboard/subscription_upsell_view.underscore +++ b/lms/templates/learner_dashboard/subscription_upsell_view.underscore @@ -8,10 +8,13 @@
- + <%- gettext('Explore subscription options') %>