We recently added invoices to Browserling. I thought I'd share how we did it as it's another interesting story.

Our customers keep asking for invoices all the time so we made it simple to create them. They can now just go to their Browserling accounts and download them. Here's how an invoice looks like:


Example invoice. (Download example.)

And here are the implementation details.

We use a node module called invoice. The invoice module takes a hash of invoice details, internally spawns pdflatex that creates a pdf invoice, and then calls a callback with the path to the pdf file, like this:

var invoice = require('invoice');
invoice(
    {
        template: 'browserling-dev-plan.tex',
        from: "Browserling inc\\\\3276 Logan Street\\\\Oakland, CA 94601\\\\USA",
        to: "John Smith\\\\Corporation Inc.",
        period: "2/2013",
        amount: "$20"
    },
    function (err, pdf) {
        if (err) {
            console.log("Failed creating the invoice: " + err);
            return;
        }
        console.log("Pdf invoice: " + pdf);
    }
);

The browserling-dev-plan.tex latex template contains %to%, %from%, %period%, and %amount% place holders that the invoice module simply replaces with the given data:

\documentclass[12pt]{article}

\pagenumbering{gobble}

\begin{document}

\begin{center}
\Large{\textbf{Invoice}} \\
\vspace{0.5cm}
\large{Subscription to Browserling's Developer Plan}
\end{center}

\vspace{1cm}

\section*{Invoice from:}
%from%

\section*{Invoice to:}
%to%

\section*{Period:}
%period%

\section*{Amount:}
%amount%

\end{document}

Once the pdf invoice is generated, we create a token that maps to the pdf file, and once it's requested, we send it to the customer as an application/pdf.

Until next time!

Comments

February 27, 2014, 17:12

Did you put the all important Invoice # on the actual invoices?

I guess I could login and check but it's more fun to be the first to comment.

February 27, 2014, 19:33

Hmm, no I don't. All these payments are automatic so we can track what's been paid. I guess it would matter if the invoices were paid by check. Then it would be harder to track, which payment is for which invoice. Is that right?

Leave a new comment

(why do I need your e-mail?)

(Your twitter name, if you have one. (I'm @pkrumins, btw.))

Type the word "computer_415": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.

Advertisements