Skip to content

Commit

Permalink
fix: fix buy_subscription_url to use get method (#32079)
Browse files Browse the repository at this point in the history
* fix: fix buy_subscription_url to use get method
  • Loading branch information
aht007 authored Apr 18, 2023
1 parent b852344 commit 2a7b400
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 5 deletions.
1 change: 1 addition & 0 deletions lms/djangoapps/learner_dashboard/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def render_to_fragment(self, request, **kwargs):
'programs': meter.engaged_programs,
'progress': meter.progress(),
'programs_subscription_data': programs_subscription_data,
'user_preferences': get_user_preferences(user),
'is_user_b2c_subscriptions_enabled': is_user_b2c_subscriptions_enabled
}
html = render_to_string('learner_dashboard/programs_fragment.html', context)
Expand Down
2 changes: 1 addition & 1 deletion lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5312,4 +5312,4 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring
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_BUY_SUBSCRIPTION_URL = f"{SUBSCRIPTIONS_ROOT_URL}/api/v1/stripe-subscribe"
2 changes: 1 addition & 1 deletion lms/envs/devstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def should_show_debug_toolbar(request): # lint-amnesty, pylint: disable=missing
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_BUY_SUBSCRIPTION_URL = f"{SUBSCRIPTIONS_ROOT_URL}/api/v1/stripe-subscribe"

################# New settings must go ABOVE this line #################
########################################################################
Expand Down
2 changes: 1 addition & 1 deletion lms/envs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,4 +682,4 @@
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_BUY_SUBSCRIPTION_URL = f"{SUBSCRIPTIONS_ROOT_URL}/api/v1/stripe-subscribe"
31 changes: 31 additions & 0 deletions openedx/core/djangoapps/programs/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from collections import namedtuple
from copy import deepcopy
from unittest import mock
from urllib.parse import urlencode

import ddt
import httpretty
Expand Down Expand Up @@ -43,6 +44,7 @@
ProgramDataExtender,
ProgramMarketingDataExtender,
ProgramProgressMeter,
get_buy_subscription_url,
get_certificates,
get_logged_in_program_certificate_url,
get_programs_subscription_data,
Expand Down Expand Up @@ -1798,3 +1800,32 @@ def test_get_programs_subscription_data_with_uuid(self, mock_log, mock_get_subsc
}
)
assert result == subscription_data


@override_settings(SUBSCRIPTIONS_BUY_SUBSCRIPTION_URL='http://subscription_buy_url')
@ddt.ddt
class TestBuySubscriptionUrl(TestCase):
"""
Tests for the BuySubscriptionUrl utility function.
"""
@ddt.data(
{
'skus': ['TESTSKU'],
'program_uuid': '12345678-9012-3456-7890-123456789012'
},
{
'skus': ['TESTSKU1', 'TESTSKU2', 'TESTSKU3'],
'program_uuid': '12345678-9012-3456-7890-123456789012'
},
{
'skus': [],
'program_uuid': '12345678-9012-3456-7890-123456789012'
}
)
@ddt.unpack
def test_get_buy_subscription_url(self, skus, program_uuid):
""" Verify the subscription purchase page URL is properly constructed and returned. """
url = get_buy_subscription_url(program_uuid, skus)
formatted_skus = urlencode({'sku': skus}, doseq=True)
expected_url = f'{settings.SUBSCRIPTIONS_BUY_SUBSCRIPTION_URL}/{program_uuid}/?{formatted_skus}'
assert url == expected_url
13 changes: 11 additions & 2 deletions openedx/core/djangoapps/programs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from collections import defaultdict
from copy import deepcopy
from itertools import chain
from urllib.parse import urljoin, urlparse, urlunparse
from urllib.parse import urlencode, urljoin, urlparse, urlunparse

import requests
from dateutil.parser import parse
Expand Down Expand Up @@ -65,6 +65,15 @@ def get_program_and_course_data(site, user, program_uuid, mobile_only=False):
return program_data, course_data


def get_buy_subscription_url(program_uuid, skus):
"""
Returns the URL to the Subscription Purchase page for the given program UUID and course Skus.
"""
formatted_skus = urlencode({'sku': skus}, doseq=True)
url = f'{settings.SUBSCRIPTIONS_BUY_SUBSCRIPTION_URL}/{program_uuid}/?{formatted_skus}'
return url


def get_program_urls(program_data):
"""Returns important urls of program."""
from lms.djangoapps.learner_dashboard.utils import FAKE_COURSE_KEY, strip_course_id
Expand All @@ -85,7 +94,7 @@ def get_program_urls(program_data):
'commerce_api_url': reverse('commerce_api:v0:baskets:create'),
'buy_button_url': ecommerce_service.get_checkout_page_url(*skus),
'program_record_url': program_record_url,
'buy_subscription_url': settings.SUBSCRIPTIONS_BUY_SUBSCRIPTION_URL,
'buy_subscription_url': get_buy_subscription_url(program_uuid, skus),
'manage_subscription_url': settings.ORDER_HISTORY_MICROFRONTEND_URL,
'subscriptions_learner_help_center_url': settings.SUBSCRIPTIONS_LEARNER_HELP_CENTER_URL
}
Expand Down

0 comments on commit 2a7b400

Please sign in to comment.