@require_POST
@login_required
def create_order(request):
 course_id = request.POST['course_id']
 course_id = CourseKey.from_string(course_id)
 donation_for_course = request.session.get('donation_for_course', {})
 contribution = request.POST.get('contribution', donation_for_course.get(unicode(course_id), 0))
 try:
  amount = decimal.Decimal(contribution).quantize(decimal.Decimal('.01'), rounding=decimal.ROUND_DOWN)
 except decimal.InvalidOperation:
  return HttpResponseBadRequest(_('Selected price is not valid number.'))
 current_mode = None
 sku = request.POST.get('sku', None)
 if sku:
  try:
   current_mode = CourseMode.objects.get(sku=sku)
  except CourseMode.DoesNotExist:
   log.exception(u'Failed to find CourseMode with SKU [%s].', sku)
 if (not current_mode):
  paid_modes = CourseMode.paid_modes_for_course(course_id)
  if paid_modes:
   if (len(paid_modes) > 1):
    log.warn(u"Multiple paid course modes found for course '%s' for create order request", course_id)
   current_mode = paid_modes[0]
 if (not current_mode):
  log.warn(u"Create order requested for course '%s' without a paid mode.", course_id)
  return HttpResponseBadRequest(_("This course doesn't support paid certificates"))
 if CourseMode.is_professional_mode(current_mode):
  amount = current_mode.min_price
 if (amount < current_mode.min_price):
  return HttpResponseBadRequest(_('No selected price or selected price is below minimum.'))
 if current_mode.sku:
  payment_data = checkout_with_ecommerce_service(request.user, course_id, current_mode, request.POST.get('processor'))
 else:
  payment_data = checkout_with_shoppingcart(request, request.user, course_id, current_mode, amount)
 if ('processor' not in request.POST):
  payment_data = payment_data['payment_form_data']
 return HttpResponse(json.dumps(payment_data), content_type='application/json')

@ require_POST @ login_required def create_order ( request ) : course_id = request . POST [ 'course_id' ] course_id = CourseKey . from_string ( course_id ) donation_for_course = request . session . get ( 'donation_for_course' , { } ) contribution = request . POST . get ( 'contribution' , donation_for_course . get ( unicode ( course_id ) , 0 ) ) try : amount = decimal . Decimal ( contribution ) . quantize ( decimal . Decimal ( '.01' ) , rounding = decimal . ROUND_DOWN ) except decimal . InvalidOperation : return HttpResponseBadRequest ( _ ( 'Selected price is not valid number.' ) ) current_mode = None sku = request . POST . get ( 'sku' , None ) if sku : try : current_mode = CourseMode . objects . get ( sku = sku ) except CourseMode . DoesNotExist : log . exception ( u'Failed to find CourseMode with SKU [%s].' , sku ) if ( not current_mode ) : paid_modes = CourseMode . paid_modes_for_course ( course_id ) if paid_modes : if ( len ( paid_modes ) > 1 ) : log . warn ( u"Multiple paid course modes found for course '%s' for create order request" , course_id ) current_mode = paid_modes [ 0 ] if ( not current_mode ) : log . warn ( u"Create order requested for course '%s' without a paid mode." , course_id ) return HttpResponseBadRequest ( _ ( "This course doesn't support paid certificates" ) ) if CourseMode . is_professional_mode ( current_mode ) : amount = current_mode . min_price if ( amount < current_mode . min_price ) : return HttpResponseBadRequest ( _ ( 'No selected price or selected price is below minimum.' ) ) if current_mode . sku : payment_data = checkout_with_ecommerce_service ( request . user , course_id , current_mode , request . POST . get ( 'processor' ) ) else : payment_data = checkout_with_shoppingcart ( request , request . user , course_id , current_mode , amount ) if ( 'processor' not in request . POST ) : payment_data = payment_data [ 'payment_form_data' ] return HttpResponse ( json . dumps ( payment_data ) , content_type = 'application/json' )
helper method for creating an order for testing .