def generate_payment(offer_id, receiver_count, dict, user):
    offer = Offer.objects.get(pk=offer_id)
    if(offer.status == Offer.PAID):
        raise BaseException('offer %s is already paid' % offer.id + '. User %s' % user)
    payment = Payment.newPayment(offer)
    parts = []
    sum = Decimal(0)
    realSum = Decimal(0)
    for i in range(receiver_count):
        check = dict.has_key('check_%s' % i)
        if(check):
            solution = Solution.objects.get(pk=int(dict['solutionId_%s' % i]))
            pay = Decimal(dict['pay_%s' % i])
            realPay = Decimal(pay * Decimal(1 - settings.FS_FEE))
            part = PaymentPart.newPart(payment, solution.programmer, pay, realPay)
            parts.append(part)
            sum += pay
            realSum += realPay
    payment.fee = sum - realSum
    payment.total = sum
    payment.save()
    for part in parts:
        part.payment = payment
        part.save()
    generate_paypal_payment(payment)
    payment.save()
    return offer, payment
def payOffer(request, offer, payment):
    current_payment_id = dictOrEmpty(request.session, 'current_payment_id')
    if(current_payment_id):
        paypal_services.forget_payment(int(current_payment_id))

    paypal_adapter.generate_paypal_payment(payment)
    payment.save()

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

    if(settings.PAYPAL_USE_SANDBOX):
        # form_action = 'https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay'
        redirect_url = 'https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=%s' % payment.paykey
    else:
        # form_action = 'https://www.paypal.com/webapps/adaptivepayment/flow/pay'
        redirect_url = 'https://www.paypal.com/webscr?cmd=_ap-payment&paykey=%s' % payment.paykey
    return redirect(redirect_url)
def payOffer(request, offer, payment):
    current_payment_id = dictOrEmpty(request.session, 'current_payment_id')
    if(current_payment_id):
        paypal_services.forget_payment(int(current_payment_id))

    try:
        paypal_adapter.generate_paypal_payment(payment)
    except BaseException as e:
        traceback.print_exc()
        messages.error(request, 'Error communicating with Paypal: %s' % e)
        mail_services.notify_admin('Error generating paypal payment', traceback.format_exc())
        return redirect(offer.get_view_link())
    payment.save()

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

    if(settings.PAYPAL_USE_SANDBOX):
        # form_action = 'https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay'
        redirect_url = 'https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=%s' % payment.paykey
    else:
        # form_action = 'https://www.paypal.com/webapps/adaptivepayment/flow/pay'
        redirect_url = 'https://www.paypal.com/webscr?cmd=_ap-payment&paykey=%s' % payment.paykey
    return redirect(redirect_url)
Beispiel #4
0
def payOffer(request, offer, payment):
    current_payment_id = request.session.get('current_payment_id')
    if (current_payment_id):
        paypal_services.forget_payment(int(current_payment_id))

    try:
        paypal_adapter.generate_paypal_payment(payment)
    except BaseException as e:
        traceback.print_exc()
        messages.error(request, 'Error communicating with Paypal: %s' % e)
        mail_services.notify_admin('Error generating paypal payment',
                                   traceback.format_exc())
        return redirect(offer.get_view_link())
    payment.save()

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

    if settings.PAYPAL_USE_SANDBOX:
        # form_action = 'https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay'
        redirect_url = 'https://www.sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=%s' % payment.paykey
    else:
        # form_action = 'https://www.paypal.com/webapps/adaptivepayment/flow/pay'
        redirect_url = 'https://www.paypal.com/webscr?cmd=_ap-payment&paykey=%s' % payment.paykey
    return redirect(redirect_url)