def _payWithPaypalForm(request, offer):
    solutions_accepting_payments = offer.issue.getSolutionsAcceptingPayments()
    shared_price = None

    convert_rate = 1
    currency_symbol = "US$"
    alert_brazil = False
    if(offer.sponsor.getUserInfo().brazilianPaypal):
        convert_rate = paypal_services.usd_2_brl_convert_rate()
        currency_symbol = "R$"
        alert_brazil = True

    if(solutions_accepting_payments.count() > 0):
        shared_price = convert_rate * float(offer.price) / solutions_accepting_payments.count()
        shared_price = twoplaces(Decimal(str(shared_price)))

    return render_to_response('core/pay_offer.html',
        {'offer':offer,
         'solutions_accepting_payments' : solutions_accepting_payments,
         'shared_price' : shared_price,
         'convert_rate' : convert_rate,
         'currency_symbol' : currency_symbol,
         'alert_brazil' : alert_brazil,
         },
        context_instance = RequestContext(request))
def _payWithPaypalForm(request, offer):
    solutions_accepting_payments = offer.issue.getSolutionsAcceptingPayments()

    solutions_with_paypal = []
    solutions_without_paypal = []
    for solution in solutions_accepting_payments:
        try: 
            accepts_paypal = paypal_services.accepts_paypal_payments(solution.programmer)
        except BaseException as e:
            traceback.print_exc()
            messages.error(request, 'Error communicating with Paypal: %s' % e)
            mail_services.notify_admin('Error determining if user accepts paypal', traceback.format_exc())
            return redirect(offer.get_view_link())
        if accepts_paypal:
            solutions_with_paypal.append(solution)
        else:
            solutions_without_paypal.append(solution)

    if len(solutions_with_paypal) == 0:
        messages.error(request, "The programmer(s) who solved this issue do not have a verified Paypal account yet, so you cannot pay them at this time.\n"+
                                "Please leave a comment for them, asking them to update their profile page with an email of a verified Paypal account, then come back here again.")
        return redirect(offer.get_view_link())
    if len(solutions_without_paypal) > 0:
        names = ', '.join(map(lambda solution:solution.programmer.getUserInfo().screenName, solutions_without_paypal))
        messages.warning(request, "The following programmer(s) do not have a verified Paypal account yet: %s\n" % names+
                                  "Therefore, you won't be able to make a payment to them at this time.\n"+
                                  "If you want, you can leave a comment for them, asking them to update their profile page with an email of a verified Paypal account, then come back here again.")

    convert_rate = 1
    currency_symbol = "US$"
    alert_brazil = False
    if(offer.sponsor.getUserInfo().brazilianPaypal):
        convert_rate = paypal_services.usd_2_brl_convert_rate()
        currency_symbol = "R$"
        alert_brazil = True

    shared_price = convert_rate * float(offer.price) / len(solutions_with_paypal)
    shared_price = twoplaces(Decimal(str(shared_price)))

    return render_to_response('core/pay_offer.html',
        {'offer':offer,
         'solutions_accepting_payments' : solutions_with_paypal,
         'shared_price' : shared_price,
         'convert_rate' : convert_rate,
         'currency_symbol' : currency_symbol,
         'alert_brazil' : alert_brazil,
         },
        context_instance = RequestContext(request))
def _payWithPaypalForm(request, offer):
    solutions_accepting_payments = offer.issue.getSolutionsAcceptingPayments()

    solutions_with_paypal = []
    solutions_without_paypal = []
    for solution in solutions_accepting_payments:
        try:
            accepts_paypal = paypal_services.accepts_paypal_payments(
                solution.programmer)
        except BaseException as e:
            traceback.print_exc()
            messages.error(request, 'Error communicating with Paypal: %s' % e)
            mail_services.notify_admin(
                'Error determining if user accepts paypal',
                traceback.format_exc())
            return redirect(offer.get_view_link())
        if accepts_paypal:
            solutions_with_paypal.append(solution)
        else:
            solutions_without_paypal.append(solution)

    if len(solutions_with_paypal) == 0:
        messages.error(
            request,
            "The programmer(s) who solved this issue do not have a verified Paypal account yet, so you cannot pay them at this time.\n"
            +
            "Please leave a comment for them, asking them to update their profile page with an email of a verified Paypal account, then come back here again."
        )
        return redirect(offer.get_view_link())
    if len(solutions_without_paypal) > 0:
        names = ', '.join(
            map(lambda solution: solution.programmer.getUserInfo().screenName,
                solutions_without_paypal))
        messages.warning(
            request,
            "The following programmer(s) do not have a verified Paypal account yet: %s\n"
            % names +
            "Therefore, you won't be able to make a payment to them at this time.\n"
            +
            "If you want, you can leave a comment for them, asking them to update their profile page with an email of a verified Paypal account, then come back here again."
        )

    convert_rate = 1
    currency_symbol = "US$"
    alert_brazil = False
    if (offer.sponsor.getUserInfo().brazilianPaypal):
        convert_rate = paypal_services.usd_2_brl_convert_rate()
        currency_symbol = "R$"
        alert_brazil = True

    shared_price = convert_rate * float(
        offer.price) / len(solutions_with_paypal)
    shared_price = twoplaces(Decimal(str(shared_price)))

    return render_to_response('core/pay_offer.html', {
        'offer': offer,
        'solutions_accepting_payments': solutions_with_paypal,
        'shared_price': shared_price,
        'convert_rate': convert_rate,
        'currency_symbol': currency_symbol,
        'alert_brazil': alert_brazil,
    },
                              context_instance=RequestContext(request))