Exemple #1
0
def pdf_invoice(request, transaction_id):
    sub = Subscription.objects.get(user=request.user)
    transaction = sub.get_transaction(transaction_id)
    if transaction is None:
        return HttpResponseForbidden()

    response = HttpResponse(content_type='application/pdf')
    filename = "MS-HC-%s.pdf" % transaction.id.upper()
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename
    PdfInvoice(response).render(transaction, sub.flattened_address())
    return response
Exemple #2
0
def charge_webhook(request):
    sub, tx = Subscription.objects.by_braintree_webhook(request)
    if sub.send_invoices:
        filename = "MS-HC-%s.pdf" % tx.id.upper()

        sink = BytesIO()
        PdfInvoice(sink).render(tx, sub.flattened_address())
        ctx = {"tx": tx}

        recipient = sub.invoice_email or sub.user.email
        emails.invoice(recipient, ctx, filename, sink.getvalue())

    return HttpResponse()
Exemple #3
0
def pdf_invoice(request, transaction_id):
    sub = Subscription.objects.get(user=request.user)
    transaction = braintree.Transaction.find(transaction_id)
    if transaction.customer_details.id != sub.customer_id:
        return HttpResponseForbidden()

    response = HttpResponse(content_type='application/pdf')
    filename = "MS-HC-%s.pdf" % transaction.id.upper()
    response['Content-Disposition'] = 'attachment; filename="%s"' % filename

    bill_to = request.user.profile.bill_to or request.user.email
    PdfInvoice(response).render(transaction, bill_to)
    return response
Exemple #4
0
def pdf_invoice(request, transaction_id):
    sub, tx = Subscription.objects.by_transaction(transaction_id)

    # Does this transaction belong to a customer we know about?
    if sub is None or tx is None:
        return HttpResponseForbidden()

    # Does the transaction's customer match the currently logged in user?
    if sub.user != request.user and not request.user.is_superuser:
        return HttpResponseForbidden()

    response = HttpResponse(content_type="application/pdf")
    filename = "MS-HC-%s.pdf" % tx.id.upper()
    response["Content-Disposition"] = 'attachment; filename="%s"' % filename
    PdfInvoice(response).render(tx, sub.flattened_address())
    return response
Exemple #5
0
def charge_webhook(request):
    sig = str(request.POST["bt_signature"])
    payload = str(request.POST["bt_payload"])

    import braintree
    doc = braintree.WebhookNotification.parse(sig, payload)
    if doc.kind != "subscription_charged_successfully":
        return HttpResponseBadRequest()

    sub = Subscription.objects.get(subscription_id=doc.subscription.id)
    if sub.send_invoices:
        transaction = doc.subscription.transactions[0]
        filename = "MS-HC-%s.pdf" % transaction.id.upper()

        sink = six.BytesIO()
        PdfInvoice(sink).render(transaction, sub.flattened_address())
        ctx = {"tx": transaction}
        emails.invoice(sub.user.email, ctx, filename, sink.getvalue())

    return HttpResponse()