def get(self, request, *args, **kwargs): studentObj = getStudent(request) host = request.get_host() totalCost, allCourses = getCartCourses(request) kwargs["tcost"] = totalCost kwargs["cartCourses"] = allCourses paypal_dict = { 'business': settings.PAYPAL_RECEIVER_EMAIL, 'amount': totalCost, 'item_name': "Courses Enrolled", 'invoice': "Invoice for " + str(request.user.name), 'currency_code': 'USD', 'notify_url': '{}://{}{}'.format(request.scheme, host, reverse('paypal-ipn')), 'return_url': '{}://{}{}'.format(request.scheme, host, reverse('payments:done')), 'cancel_return': '{}://{}{}'.format(request.scheme, host, reverse('payments:canceled')), } form = PayPalPaymentsForm(initial=paypal_dict) kwargs["form"] = form return super().get(request, *args, **kwargs)
def payment_canceled(request): studentObj = getStudent(request) cartObjs = models.Cart.objects.filter(student_id=studentObj.id).filter( checkout=True) for obj in cartObjs: obj.checkout = False obj.save() return render(request, 'payment/canceled.html')
def payment_done(request): studentObj = getStudent(request) cartObjs = models.Cart.objects.filter(student_id=studentObj.id).filter( checkout=True) for obj in cartObjs: enrolledCourseObj = course.models.EnrolledCourse() enrolledCourseObj.student = studentObj enrolledCourseObj.course = course.models.Course.objects.filter( id=obj.course_id)[0] enrolledCourseObj.save() obj.delete() return render(request, 'payment/done.html')
def get(self, request, id, *args, **kwargs): refered_url = get_referer_view(request) if refered_url is None: return redirect("home") courseid = id studentObj = getStudent(request) if studentObj: add_to_cart(studentObj, courseid) # check the source from where add to cart is called if 'course' in refered_url and 'coursePage' in refered_url: url = "course:coursePage" return redirect(url, courseid) url = "home" return redirect(url)
def post(self, request, *args, **kwargs): if request.user.is_staff: raise Http404() if not settings.COURSE_ENROLLING_ALLOWED: return render(request, 'join_block.html') studentObj = getStudent(request) cartObjs = models.Cart.objects.filter(student_id=studentObj.id) coursesStr = '' for cartObj in cartObjs: cartObj.checkout = True cartObj.save() #coursesStr = coursesStr + " " + str(cartObj.course_id) #query_dictionary = QueryDict('', mutable=True) #query_dictionary.update({'id': coursesStr}) #url = '{base_url}?{querystring}'.format(base_url=reverse("payments:process"), # querystring=query_dictionary.urlencode()) url = "payments:process" return redirect(url)
def get(self, request, id, *args, **kwargs): refered_url = get_referer_view(request) if refered_url is None: return redirect("home") courseid = id studentObj = getStudent(request) cartCnt = -1 if studentObj: cartCnt = delete_from_cart(studentObj, courseid) # check the source from where delete from cart is called if 'course' in refered_url and 'coursePage' in refered_url: url = "course:coursePage" return redirect(url, courseid) elif 'payment' in refered_url and cartCnt > 0: if 'cart' in refered_url: url = "payments:my_cart" elif 'process' in refered_url: url = "payments:process" else: url = "home" return redirect(url)