def payOffer(request):
    offer_id = int(request.POST['offer_id'])
    count = int(request.POST['count'])
    current_payment_id = dictOrEmpty(request.session, 'current_payment_id')
    if(current_payment_id):
        payment_services.forget_payment(int(current_payment_id))

    offer, payment = payment_services.generate_payment(offer_id, count, request.POST, request.user)

    request.session['current_payment_id'] = payment.id

    if(settings.PAYPAL_USE_SANDBOX):
        form_action = 'https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay'
    else:
        form_action = 'https://www.paypal.com/webapps/adaptivepayment/flow/pay'

    return render_to_response('core/waitPayment.html',
        {'offer' : offer,
        'paykey':payment.paykey,
        'form_action':form_action},
        context_instance = RequestContext(request))
def payOffer(request):
    offer_id = int(request.POST['offer_id'])
    count = int(request.POST['count'])
    current_payment_id = dictOrEmpty(request.session, 'current_payment_id')
    if (current_payment_id):
        payment_services.forget_payment(int(current_payment_id))

    offer, payment = payment_services.generate_payment(offer_id, count,
                                                       request.POST,
                                                       request.user)

    request.session['current_payment_id'] = payment.id

    if (settings.PAYPAL_USE_SANDBOX):
        form_action = 'https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay'
    else:
        form_action = 'https://www.paypal.com/webapps/adaptivepayment/flow/pay'

    return render_to_response('core/waitPayment.html', {
        'offer': offer,
        'paykey': payment.paykey,
        'form_action': form_action
    },
                              context_instance=RequestContext(request))