Merge pull request #12052 from edx/vkaracic/SOL-1668
[SOL-1668] Coupon codes application is not available for a user who has just activated his account
This commit is contained in:
@@ -35,7 +35,8 @@ from course_modes.models import CourseMode
|
||||
from course_modes.tests.factories import CourseModeFactory
|
||||
from courseware.url_helpers import get_redirect_url
|
||||
from common.test.utils import XssTestMixin
|
||||
from commerce.tests import TEST_PAYMENT_DATA, TEST_API_URL, TEST_API_SIGNING_KEY
|
||||
from commerce.models import CommerceConfiguration
|
||||
from commerce.tests import TEST_PAYMENT_DATA, TEST_API_URL, TEST_API_SIGNING_KEY, TEST_PUBLIC_URL_ROOT
|
||||
from embargo.test_utils import restrict_course
|
||||
from openedx.core.djangoapps.user_api.accounts.api import get_account_settings
|
||||
from openedx.core.djangoapps.theming.test_util import with_comprehensive_theme
|
||||
@@ -134,6 +135,34 @@ class TestPayAndVerifyView(UrlResetMixin, ModuleStoreTestCase, XssTestMixin):
|
||||
])
|
||||
self._assert_upgrade_session_flag(False)
|
||||
|
||||
@httpretty.activate
|
||||
@override_settings(
|
||||
ECOMMERCE_API_URL=TEST_API_URL,
|
||||
ECOMMERCE_API_SIGNING_KEY=TEST_API_SIGNING_KEY,
|
||||
ECOMMERCE_PUBLIC_URL_ROOT=TEST_PUBLIC_URL_ROOT
|
||||
)
|
||||
def test_start_flow_with_ecommerce(self):
|
||||
"""Verify user gets redirected to ecommerce checkout when ecommerce checkout is enabled."""
|
||||
checkout_page = '/test_basket/'
|
||||
sku = 'TESTSKU'
|
||||
# When passing a SKU ecommerce api gets called.
|
||||
httpretty.register_uri(
|
||||
httpretty.GET,
|
||||
"{}/payment/processors/".format(TEST_API_URL),
|
||||
body=json.dumps(['foo', 'bar']),
|
||||
content_type="application/json",
|
||||
)
|
||||
httpretty.register_uri(httpretty.GET, "{}{}".format(TEST_PUBLIC_URL_ROOT, checkout_page))
|
||||
CommerceConfiguration.objects.create(
|
||||
checkout_on_ecommerce_service=True,
|
||||
single_course_checkout_page=checkout_page
|
||||
)
|
||||
course = self._create_course('verified', sku=sku)
|
||||
self._enroll(course.id)
|
||||
response = self._get_page('verify_student_start_flow', course.id, expected_status_code=302)
|
||||
expected_page = '{}{}?sku={}'.format(TEST_PUBLIC_URL_ROOT, checkout_page, sku)
|
||||
self.assertRedirects(response, expected_page, fetch_redirect_response=False)
|
||||
|
||||
@ddt.data(
|
||||
("no-id-professional", "verify_student_start_flow"),
|
||||
("no-id-professional", "verify_student_begin_flow")
|
||||
|
||||
@@ -30,7 +30,7 @@ from eventtracking import tracker
|
||||
from opaque_keys import InvalidKeyError
|
||||
from opaque_keys.edx.keys import CourseKey, UsageKey
|
||||
|
||||
from commerce.utils import audit_log
|
||||
from commerce.utils import audit_log, EcommerceService
|
||||
from course_modes.models import CourseMode
|
||||
from courseware.url_helpers import get_redirect_url
|
||||
from edx_rest_api_client.exceptions import SlumberBaseException
|
||||
@@ -338,7 +338,10 @@ class PayAndVerifyView(View):
|
||||
already_verified,
|
||||
already_paid,
|
||||
is_enrolled,
|
||||
course_key
|
||||
course_key,
|
||||
user_is_trying_to_pay,
|
||||
request.user,
|
||||
relevant_course_mode.sku
|
||||
)
|
||||
if redirect_response is not None:
|
||||
return redirect_response
|
||||
@@ -429,12 +432,8 @@ class PayAndVerifyView(View):
|
||||
return render_to_response("verify_student/pay_and_verify.html", context)
|
||||
|
||||
def _redirect_if_necessary(
|
||||
self,
|
||||
message,
|
||||
already_verified,
|
||||
already_paid,
|
||||
is_enrolled,
|
||||
course_key
|
||||
self, message, already_verified, already_paid, is_enrolled, course_key, # pylint: disable=bad-continuation
|
||||
user_is_trying_to_pay, user, sku # pylint: disable=bad-continuation
|
||||
):
|
||||
"""Redirect the user to a more appropriate page if necessary.
|
||||
|
||||
@@ -493,6 +492,13 @@ class PayAndVerifyView(View):
|
||||
else:
|
||||
url = reverse('verify_student_start_flow', kwargs=course_kwargs)
|
||||
|
||||
if user_is_trying_to_pay and user.is_active:
|
||||
# IIf the user is trying to pay, has activated their account, and the ecommerce service
|
||||
# is enabled redirect him to the ecommerce checkout page.
|
||||
ecommerce_service = EcommerceService()
|
||||
if ecommerce_service.is_enabled(user):
|
||||
url = ecommerce_service.checkout_page_url(sku)
|
||||
|
||||
# Redirect if necessary, otherwise implicitly return None
|
||||
if url is not None:
|
||||
return redirect(url)
|
||||
|
||||
Reference in New Issue
Block a user