コード例 #1
0
ファイル: views.py プロジェクト: amit1870/studentscorner
def show_checkout(request, template_name='checkout/checkout.html'):
	page_title = 'Checkout'
	
	if cart.is_empty(request):
		cart_url = urlresolvers.reverse('cart:show_cart')
		return HttpResponseRedirect(cart_url)

	if request.method == 'POST':
		postdata = request.POST.copy()
		form = CheckoutForm(postdata)
		print "comm"
		if form.is_valid():
			print "formvalid"
			response = checkout.process(request)
			order_number = response.get('order_number',0)
			error_message = response.get('message','')

			if order_number :
				request.session['order_number'] = order_number
				receipt_url = urlresolvers.reverse('checkout:receipt')
				return HttpResponseRedirect(receipt_url)
	else:
		if request.user.is_authenticated():
			user_profile = profile.retrieve(request)
			form = CheckoutForm(instance=user_profile)
		else:
			form = CheckoutForm()
	
	context = {'page_title':page_title, 'form':form}
	return render(request,template_name, context)
コード例 #2
0
ファイル: views.py プロジェクト: c-j-j/ecomstore
def show_checkout(request, template_name="checkout/checkout.html"):
    if cart.is_empty(request):
        cart_url = urlresolvers.reverse('show_cart')
        return HttpResponseRedirect(cart_url)

    error_message = ''
    if request.method == 'POST':
        form = CheckoutForm(request.POST)
        if form.is_valid():
            response = checkout.process(request)
            order_number = response.get('order_number', 0)
            error_message = response.get('message', '')
            if order_number:
                request.session['order_number'] = order_number
                receipt_url = urlresolvers.reverse('checkout_receipt')
                return HttpResponseRedirect(receipt_url)
        else:
            error_message = 'Correct the errors below'
    else:
        if request.user.is_authenticated():
            user_profile = profile.retrieve(request)
            form = CheckoutForm(instance=user_profile)
        else:
            form = CheckoutForm()
    ctx_dict = {
        'error_message': error_message,
        'form': form,
        'page_title': 'Checkout',
    }
    return render_to_response(template_name, ctx_dict, context_instance=RequestContext(request))
コード例 #3
0
ファイル: views.py プロジェクト: Pythonian/ecomstore
def show_checkout(request):
    """ checkout form page to collect user shipping and billing information """
    if cart.is_empty(request):
        return redirect('show_cart')
    error_message = ''
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        if form.is_valid():
            # If form is valid, pass along the request to the process checkout
            response = checkout.process(request)
            order_number = response.get('order_number', 0)
            error_message = response.get('message', '')
            if order_number:
                # If order number was valid, redirect user to the receipt page.
                # Store User's order number in the user's session for later use
                request.session['order_number'] = order_number
                return redirect('checkout_receipt')
        else:
            error_message = 'Correct the errors below'
    else:
        if request.user.is_authenticated:
            user_profile = profile.retrieve(request)
            form = CheckoutForm(instance=user_profile)
        else:
            form = CheckoutForm()
    page_title = 'Checkout'
    template_name = 'checkout/checkout.html'
    context = {
        'page_title': page_title,
        'form': form,
        'error_message': error_message
    }
    return render(request, template_name, context)
コード例 #4
0
ファイル: views.py プロジェクト: Mwamitovi/ecomstore
def show_checkout(request, template_name):
    """ checkout form page to collect user shipping and billing information """
    if cart.is_empty(request):
        cart_url = reverse('cart:show_cart')
        return HttpResponseRedirect(cart_url)

    if request.method == 'POST':
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        if form.is_valid():
            response = checkout.process(request)
            order_number = response.get('order_number', 0)
            error_message = response.get('message', '')
            if order_number:
                request.session['order_number'] = order_number
                receipt_url = reverse('checkout:checkout_receipt')
                return HttpResponseRedirect(receipt_url)
        else:
            error_message = 'Please correct the errors below'
    else:
        if request.user.is_authenticated():
            user_p = profile.retrieve(request)
            form = CheckoutForm(instance=user_p)
        else:
            form = CheckoutForm()
    page_title = 'Checkout'

    return render(request, template_name, locals(),
                  RequestContext(request, processors=[context_processors]))
コード例 #5
0
def show_checkout(request, template_name='checkout/checkout.html'):
    page_title = 'Checkout'

    if cart.is_empty(request):
        cart_url = urlresolvers.reverse('cart:show_cart')
        return HttpResponseRedirect(cart_url)

    if request.method == 'POST':
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        print "comm"
        if form.is_valid():
            print "formvalid"
            response = checkout.process(request)
            order_number = response.get('order_number', 0)
            error_message = response.get('message', '')

            if order_number:
                request.session['order_number'] = order_number
                receipt_url = urlresolvers.reverse('checkout:receipt')
                return HttpResponseRedirect(receipt_url)
    else:
        if request.user.is_authenticated():
            user_profile = profile.retrieve(request)
            form = CheckoutForm(instance=user_profile)
        else:
            form = CheckoutForm()

    context = {'page_title': page_title, 'form': form}
    return render(request, template_name, context)
コード例 #6
0
ファイル: views.py プロジェクト: thorrak/pyment
def show_checkout(request, template_name='checkout/checkout.djhtml'):
    if cart.is_empty(request):
        cart_url = urlresolvers.reverse('show_cart')
        return HttpResponseRedirect(cart_url)
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        if form.is_valid():
            response = checkout.process(request)
            order_number = response.get('order_number', 0)
            error_message = response.get('message', '')
            if order_number:
                request.session['order_number'] = order_number
                receipt_url = urlresolvers.reverse('checkout_receipt')
                return HttpResponseRedirect(receipt_url)
        else:
            error_message = 'Correct the errors below'
    else:
        if request.user.is_authenticated():
            user_profile = profile.retrieve(request)
            form = CheckoutForm(instance=user_profile)
        else:
            form = CheckoutForm()
    page_title = 'Checkout'
    return render(request, template_name, locals())
コード例 #7
0
def show_checkout(request , template_name = "checkout/checkout.html" ):
    if cart.is_empty(request):
        cart_url = urlresolvers.reverse('show_cart')
        return HttpResponseRedirect(cart_url)
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        if form.is_valid():
            response = process1(request)
            order_number = response.get('order_number',0)
            if order_number:
                request.session['order_number'] = order_number
                receipt_url = urlresolvers.reverse('payment')
                return HttpResponseRedirect(receipt_url)
        else:
            error_message = 'Correct the errors below'
    else:
        if request.user.is_authenticated():
            user_profile = profile.retrieve(request)
            form = CheckoutForm(instance = user_profile)
        else:
            form = CheckoutForm()

    page_title = 'Checkout'
    return render_to_response(template_name , locals(),context_instance = RequestContext(request))
コード例 #8
0
def show_checkout(request, template_name="checkout/checkout.html"):
    if cart.is_empty(request):
        cart_url = reverse("cart:show_cart")
        return HttpResponseRedirect(cart_url)
    if request.method == "POST":
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        if form.is_valid():
            response = checkout.process(request)
            order_number = response.get("order_number", 0)
            error_message = response.get("message", "")
            if order_number:
                request.session["order_number"] = order_number
                receipt_url = reverse("checkout:checkout_receipt")
                return HttpResponseRedirect(receipt_url)
        else:
            error_message = "Correct the errors below"
    else:
        if request.user.is_authenticated:
            user_profile = profile.retrieve(request)
            form = CheckoutForm(instance=user_profile)
        else:
            form = CheckoutForm()
    page_title = "Checkout"
    return render(request, template_name, locals())
コード例 #9
0
ファイル: views.py プロジェクト: shivam1111/ecomstore
def show_checkout(request, template_name='checkout/checkout.html'):
    if cart.is_empty(request):
        cart_url = urlresolvers.reverse('show_cart')
        return HttpResponseRedirect(cart_url)
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        if form.is_valid(): 
            response = checkout.process(request)
            if postdata.get('payment_method',False) == "credit_card":
                order_number = response.get('order_number',0)
                error_message = response.get('message','')   
                if order_number:
                    request.session['order_number'] = order_number
                    receipt_url = urlresolvers.reverse('checkout_receipt')
                    return HttpResponseRedirect(receipt_url)  
            if postdata.get('payment_method',False) == "paypal":
                if response:
                    order_number = response.get('order_number',0)
                    error_message = response.get('message','')   
                    request.session['order_number'] = order_number
                    approval_link = response.get('approval_link',False)
                    return HttpResponseRedirect(approval_link[0].get('href',"."))
                else:
                    pass
        else:
            error_message = 'Correct the errors below'
    else:
        if request.user.is_authenticated(): 
            user_profile = profile.retrieve(request)
            form = CheckoutForm(instance=user_profile)
        else:
            form = CheckoutForm()
    page_title = 'Checkout'
    return render_to_response(template_name, locals(), context_instance=RequestContext(request)) 
コード例 #10
0
def show_checkout(request,
                  checkout_type,
                  template_name="checkout/checkout.html"):
    print(request.GET.copy())
    # request1 = locals()
    # print(request1)
    print('ian')
    print(request)
    if cart.is_empty(request):
        cart_url = reverse('show_cart')
        return HttpResponseRedirect(cart_url)
    if request.method == 'POST' and request.POST.copy(
    )['submit'] == "Mpesa Payment":
        postdata = request.POST.copy()
        form = MpesaCheckoutForm(postdata)
        if form.is_valid():
            response = mpesa_processor.process(request)
            order_number = response.get('order_number', 0)
            error_message = response.get('message', '')
            if order_number:
                request.session['order_number'] = order_number
                receipt_url = reverse('checkout_receipt')
                CART_ID_SESSION_KEY = cart.CART_ID_SESSION_KEY
                pending = PendingMpesa.objects.filter(
                    cart=request.session[CART_ID_SESSION_KEY])
                pending.delete()
                return HttpResponseRedirect(receipt_url)
        else:
            error_message = "Correct the errors below"
    if request.method == 'POST' and request.POST.copy(
    )['submit'] == "Place Order":
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        if form.is_valid():
            response = checkout.process(request)
            order_number = response.get('order_number', 0)
            error_message = response.get('message', '')
            if order_number:
                request.session['order_number'] = order_number
                receipt_url = reverse('checkout_receipt')
                return HttpResponseRedirect(receipt_url)
        else:
            error_message = 'Correct the errors below'
    else:
        if request.user.is_authenticated:
            user_profile = profile.retrieve(request)
            form = CheckoutForm(instance=user_profile)
        else:
            form = CheckoutForm()
    page_title = 'Checkout'
    if request.method == 'POST' and checkout_type == "Lipa":
        postdata = request.POST.copy()
        form = MpesaCheckoutForm(postdata)
    if request.GET and checkout_type == "Lipa":
        form = MpesaCheckoutForm()
    checkout_type = checkout_type
    return render(request, template_name, locals(), RequestContext(request))
コード例 #11
0
ファイル: views.py プロジェクト: mathuin/pyment
def order_info(request, template_name="registration/order_info.html"):
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = UserProfileForm(postdata)
        if form.is_valid():
            profile.fill(request)
            url = reverse('accounts:my_account')
            return HttpResponseRedirect(url)
    else:
        user_profile = profile.retrieve(request)
        form = UserProfileForm(instance=user_profile)
    page_title = 'Edit Order Information'
    return render(request, template_name, locals())
コード例 #12
0
ファイル: views.py プロジェクト: osamwelian3/ecomstore2
def order_info(request, template_name="registration/order_info.html"):
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = UserProfileForm(postdata)
        if form.is_valid():
            profile.set(request)
            url = reverse('my_account')
            return HttpResponseRedirect(url)
    else:
        user_profile = profile.retrieve(request)
        form = UserProfileForm(instance=user_profile)
    page_title = 'Edit Order Information'
    return render(request, template_name, locals(), RequestContext(request))
コード例 #13
0
def order_info(request, template_name="accounts/order_info.html"):
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = UserProfileForm(postdata)
        if form.is_valid():
            profile.set(request)
            url = urlresolvers.reverse('my_account')
            return HttpResponseRedirect(url)
    else:
        user_profile = profile.retrieve(request)
        form = UserProfileForm(instance=user_profile)
    page_title = 'Edit Order Information'
    return render_to_response(template_name, locals(),
            context_instance=RequestContext(request))
コード例 #14
0
ファイル: views.py プロジェクト: ViktorOgnev/tradenplay
def order_info(request, template_name="registration/order_info.html"):
    if request.method == "POST":
        postdata = request.POST.copy()
        form = UserProfileForm(postdata)
        if form.is_valid():
            profile.set(request)
            url = urlresolvers.reverse('my_account')
            return HttpResponseRedirect(url)
    else:
        user_profile = profile.retrieve(request)
        form = UserProfileForm(instance=user_profile)
    page_title = _("Edit order information")
    context = locals()
    context.update(csrf(request))
    return render_to_resonse(template_name, context,
                             context_instance=RequestContext(request))
コード例 #15
0
def order_info(request, template_name="registration/order_info.html"):
    """
    page containing a form that allows a customer to edit their billing and shipping information that
    will be displayed in the order form next time they are logged in and go to check out
    """
    if request.method == 'POST':
        post_data = request.POST.copy()
        form = UserProfileForm(post_data)
        if form.is_valid():
            profile.set(request)
            url = urlresolvers.reverse('accounts:my_account')
            return HttpResponseRedirect(url)
    else:
        user_profile = profile.retrieve(request)
        form = UserProfileForm(instance=user_profile)
    page_title = 'Edit Order Information'

    return render(request, template_name, locals())
コード例 #16
0
ファイル: views.py プロジェクト: shivam1111/ecomstore
def show_checkout(request, template_name='checkout/checkout.html'):
    if cart.is_empty(request):
        cart_url = urlresolvers.reverse('show_cart')
        return HttpResponseRedirect(cart_url)
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        if form.is_valid():
            response = checkout.process(request)
            if postdata.get('payment_method', False) == "credit_card":
                order_number = response.get('order_number', 0)
                error_message = response.get('message', '')
                if order_number:
                    request.session['order_number'] = order_number
                    receipt_url = urlresolvers.reverse('checkout_receipt')
                    return HttpResponseRedirect(receipt_url)
            if postdata.get('payment_method', False) == "paypal":
                if response:
                    order_number = response.get('order_number', 0)
                    error_message = response.get('message', '')
                    request.session['order_number'] = order_number
                    approval_link = response.get('approval_link', False)
                    return HttpResponseRedirect(approval_link[0].get(
                        'href', "."))
                else:
                    pass
        else:
            error_message = 'Correct the errors below'
    else:
        if request.user.is_authenticated():
            user_profile = profile.retrieve(request)
            form = CheckoutForm(instance=user_profile)
        else:
            form = CheckoutForm()
    page_title = 'Checkout'
    return render_to_response(template_name,
                              locals(),
                              context_instance=RequestContext(request))
コード例 #17
0
ファイル: views.py プロジェクト: rizwanoffice/books
def show_checkout(request):
    error_message = ''
    if cart.is_empty(request):
        cart_url = reverse('show_cart')
        return HttpResponseRedirect(cart_url)

    if request.method == 'POST':
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        order_number = request.session.get('order_number', '')

        if form.is_valid():
            response = checkout.process(request)
            order_number = response.get('order_number', 0)
            error_message = response.get('message', '')
            if order_number:
                request.session['order_number'] = order_number
                receipt_url = reverse('checkout_receipt')
                return HttpResponseRedirect(receipt_url)
        else:
            error_message = 'Correct the errors below'
    else:
        if request.user.is_authenticated:
            user_profile = profile.retrieve(request)
            form = CheckoutForm(instance=user_profile)
        else:
            form = CheckoutForm()

    page_title = 'Checkout'
    total = cart.cart_subtotal(request)
    template = 'checkout/checkout.html'
    context = {
        'page_title': page_title,
        'error_message': error_message,
        'form': form,
        'total': total,
    }
    return render(request, template, context)
コード例 #18
0
ファイル: views.py プロジェクト: osamwelian3/ecomstore
def show_checkout(request,
                  checkout_type,
                  template_name="checkout/checkout.html"):
    # print(request.POST.copy())
    # request1 = locals()
    # print(request1)
    print('ian')
    print(request.method)
    error_message = ''
    if cart.is_empty(request):
        cart_url = reverse('show_cart')
        return HttpResponseRedirect(cart_url)
    if request.method == 'POST' and request.POST.copy()['payment'] == "Mpesa Payment" or request.method == 'POST' and\
            request.POST.copy()['phone2'] != '' and request.POST.copy()['credit_card_number'] == '' and\
            request.POST.copy()['credit_card_cvv'] == '':
        postdata = request.POST.copy()
        postdata['billing_name'] = postdata['shipping_name']
        postdata['billing_address_1'] = postdata['shipping_address_1']
        postdata['billing_address_2'] = postdata['shipping_address_2']
        postdata['billing_city'] = postdata['shipping_city']
        postdata['billing_zip'] = postdata['shipping_zip']
        postdata['billing_country'] = postdata['shipping_country']
        postdata['payment'] = postdata['payment']
        form = CheckoutForm(postdata)
        if form.is_valid():
            response = mpesa_processor.process(request)
            order_number = response.get('order_number', 0)
            error_message = response.get('message', '')
            if order_number:
                request.session['order_number'] = order_number
                receipt_url = reverse('checkout_receipt')
                CART_ID_SESSION_KEY = cart.CART_ID_SESSION_KEY
                pending = PendingMpesa.objects.filter(
                    cart=request.session[CART_ID_SESSION_KEY])
                if pending.count() == 1:
                    pending.delete()
                return HttpResponseRedirect(receipt_url)
        else:
            error_message = "Correct the errors below"
    if request.method == 'POST' and request.POST.copy()['payment'] == "Place Order" or request.method == 'POST' and\
            request.POST.copy()['credit_card_number'] != '' and request.POST.copy()['credit_card_cvv'] != '' and\
            request.POST.copy()['phone2'] == '':
        postdata = request.POST.copy()
        if 'billing' in request.POST.copy():
            if postdata['billing_name'] == '':
                error_message = 'Input billing name'
            if postdata['billing_address_1'] == '':
                error_message = 'Input billing address'
            if postdata['billing_city'] == '':
                error_message = 'Input billing city'
            if postdata['billing_zip'] == '':
                error_message = 'Input billing zip/postal code'
            if postdata['billing_country'] == '':
                error_message = 'Input billing country'
        if not 'billing' in request.POST.copy():
            postdata['billing_name'] = postdata['shipping_name']
            postdata['billing_address_1'] = postdata['shipping_address_1']
            postdata['billing_address_2'] = postdata['shipping_address_2']
            postdata['billing_city'] = postdata['shipping_city']
            postdata['billing_zip'] = postdata['shipping_zip']
            postdata['billing_country'] = postdata['shipping_country']
        form = CheckoutForm(postdata)
        # print(postdata)
        # print(form)
        # print("frm")
        if form.is_valid():
            response = checkout.process(request)
            order_number = response.get('order_number', 0)
            error_message = response.get('message', '')
            if order_number:
                request.session['order_number'] = order_number
                receipt_url = reverse('checkout_receipt')
                return HttpResponseRedirect(receipt_url)
        else:
            error_message = 'Correct the errors below'
    else:
        if request.user.is_authenticated:
            user_profile = profile.retrieve(request)
            form = CheckoutForm(instance=user_profile)
        else:
            form = CheckoutForm()
            """if request.method == 'GET' and checkout_type != 'Lipa' and checkout_type != 'PendingLipa':
                form = CheckoutForm(instance=user_profile)
            if request.method == 'POST' and checkout_type == "Lipa":
                postdata = request.POST.copy()
                form = MpesaCheckoutForm(postdata)
            if request.GET and checkout_type == "Lipa":
                form = MpesaCheckoutForm(instance=user_profile)
            if request.GET and checkout_type == "PendingLipa":
                form = MpesaCheckoutForm(instance=user_profile)"""

        if request.method == 'POST' and checkout_type == "Lipa":
            postdata = request.POST.copy()
            # print(postdata)
            form = CheckoutForm(postdata)
            # print(request.POST.copy()['payment'])
            if request.POST.copy()['payment'] == 'on' and postdata['phone2'] == '' and postdata['credit_card_number']\
                    == '' and postdata['credit_card_cvv'] == '':
                empty1 = 'Please select payment method'
                error_message = 'Correct the errors below'
            if request.POST.copy()['payment'] == 'on' and postdata['phone2'] != '' and postdata['credit_card_number']\
                    != '' or postdata['credit_card_cvv'] != '':
                empty1 = 'Please select payment method'
                error_message = 'Correct the errors below'
        if request.GET and checkout_type == "Lipa":
            form = CheckoutForm()
            """if request.method == 'POST' and checkout_type == "Lipa":
                postdata = request.POST.copy()
                form = MpesaCheckoutForm(postdata)
            if request.GET and checkout_type == "Lipa":
                form = MpesaCheckoutForm()
            if request.GET and checkout_type == "PendingLipa":
                form = MpesaCheckoutForm()"""
    page_title = 'Checkout'
    cart_items = cart.get_cart_items(request)
    cart_subtotal = cart.cart_subtotal(request)
    checkout_type = checkout_type
    return render(request, template_name, locals(), RequestContext(request))
コード例 #19
0
def create_order(request, transaction_id):
    postdata = request.POST.copy()
    CART_ID_SESSION_KEY = cart.CART_ID_SESSION_KEY
    pending = PendingMpesa.objects.filter(
        cart=request.session[CART_ID_SESSION_KEY])
    if request.user.is_authenticated:
        user_profile = profile.retrieve(request)
    else:
        user_profile = ''
    if pending.count(
    ) > 0 and request.user.is_authenticated and not request.method == 'POST' and user_profile.shipping_name != '':
        user_profile = profile.retrieve(request)
        print(user_profile.shipping_name)
        order = Order()
        # checkout_form = MpesaCheckoutForm(instance=order)
        # order = checkout_form.save(commit=False)
        order.shipping_name = user_profile.shipping_name
        order.shipping_address_1 = user_profile.shipping_address_1
        order.shipping_address_2 = user_profile.shipping_address_2
        order.shipping_city = user_profile.shipping_city
        order.shipping_zip = user_profile.shipping_zip
        order.shipping_country = user_profile.shipping_country
        order.transaction_id = transaction_id
        order.ip_address = request.META.get('REMOTE_ADDR')
        order.user = None
        if request.user.is_authenticated:
            order.user = request.user
        order.status = Order.SUBMITTED
        order.save()
    else:
        order = Order()
        checkout_form = MpesaCheckoutForm(request.POST, instance=order)
        order = checkout_form.save(commit=False)
        order.billing_name = postdata['shipping_name']
        order.billing_address_1 = postdata['shipping_address_1']
        order.billing_address_2 = postdata['shipping_address_2']
        order.billing_city = postdata['shipping_city']
        order.billing_zip = postdata['shipping_zip']
        order.billing_country = postdata['shipping_country']
        order.transaction_id = transaction_id
        order.ip_address = request.META.get('REMOTE_ADDR')
        order.user = None
        if request.user.is_authenticated:
            order.user = request.user
        order.status = Order.SUBMITTED
        order.save()
    # if the order save succeeded
    if order.pk:
        cart_items = cart.get_cart_items(request)
        for ci in cart_items:
            # create order item for each cart item
            oi = OrderItem()
            oi.order = order
            oi.quantity = ci.quantity
            oi.price = ci.price  # now using @property
            oi.product = ci.product
            oi.save()
        # all set, empty cart
        cart.empty_cart(request)
        # save profile info for future orders
        if request.user.is_authenticated and not pending_checker(request) == 0:
            profile.set(request)
    # return the new order object
    return order