diff --git a/lms/djangoapps/shoppingcart/processors/CyberSource.py b/lms/djangoapps/shoppingcart/processors/CyberSource.py index 5952668d8f..18e3a4a750 100644 --- a/lms/djangoapps/shoppingcart/processors/CyberSource.py +++ b/lms/djangoapps/shoppingcart/processors/CyberSource.py @@ -102,6 +102,15 @@ def render_purchase_form_html(cart): """ Renders the HTML of the hidden POST form that must be used to initiate a purchase with CyberSource """ + return render_to_string('shoppingcart/cybersource_form.html', { + 'action': purchase_endpoint, + 'params': get_signed_purchase_params(params), + }) + +def get_signed_purchase_params(cart): + return sign(get_purchase_params(cart)) + +def get_purchase_params(cart): purchase_endpoint = settings.CC_PROCESSOR['CyberSource'].get('PURCHASE_ENDPOINT', '') total_cost = cart.total_cost @@ -112,12 +121,8 @@ def render_purchase_form_html(cart): params['currency'] = cart.currency params['orderPage_transactionType'] = 'sale' params['orderNumber'] = "{0:d}".format(cart.id) - signed_param_dict = sign(params) - return render_to_string('shoppingcart/cybersource_form.html', { - 'action': purchase_endpoint, - 'params': signed_param_dict, - }) + return params def payment_accepted(params): diff --git a/lms/djangoapps/verify_student/urls.py b/lms/djangoapps/verify_student/urls.py index 43e258e912..3f1a35685d 100644 --- a/lms/djangoapps/verify_student/urls.py +++ b/lms/djangoapps/verify_student/urls.py @@ -38,6 +38,12 @@ urlpatterns = patterns( r'^verify', views.VerifyView.as_view(), name="verify_student_verify" + ), + + url( + r'^create_order', + views.create_order, + name="verify_student_create_order" ) ) diff --git a/lms/djangoapps/verify_student/views.py b/lms/djangoapps/verify_student/views.py index 677d383bf8..7986b8c670 100644 --- a/lms/djangoapps/verify_student/views.py +++ b/lms/djangoapps/verify_student/views.py @@ -2,15 +2,21 @@ """ +import json + from mitxmako.shortcuts import render_to_response from django.conf import settings from django.core.urlresolvers import reverse +from django.http import HttpResponse from django.shortcuts import redirect from django.views.generic.base import View from course_modes.models import CourseMode +from student.models import CourseEnrollment from student.views import course_from_id +from shoppingcart.models import Order, CertificateItem +from shoppingcart.processors.CyberSource import get_signed_purchase_params from verify_student.models import SoftwareSecurePhotoVerification class VerifyView(View): @@ -29,21 +35,32 @@ class VerifyView(View): # bookkeeping-wise just to start over. progress_state = "start" + course_id = request.GET['course_id'] context = { "progress_state" : progress_state, "user_full_name" : request.user.profile.name, - "course_name" : course_from_id(request.GET['course_id']).display_name + "course_id" : course_id, + "course_name" : course_from_id(course_id).display_name } return render_to_response('verify_student/photo_verification.html', context) - def post(request): - attempt = SoftwareSecurePhotoVerification(user=request.user) - attempt.status = "pending" - attempt.save() +def create_order(request): + attempt = SoftwareSecurePhotoVerification(user=request.user) + attempt.status = "pending" + attempt.save() + course_id = request.POST['course_id'] + # I know, we should check this is valid. All kinds of stuff missing here + # enrollment = CourseEnrollment.create_enrollment(request.user, course_id) + cart = Order.get_cart_for_user(request.user) + CertificateItem.add_to_order(cart, course_id, 30, 'verified') + + params = get_signed_purchase_params(cart) + + return HttpResponse(json.dumps(params), content_type="text/json") def show_requirements(request): diff --git a/lms/templates/verify_student/photo_verification.html b/lms/templates/verify_student/photo_verification.html index fb098d3c65..a0f756717d 100644 --- a/lms/templates/verify_student/photo_verification.html +++ b/lms/templates/verify_student/photo_verification.html @@ -264,9 +264,10 @@