예제 #1
0
def handlerequest(request):
    cart_prods = [p for p in Cart.objects.all() if p.user == request.user]
    # paytm will send you post request here
    form = request.POST
    response_dict = {}
    for i in form.keys():
        response_dict[i] = form[i]
        if i == 'CHECKSUMHASH':
            checksum = form[i]

    verify = Checksum.verify_checksum(response_dict, MERCHANT_KEY, checksum)
    if verify:
        if response_dict['RESPCODE'] == '01':
            for item in cart_prods:
                order_id = 'ordr' + str((Orders.objects.all().last().pk) + 1)
                o_id = order_id
                product1 = item.product_id + '|' + str(item.number) + ','
                Orders(order_id=order_id, user=request.user,
                       saler=Product.objects.filter(product_id=int(item.product_id)).first().shop, products=product1,
                       size=item.product_size).save()
                item.delete()
                if int(item.product_id) in trends:
                    t = trend.objects.filter(product=Product.objects.filter(product_id=int(item.product_id)).first())[0]
                    t.number += 1
                    t.save()
                else:
                    trend(product=Product.objects.filter(product_id=int(item.product_id)).first(), number=1).save()
            print('order successful')
        else:
            print('order was not successful because' + response_dict['RESPMSG'])
    return render(request, 'main/paymentstatus.html', {'response': response_dict})
예제 #2
0
def checkout(request):
    temp = 0
    allProds = []
    cart_prods = [p for p in Cart.objects.all() if p.user == request.user]
    for cprod in cart_prods:
        prod = Product.objects.filter(product_id=cprod.product_id)[0]
        allProds.append([cprod, prod])
    if request.method == 'POST':
        address_form = UserAddressForm(request.POST, instance=request.user.userdetail)
        u_form2 = UserAddressForm1(request.POST, instance=request.user)
        if address_form.is_valid() and u_form2.is_valid():
            address_form.save()
            u_form2.save()
            pay_mode = request.POST.get('pay_mode')
            trends = [i.product.product_id for i in trend.objects.all()]
            # 			print(order)
            if pay_mode == 'on':
                for item in cart_prods:
                    if Orders.objects.all().last():
                        order_id = 'ordr' + str((Orders.objects.all().last().pk) + 1)
                    else:
                        order_id = 'ordr001'
                    product1 = item.product_id + '|' + str(item.number) + ','
                    Orders(order_id=order_id, user=request.user,
                           saler=Product.objects.filter(product_id=int(item.product_id)).first().shop,
                           products=product1, size=item.product_size).save()
                    item.delete()
                    if int(item.product_id) in trends:
                        t = \
                            trend.objects.filter(
                                product=Product.objects.filter(product_id=int(item.product_id)).first())[0]
                        t.number += 1
                        t.save()
                    else:
                        trend(product=Product.objects.filter(product_id=int(item.product_id)).first(), number=1).save()
                return redirect('/myorders')
            else:
                temp = 1
    else:
        address_form = UserAddressForm(instance=request.user.userdetail)
        u_form2 = UserAddressForm1(instance=request.user)
    subtotal = 0.0
    delev = 0.0
    tax = 0.0
    for p in cart_prods:
        tempTotal = p.number * Product.objects.filter(product_id=p.product_id)[0].price
        subtotal += tempTotal
        tax += tempTotal * int(Product.objects.filter(product_id=p.product_id).first().gst) / 100

    if temp == 1:
        o_id = ''
        for item in cart_prods:
            order_id = 'ordr' + str((Orders.objects.all().last().pk) + 1)
            o_id = order_id
            product1 = item.product_id + '|' + str(item.number) + ','
            Orders(order_id=order_id, user=request.user,
                   saler=Product.objects.filter(product_id=int(item.product_id)).first().shop, products=product1,
                   size=item.product_size)

            if int(item.product_id) in trends:
                t = trend.objects.filter(product=Product.objects.filter(product_id=int(item.product_id)).first())[0]
                t.number += 1
                t.save()
            else:
                trend(product=Product.objects.filter(product_id=int(item.product_id)).first(), number=1)
        param_dict = {

            'MID': 'YOUR_MID',
            'ORDER_ID': str(o_id),
            'TXN_AMOUNT': str(subtotal + tax + delev),
            'CUST_ID': request.user.username,
            'INDUSTRY_TYPE_ID': 'Retail',
            'WEBSITE': 'WEBSTAGING',
            'CHANNEL_ID': 'WEB',
            'CALLBACK_URL': 'http://127.0.0.1:8000/handlerequest/',

        }
        param_dict['CHECKSUMHASH'] = Checksum.generate_checksum(param_dict, MERCHANT_KEY)
        return render(request, 'main/paytm.html', {'param_dict': param_dict})

    params = {
        'allProds': allProds,
        'cart_element_no': len(cart_prods),
        'address_form': address_form,
        'u_form': u_form2,
        'total': subtotal + tax + delev,
        'category': category.objects.all(),
    }
    return render(request, 'main/checkout.html', params)
예제 #3
0
def order_now(request):
    allProds = []
    if request.method == 'GET':
        new_prod = request.GET.get('prod_id')
        prod_size = request.GET.get('prod_size')
        allProds = [[1, Product.objects.filter(product_id=int(new_prod))[0]]]
    if request.method == 'POST':
        new_prod = request.GET.get('prod_id')
        prod_size = request.GET.get('prod_size')
        address_form = UserAddressForm(request.POST, instance=request.user.userdetail)
        u_form2 = UserAddressForm1(request.POST, instance=request.user)
        if address_form.is_valid() and u_form2.is_valid():
            address_form.save()
            u_form2.save()
            pay_mode = request.POST.get('pay_mode')
            trends = [i.product.product_id for i in trend.objects.all()]
            # 			print(order)
            if pay_mode == 'on':
                if Orders.objects.all().last():
                    order_id = 'ordr' + str((Orders.objects.all().last().pk) + 1)
                else:
                    order_id = 'ordr001'
                product1 = new_prod + '|' + str(1) + ','
                Orders(order_id=order_id, user=request.user,
                       saler=Product.objects.filter(product_id=int(new_prod)).first().shop, products=product1,
                       size=prod_size).save()
                if int(new_prod) in trends:
                    t = trend.objects.filter(product=Product.objects.filter(product_id=int(new_prod)).first())[0]
                    t.number += 1
                    t.save()
                else:
                    trend(product=Product.objects.filter(product_id=int(new_prod)).first(), number=1).save()
                return redirect('/myorders')
            else:
                o_id = ''
                if Orders.objects.all().last():
                    order_id = 'ordr' + str((Orders.objects.all().last().pk) + 1)
                else:
                    order_id = 'ordr001'
                o_id = order_id
                product1 = new_prod + '|' + str(1) + ','
                Orders(order_id=order_id, user=request.user,
                       saler=Product.objects.filter(product_id=int(new_prod)).first().shop, products=product1,
                       size=prod_size).save()
                if int(new_prod) in trends:
                    t = trend.objects.filter(product=Product.objects.filter(product_id=int(new_prod)).first())[0]
                    t.number += 1
                    t.save()
                else:
                    trend(product=Product.objects.filter(product_id=int(new_prod)).first(), number=1).save()
                delev = 0.0
                subtotal = Product.objects.filter(product_id=int(new_prod)).first().price
                tax = subtotal * int(Product.objects.filter(product_id=int(new_prod)).first().gst) / 100

                param_dict = {

                    'MID': 'YOUR_MID',
                    'ORDER_ID': str(o_id),
                    'TXN_AMOUNT': str(subtotal + tax + delev),
                    'CUST_ID': request.user.username,
                    'INDUSTRY_TYPE_ID': 'Retail',
                    'WEBSITE': 'WEBSTAGING',
                    'CHANNEL_ID': 'WEB',
                    'CALLBACK_URL': 'http://127.0.0.1:8000/handlerequest/',

                }
                param_dict['CHECKSUMHASH'] = Checksum.generate_checksum(param_dict, MERCHANT_KEY)
                return render(request, 'main/paytm.html', {'param_dict': param_dict})

    else:
        address_form = UserAddressForm(instance=request.user.userdetail)
        u_form2 = UserAddressForm1(instance=request.user)
    delev = 0.0
    subtotal = Product.objects.filter(product_id=int(new_prod)).first().price
    tax = subtotal * int(Product.objects.filter(product_id=int(new_prod)).first().gst) / 100
    totl = round(subtotal + tax + delev, 2)
    params = {
        'allProds': allProds,
        'cart_element_no': len([p for p in Cart.objects.all() if p.user == request.user]),
        'address_form': address_form,
        'u_form': u_form2,
        'total': totl,
        'category': category.objects.all(),
    }
    return render(request, 'main/checkout2.html', params)