2012-10-11

Generating receipts

Last week it was brought to my attention that PageKite's payment processor, Dalpay, is not actually sending people receipts. I am not sure why I thought they were, but it turns out I was wrong.

Now, receipts don't matter much to individuals, but they are kind of a big deal for companies. And I've got a few of those now as subscription customers, with more signing up all the time. Not offering these people receipts is pretty lame.

So this week, I have been working on generating receipts automatically in response to received payments. I decided to see if I could make them look a bit more professional than the plain-text e-mails I get from some other online service providers, and also I wanted people to be able to download old receipts from their account pages - this allows me to compensate for past mistakes by generating old receipts now.

So the first step, was creating a template which could be programmatically edited and updated.

After looking around a bit, I remembered that the Open Document format (.odt) is actually just a .zip archive with some xml files inside. So creating a good looking receipt in Open Office, and then writing code (shell scripts, actually) to fill in customer details and amounts is actually very easy.

The next step, was to convert these autogenerated .odt files into PDFs.

For this, I did some googling and discovered the unoconv utility. It can run in the background as a service, basically using the built in export features of Open Office itself to generate the PDFs.

All it took on the server side was:

apt-get install unoconv openoffice.org-writer gsfonts

The fonts package was needed to make the receipts properly pretty.

The third step was to make sure to generate PDF files with unguessable names, dump them in a static folder accessible by the web server and tweak the code to add an item to the user's account history, telling them how to download their receipt. Voila! Pretty receipts accessible from the web.

Once I am sure the receipts are being generated properly, I may also start sending them as e-mail attachments (using mutt from a shell script, of course).

Tags: tech, pagekite


Recent posts

...