Commit ff472e16 by David Ormsbee

Grabbing the basic order information we need to sent to CyberSource.

parent 247c3ade
...@@ -102,6 +102,15 @@ def render_purchase_form_html(cart): ...@@ -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 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', '') purchase_endpoint = settings.CC_PROCESSOR['CyberSource'].get('PURCHASE_ENDPOINT', '')
total_cost = cart.total_cost total_cost = cart.total_cost
...@@ -112,12 +121,8 @@ def render_purchase_form_html(cart): ...@@ -112,12 +121,8 @@ def render_purchase_form_html(cart):
params['currency'] = cart.currency params['currency'] = cart.currency
params['orderPage_transactionType'] = 'sale' params['orderPage_transactionType'] = 'sale'
params['orderNumber'] = "{0:d}".format(cart.id) params['orderNumber'] = "{0:d}".format(cart.id)
signed_param_dict = sign(params)
return render_to_string('shoppingcart/cybersource_form.html', { return params
'action': purchase_endpoint,
'params': signed_param_dict,
})
def payment_accepted(params): def payment_accepted(params):
......
...@@ -38,6 +38,12 @@ urlpatterns = patterns( ...@@ -38,6 +38,12 @@ urlpatterns = patterns(
r'^verify', r'^verify',
views.VerifyView.as_view(), views.VerifyView.as_view(),
name="verify_student_verify" name="verify_student_verify"
),
url(
r'^create_order',
views.create_order,
name="verify_student_create_order"
) )
) )
...@@ -2,15 +2,21 @@ ...@@ -2,15 +2,21 @@
""" """
import json
from mitxmako.shortcuts import render_to_response from mitxmako.shortcuts import render_to_response
from django.conf import settings from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.http import HttpResponse
from django.shortcuts import redirect from django.shortcuts import redirect
from django.views.generic.base import View from django.views.generic.base import View
from course_modes.models import CourseMode from course_modes.models import CourseMode
from student.models import CourseEnrollment
from student.views import course_from_id 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 from verify_student.models import SoftwareSecurePhotoVerification
class VerifyView(View): class VerifyView(View):
...@@ -29,21 +35,32 @@ class VerifyView(View): ...@@ -29,21 +35,32 @@ class VerifyView(View):
# bookkeeping-wise just to start over. # bookkeeping-wise just to start over.
progress_state = "start" progress_state = "start"
course_id = request.GET['course_id']
context = { context = {
"progress_state" : progress_state, "progress_state" : progress_state,
"user_full_name" : request.user.profile.name, "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) return render_to_response('verify_student/photo_verification.html', context)
def post(request): def create_order(request):
attempt = SoftwareSecurePhotoVerification(user=request.user) attempt = SoftwareSecurePhotoVerification(user=request.user)
attempt.status = "pending" attempt.status = "pending"
attempt.save() 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): def show_requirements(request):
......
...@@ -264,9 +264,10 @@ ...@@ -264,9 +264,10 @@
<div class="actions"> <div class="actions">
<ul> <ul>
<li class="action action-next"> <li class="action action-next">
<form method="post"> <form method="post" action="create_order">
<!-- <a href="#">Go to Step 4: Secure Payment</a> --> <!-- <a href="#">Go to Step 4: Secure Payment</a> -->
<input type="hidden" name="csrfmiddlewaretoken" value="${ csrf_token }">
<input type="hidden" name="course_id" value="${course_id | h}" />
<input type="submit" value="Go to Step 4" name="payment"> <input type="submit" value="Go to Step 4" name="payment">
</form> </form>
<p class="tips">Once you verify your details match the requirements, you can move on to step 4, payment on our secure server.</p> <p class="tips">Once you verify your details match the requirements, you can move on to step 4, payment on our secure server.</p>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment