def donate(request, p, engine): if not can_accept_donations(p): return redirect("project-main", project_id=p.id) is_test_donation = getattr(settings, "DONATION_TEST", False) if request.method == "POST": donate_form = InvoiceForm(data=request.POST, project=p, engine=engine) if donate_form.is_valid(): description = u"Akvo-%d-%s" % (p.id, p.title) cd = donate_form.cleaned_data invoice = donate_form.save(commit=False) invoice.project = p invoice.engine = engine invoice.name = cd["name"] invoice.email = cd["email"] invoice.campaign_code = cd["campaign_code"] invoice.is_anonymous = not cd["is_public"] original_http_referer = request.session.get("original_http_referer", None) if original_http_referer: invoice.http_referer = original_http_referer del request.session["original_http_referer"] else: invoice.http_referer = request.META.get("HTTP_REFERER", None) if is_test_donation: invoice.test = True if request.session.get("donation_return_url", False): return_url = urljoin(request.session["donation_return_url"], reverse("donate_thanks")) else: return_url = urljoin(request.META['HTTP_ORIGIN'], reverse("donate_thanks")) if engine == "ideal": invoice.bank = cd["bank"] mollie_dict = dict( amount=invoice.amount * 100, bank_id=invoice.bank, partnerid=invoice.gateway, description=description, reporturl=urljoin(request.META['HTTP_ORIGIN'], reverse("mollie_report")), returnurl=return_url) try: mollie_response = query_mollie(mollie_dict, "fetch") invoice.transaction_id = mollie_response["transaction_id"] order_url = mollie_response["order_url"] invoice.save() except: return redirect("donate_500") return render_to_response("donate/donate_step3.html", dict(invoice=invoice, project=p, payment_engine=engine, mollie_order_url=order_url), context_instance=RequestContext(request)) elif engine == "paypal": invoice.save() pp_dict = dict( cmd="_donations", currency_code=invoice.currency, business=invoice.gateway, amount=invoice.amount, item_name=description, invoice=int(invoice.id), lc=invoice.locale, notify_url=urljoin(request.META['HTTP_ORIGIN'], reverse("paypal_ipn")), return_url=return_url, cancel_url=request.META['HTTP_ORIGIN']) pp_form = PayPalPaymentsForm(initial=pp_dict) if is_test_donation: pp_button = pp_form.sandbox() else: pp_button = pp_form.render() return render_to_response("donate/donate_step3.html", dict(invoice=invoice, payment_engine=engine, pp_form=pp_form, pp_button=pp_button, project=p), context_instance=RequestContext(request)) else: invoice_id = request.GET.get("invoice_id", None) if not invoice_id: donate_form = InvoiceForm(project=p, engine=engine, initial=dict(is_public=True)) else: invoice = get_object_or_404(Invoice, pk=invoice_id) donate_form = InvoiceForm(project=p, engine=engine, initial=dict(amount=invoice.amount, name=invoice.name, email=invoice.email, email2=invoice.email, campaign_code=invoice.campaign_code, is_public=not invoice.is_anonymous)) if request.session.get("donation_return_url", False): request.session["cancel_url"] = urljoin(request.session["donation_return_url"], reverse("project-main", kwargs={'project_id': p.id})) else: request.session["cancel_url"] = reverse("project-main", kwargs={'project_id': p.id}) return render_to_response("donate/donate_step2.html", dict(donate_form=donate_form, payment_engine=engine, project=p), context_instance=RequestContext(request))
def donate(request, p, engine, has_sponsor_banner=False): if p not in Project.objects.published().need_funding(): return redirect("project_main", project_id=p.id) if get_object_or_404(Organisation, pk=settings.LIVE_EARTH_ID) in p.sponsor_partners(): has_sponsor_banner = True if request.method == "POST": donate_form = InvoiceForm(data=request.POST, user=request.user, project=p, engine=engine) if donate_form.is_valid(): cd = donate_form.cleaned_data invoice = donate_form.save(commit=False) invoice.project = p invoice.engine = engine if request.user.is_authenticated() and request.user.email: invoice.user = request.user else: invoice.name = cd["name"] invoice.email = cd["email"] original_http_referer = request.session.get("original_http_referer", None) if original_http_referer: invoice.http_referer = original_http_referer del request.session["original_http_referer"] else: invoice.http_referer = request.META.get("HTTP_REFERER", None) if settings.DONATION_TEST: invoice.test = True if engine == "ideal": invoice.bank = cd["bank"] mollie_dict = { "amount": invoice.amount * 100, "bank_id": invoice.bank, "partnerid": invoice.gateway, "description": u"Donation: Akvo Project %d" % int(p.id), "reporturl": settings.MOLLIE_REPORT_URL, "returnurl": settings.MOLLIE_RETURN_URL, } try: mollie_response = query_mollie(mollie_dict, "fetch") invoice.transaction_id = mollie_response["transaction_id"] order_url = mollie_response["order_url"] invoice.save() except: return redirect("donate_500") return render_to_response( "rsr/donate_step3.html", { "invoice": invoice, "p": p, "payment_engine": engine, "mollie_order_url": order_url, "has_sponsor_banner": has_sponsor_banner, "live_earth_enabled": settings.LIVE_EARTH_ENABLED, }, context_instance=RequestContext(request), ) elif engine == "paypal": invoice.save() pp_dict = { "cmd": getattr(settings, "PAYPAL_COMMAND", "_donations"), "currency_code": invoice.currency, "business": invoice.gateway, "amount": invoice.amount, "item_name": u"%s: Project %d - %s" % (settings.PAYPAL_PRODUCT_DESCRIPTION_PREFIX, int(invoice.project.id), invoice.project.name), "invoice": int(invoice.id), "lc": invoice.locale, "notify_url": settings.PAYPAL_NOTIFY_URL, "return_url": settings.PAYPAL_RETURN_URL, "cancel_url": settings.PAYPAL_CANCEL_URL, } pp_form = PayPalPaymentsForm(initial=pp_dict) if settings.PAYPAL_TEST: pp_button = pp_form.sandbox() else: pp_button = pp_form.render() action = request.POST.get("action", None) return render_to_response( "rsr/donate_step3.html", { "invoice": invoice, "payment_engine": engine, "pp_form": pp_form, "pp_button": pp_button, "p": p, "has_sponsor_banner": has_sponsor_banner, "live_earth_enabled": settings.LIVE_EARTH_ENABLED, }, context_instance=RequestContext(request), ) else: donate_form = InvoiceForm(user=request.user, project=p, engine=engine) return render_to_response( "rsr/donate_step2.html", { "donate_form": donate_form, "payment_engine": engine, "p": p, "has_sponsor_banner": has_sponsor_banner, "live_earth_enabled": settings.LIVE_EARTH_ENABLED, }, context_instance=RequestContext(request), )
def donate(request, p, engine, has_sponsor_banner=False): if p not in Project.objects.published().need_funding(): return redirect('project_main', project_id=p.id) if get_object_or_404(Organisation, pk=settings.LIVE_EARTH_ID) in p.sponsor_partners(): has_sponsor_banner = True if request.method == 'POST': donate_form = InvoiceForm(data=request.POST, project=p, engine=engine) if donate_form.is_valid(): cd = donate_form.cleaned_data invoice = donate_form.save(commit=False) invoice.project = p invoice.engine = engine invoice.name = cd['name'] invoice.email = cd['email'] original_http_referer = request.session.get('original_http_referer', None) if original_http_referer: invoice.http_referer = original_http_referer del request.session['original_http_referer'] else: invoice.http_referer = request.META.get('HTTP_REFERER', None) if settings.DONATION_TEST: invoice.test = True if engine == 'ideal': invoice.bank = cd['bank'] mollie_dict = { 'amount': invoice.amount * 100, 'bank_id': invoice.bank, 'partnerid': invoice.gateway, 'description': u'Donation: Akvo Project %d' % int(p.id), 'reporturl': settings.MOLLIE_REPORT_URL, 'returnurl': settings.MOLLIE_RETURN_URL} try: mollie_response = query_mollie(mollie_dict, 'fetch') invoice.transaction_id = mollie_response['transaction_id'] order_url = mollie_response['order_url'] invoice.save() except: return redirect('donate_500') return render_to_response('rsr/donate_step3.html', {'invoice': invoice, 'p': p, 'payment_engine': engine, 'mollie_order_url': order_url, 'has_sponsor_banner': has_sponsor_banner, 'live_earth_enabled': settings.LIVE_EARTH_ENABLED}, context_instance=RequestContext(request)) elif engine == 'paypal': invoice.save() pp_dict = { 'cmd': getattr(settings, 'PAYPAL_COMMAND', '_donations'), 'currency_code': invoice.currency, 'business': invoice.gateway, 'amount': invoice.amount, 'item_name': u'%s: Project %d - %s' % (settings.PAYPAL_PRODUCT_DESCRIPTION_PREFIX, int(invoice.project.id), invoice.project.name), 'invoice': int(invoice.id), 'lc': invoice.locale, 'notify_url': settings.PAYPAL_NOTIFY_URL, 'return_url': settings.PAYPAL_RETURN_URL, 'cancel_url': settings.PAYPAL_CANCEL_URL} pp_form = PayPalPaymentsForm(initial=pp_dict) if settings.PAYPAL_TEST: pp_button = pp_form.sandbox() else: pp_button = pp_form.render() action = request.POST.get('action', None) return render_to_response('rsr/donate_step3.html', {'invoice': invoice, 'payment_engine': engine, 'pp_form': pp_form, 'pp_button': pp_button, 'p': p, 'has_sponsor_banner': has_sponsor_banner, 'live_earth_enabled': settings.LIVE_EARTH_ENABLED}, context_instance=RequestContext(request)) else: donate_form = InvoiceForm(project=p, engine=engine) return render_to_response('rsr/donate_step2.html', {'donate_form': donate_form, 'payment_engine': engine, 'p': p, 'has_sponsor_banner': has_sponsor_banner, 'live_earth_enabled': settings.LIVE_EARTH_ENABLED}, context_instance=RequestContext(request))
def donate(request, p, engine): if not can_accept_donations(p): return redirect("project-main", project_id=p.id) is_test_donation = getattr(settings, "DONATION_TEST", False) if request.method == "POST": donate_form = InvoiceForm(data=request.POST, project=p, engine=engine) if donate_form.is_valid(): description = u"Akvo-%d-%s" % (p.id, p.title) cd = donate_form.cleaned_data invoice = donate_form.save(commit=False) invoice.project = p invoice.engine = engine invoice.name = cd["name"] invoice.email = cd["email"] invoice.campaign_code = cd["campaign_code"] invoice.is_anonymous = not cd["is_public"] original_http_referer = request.session.get( "original_http_referer", None) if original_http_referer: invoice.http_referer = original_http_referer del request.session["original_http_referer"] else: invoice.http_referer = request.META.get("HTTP_REFERER", None) if is_test_donation: invoice.test = True if request.session.get("donation_return_url", False): return_url = urljoin(request.session["donation_return_url"], reverse("donate_thanks")) else: return_url = urljoin(request.META['HTTP_ORIGIN'], reverse("donate_thanks")) if engine == "ideal": invoice.bank = cd["bank"] mollie_dict = dict(amount=invoice.amount * 100, bank_id=invoice.bank, partnerid=invoice.gateway, description=description, reporturl=urljoin( request.META['HTTP_ORIGIN'], reverse("mollie_report")), returnurl=return_url) try: mollie_response = query_mollie(mollie_dict, "fetch") invoice.transaction_id = mollie_response["transaction_id"] order_url = mollie_response["order_url"] invoice.save() except: return redirect("donate_500") return render_to_response( "donate/donate_step3.html", dict(invoice=invoice, project=p, payment_engine=engine, mollie_order_url=order_url), context_instance=RequestContext(request)) elif engine == "paypal": invoice.save() pp_dict = dict(cmd="_donations", currency_code=invoice.currency, business=invoice.gateway, amount=invoice.amount, item_name=description, invoice=int(invoice.id), lc=invoice.locale, notify_url=urljoin(request.META['HTTP_ORIGIN'], reverse("paypal_ipn")), return_url=return_url, cancel_url=request.META['HTTP_ORIGIN']) pp_form = PayPalPaymentsForm(initial=pp_dict) if is_test_donation: pp_button = pp_form.sandbox() else: pp_button = pp_form.render() return render_to_response( "donate/donate_step3.html", dict(invoice=invoice, payment_engine=engine, pp_form=pp_form, pp_button=pp_button, project=p), context_instance=RequestContext(request)) else: invoice_id = request.GET.get("invoice_id", None) if not invoice_id: donate_form = InvoiceForm(project=p, engine=engine, initial=dict(is_public=True)) else: invoice = get_object_or_404(Invoice, pk=invoice_id) donate_form = InvoiceForm(project=p, engine=engine, initial=dict( amount=invoice.amount, name=invoice.name, email=invoice.email, email2=invoice.email, campaign_code=invoice.campaign_code, is_public=not invoice.is_anonymous)) if request.session.get("donation_return_url", False): request.session["cancel_url"] = urljoin( request.session["donation_return_url"], reverse("project-main", kwargs={'project_id': p.id})) else: request.session["cancel_url"] = reverse( "project-main", kwargs={'project_id': p.id}) return render_to_response("donate/donate_step2.html", dict(donate_form=donate_form, payment_engine=engine, project=p), context_instance=RequestContext(request))