From 4f67f0dad93a9184f365b69ff53909b5c1b99889 Mon Sep 17 00:00:00 2001 From: Diana Huang Date: Mon, 8 Sep 2014 15:43:44 -0400 Subject: [PATCH 1/2] Add course_id as merchant defined data --- lms/djangoapps/verify_student/views.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lms/djangoapps/verify_student/views.py b/lms/djangoapps/verify_student/views.py index 862edc2fdb..1b6fdd6e5c 100644 --- a/lms/djangoapps/verify_student/views.py +++ b/lms/djangoapps/verify_student/views.py @@ -34,7 +34,7 @@ from verify_student.models import ( from reverification.models import MidcourseReverificationWindow import ssencrypt from xmodule.modulestore.exceptions import ItemNotFoundError -from opaque_keys.edx.locations import SlashSeparatedCourseKey +from opaque_keys.edx.keys import CourseKey from .exceptions import WindowExpiredException from xmodule.modulestore.django import modulestore @@ -59,7 +59,7 @@ class VerifyView(View): """ upgrade = request.GET.get('upgrade', False) - course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id) + course_id = CourseKey.from_string(course_id) # If the user has already been verified within the given time period, # redirect straight to the payment -- no need to verify again. if SoftwareSecurePhotoVerification.user_has_valid_or_pending(request.user): @@ -133,7 +133,7 @@ class VerifiedView(View): Handle the case where we have a get request """ upgrade = request.GET.get('upgrade', False) - course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id) + course_id = CourseKey.from_string(course_id) if CourseEnrollment.enrollment_mode_for_user(request.user, course_id) == ('verified', True): return redirect(reverse('dashboard')) @@ -195,7 +195,7 @@ def create_order(request): attempt.save() course_id = request.POST['course_id'] - course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id) + course_id = CourseKey.from_string(course_id) donation_for_course = request.session.get('donation_for_course', {}) current_donation = donation_for_course.get(unicode(course_id), decimal.Decimal(0)) contribution = request.POST.get("contribution", donation_for_course.get(unicode(course_id), 0)) @@ -230,10 +230,13 @@ def create_order(request): callback_url = request.build_absolute_uri( reverse("shoppingcart.views.postpay_callback") ) + params = get_signed_purchase_params( cart, callback_url=callback_url ) + params['success'] = True + params['merchant_defined_data1'] = unicode(course_id) return HttpResponse(json.dumps(params), content_type="text/json") @@ -322,7 +325,7 @@ def show_requirements(request, course_id): Show the requirements necessary for the verification flow. """ # TODO: seems borked for professional; we're told we need to take photos even if there's a pending verification - course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id) + course_id = CourseKey.from_string(course_id) upgrade = request.GET.get('upgrade', False) if CourseEnrollment.enrollment_mode_for_user(request.user, course_id) == ('verified', True): return redirect(reverse('dashboard')) @@ -421,7 +424,7 @@ class MidCourseReverifyView(View): """ display this view """ - course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id) + course_id = CourseKey.from_string(course_id) course = modulestore().get_course(course_id) course_enrollment = CourseEnrollment.get_or_create_enrollment(request.user, course_id) course_enrollment.update_enrollment(mode="verified") @@ -445,7 +448,7 @@ class MidCourseReverifyView(View): """ try: now = datetime.datetime.now(UTC) - course_id = SlashSeparatedCourseKey.from_deprecated_string(course_id) + course_id = CourseKey.from_string(course_id) window = MidcourseReverificationWindow.get_window(course_id, now) if window is None: raise WindowExpiredException From c47673bb8b45953561c154e4892b8ecfda8989e8 Mon Sep 17 00:00:00 2001 From: Will Daly Date: Tue, 9 Sep 2014 16:32:52 -0400 Subject: [PATCH 2/2] Add a test for the course ID merchant defined field data --- lms/djangoapps/verify_student/tests/test_views.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lms/djangoapps/verify_student/tests/test_views.py b/lms/djangoapps/verify_student/tests/test_views.py index 29d1d1d808..14c7013b14 100644 --- a/lms/djangoapps/verify_student/tests/test_views.py +++ b/lms/djangoapps/verify_student/tests/test_views.py @@ -675,6 +675,9 @@ class TestCreateOrder(ModuleStoreTestCase): data = json.loads(response.content) self.assertEqual(data['override_custom_receipt_page'], "http://testserver/shoppingcart/postpay_callback/") + # Verify that the course ID is included in "merchant-defined data" + self.assertEqual(data['merchant_defined_data1'], unicode(self.course.id)) + def test_create_order_set_donation_amount(self): # Verify the student so we don't need to submit photos self._verify_student()