Пример #1
0
def checkout(request):
    if request.method == 'POST':
        order_form = OrderForm(request.POST)
        if order_form.is_valid():
            initial = order_form.cleaned_data
            initial.update({'key': settings.PAYU_INFO['merchant_key'],
                            'surl': request.build_absolute_uri(reverse('order.success')),
                            'furl': request.build_absolute_uri(reverse('order.success')),
                            'curl': request.build_absolute_uri(reverse('order.cancel'))})
            # Once you have all the information that you need to submit to payu
            # create a payu_form, validate it and render response using
            # template provided by PayU.
            payu_form = PayUForm(initial)
            if payu_form.is_valid():
                context = {'form': payu_form,
                           'action': "%s_payment" % settings.PAYU_INFO['payment_url']}
                return render(request, 'payu_form.html', context)
            else:
                logger.error('Something went wrong! Looks like initial data\
                        used for payu_form is failing validation')
                return HttpResponse(status=500)
    else:
        initial = {'txnid': uuid4().hex,
                'productinfo': lorem_ipsum(),
                'amount': randint(100, 1000)/100.0}
        order_form = OrderForm(initial=initial)
    context = {'form': order_form}
    return render(request, 'checkout.html', context)
def checkout(request):
    if request.method == 'POST':
        order_form = OrderForm(request.POST)
        if order_form.is_valid():

            initial = order_form.cleaned_data
            print(initial['amount'])
            payu_hash = sha512(
                str(settings.PAYU_INFO['merchant_key'] + '|' +
                    initial["txnid"] + '|' + str(initial['amount']) + '|' +
                    initial["productinfo"] + '|' + initial["firstname"] + '|' +
                    initial["email"] + '|||||||||||' +
                    settings.PAYU_INFO["merchant_salt"]).encode(
                        'utf-8')).hexdigest()
            print(settings.PAYU_INFO['merchant_key'], initial['txnid'])
            print(payu_hash)
            initial.update({
                'key':
                settings.PAYU_INFO['merchant_key'],
                'hash':
                payu_hash,
                'surl':
                request.build_absolute_uri(reverse('order.success')),
                'furl':
                request.build_absolute_uri(reverse('order.failure')),
                'curl':
                request.build_absolute_uri(reverse('order.cancel'))
            })
            # Once you have all the information that you need to submit to payu
            # create a payu_form, validate it and render response using
            # template provided by PayU.
            payu_form = PayUForm(initial)
            if payu_form.is_valid():
                context = {
                    'form': payu_form,
                    'action': "%s_payment" % settings.PAYU_INFO['payment_url']
                }
                return render(request, 'payu_form.html', context)
            else:
                logger.error('Something went wrong! Looks like initial data\
                        used for payu_form is failing validation')
                return HttpResponse(status=500)
    else:
        initial = {
            'txnid': uuid4().hex,
            'productinfo': "Home",
            'amount': randint(100, 1000) / 100.0
        }
        order_form = OrderForm(initial=initial)
    context = {'form': order_form}
    return render(request, 'checkout.html', context)
Пример #3
0
def checkout(request):
    if request.method == 'POST':
        order_form = OrderForm(request.POST)
        if order_form.is_valid():
            user = request.user
            user = User.objects.get(username=user)
            initial = order_form.cleaned_data
            initial.update({
                'key':
                settings.PAYU_INFO['merchant_key'],
                'surl':
                request.build_absolute_uri(reverse('order:success')),
                'furl':
                request.build_absolute_uri(reverse('order:success')),
                'service_provider':
                'payu_paisa',
                'firstname':
                user.first_name,
                'email':
                user.email,
                'curl':
                request.build_absolute_uri(reverse('order:cancel'))
            })
            # Once you have all the information that you need to submit to payu
            # create a payu_form, validate it and render response using
            # template provided by PayU.
            initial.update({'hash': generate_hash(initial)})
            payu_form = PayUForm(initial)

            if payu_form.is_valid():
                context = {
                    'form': payu_form,
                    'action': "%s" % settings.PAYU_INFO['payment_url']
                }
                return render(request, 'payu_form.html', context)
            else:
                logger.error('Something went wrong! Looks like initial data\
                        used for payu_form is failing validation')
                return HttpResponse(status=500)
    else:
        initial = {
            'txnid': uuid4().hex,
            'productinfo': 'package',
            'amount': randint(100, 1000) / 100.0
        }
        order_form = OrderForm(initial=initial)
    context = {'form': order_form}
    return render(request, 'checkout.html', context)
Пример #4
0
def checkout(request,name):
    user=request.user
    try:
        profile=Profile.objects.get(user=user)
    except:
          profile=Profile()
    try:
        rob=roboreg.objects.get(user=user)
    except:
        rob=roboreg()






    if rob.payment_status=='failure':
            if request.user.is_authenticated():
                    if request.method == 'POST':
                            cntxt = {'username': request.user.first_name + ' ' + request.user.last_name, 'cityname': name}
                            city_name = name
                            if not roboreg.objects.filter(user=request.user, city=name).exists():
                                timenow = datetime.datetime.now()
                                robo_reg = roboreg.objects.create(user=request.user, city=city_name, time_work=timenow)
                                robo_reg.firstname=request.user.first_name
                                robo_reg.lastname=request.user.last_name
                                robo_reg.contact=profile.contact
                                robo_reg.save()





                            order_form = OrderForm(request.POST)
                            if order_form.is_valid():
                                            initial = order_form.cleaned_data
                                            initial.update({'key': settings.PAYU_INFO['merchant_key'],
                                                            'surl': request.build_absolute_uri(reverse('order.success')),
                                                            'furl': request.build_absolute_uri(reverse('order.failure')),
                                                            'curl': request.build_absolute_uri(reverse('order.cancel'))})
                                            # Once you have all the information that you need to submit to payu
                                            # create a payu_form, validate it and render response using
                                            # template provided by PayU.
                                            payu_form = PayUForm(initial)
                                            if payu_form.is_valid():
                                                context = {'form': payu_form,
                                                           'hash_form': HashForm({'hash': generate_hash(payu_form.cleaned_data)}),
                                                           'action': "%s" % settings.PAYU_INFO['payment_url']}
                                                return render(request, 'payu_form.html', context)
                                            else:
                                                return HttpResponse(status=500)
                    else:
                                        initial = {'txnid': uuid4().hex,
                                                   'productinfo': 'Workshop ticket',
                                                   'amount': 400,
                                                   'firstname':request.user.first_name,
                                                   'lastname':request.user.last_name,
                                                   'email':request.user.email,
                                                    'phone':profile.contact,
                                                    'address1':profile.address,
                                                   'address2':profile.address,
                                                    'city':name,
                                                    'state':profile.state,
                                                    'country':profile.country,
                                                   'service_provider':'payu_paisa',

                                                   }
                                        order_form = OrderForm(initial=initial)
                    context = {'form': order_form}
                    return render(request, 'checkout.html', context)
            else:
                return redirect('/accounts/msignin')
    else:
        return render_to_response('success1.html',
                              RequestContext(request, { "status": 'success','txnid':rob.txnid, 'city':name}, ))