eWay response codes as a file

, posted: 2-May-2016 16:29

Anyone who has used the eWay payment gateway for processing credit cards, will have come across this.  If there is an issue, rather than alert you with what the issue is, the eWay API will give you a five digit response code, which you then have to decipher.  Not helpful.

Chatting to their helpdesk today, they don’t provide all 235 different codes as a simple download (too easy I know), so using some regex magic from their documentation, I’ve dropped them all into one easy to import CSV file.

Import into your database of choice, and more meaningful eWay error codes are only a query away!

Fixing strange characters printing on Epson receipt printers

, posted: 21-Aug-2014 22:56

Back in 2012, in my never-ending quest to geek up Tuihana Cafe, I threw together a Windows based app that takes SMS messages and prints them out on our kitchen receipt printer (read about it here).  It allows our customers to make an order on their way to the cafe, without having to stand around and wait for the coffee to be made.

All was right in the world… or so I thought.

Late last year I decided to learn ESC/POS and print directly to the receipt printer, rather than continue cheating by using the Epson .Net OPOS drivers.  This introduced a very annoying bug:

For some reason, the receipt printer or my program was adding in random characters (such as the speech marks before Printed, and the bracket before Sender) and dropping characters (like the O from the word One).  My staff were clever enough to decipher these messages, however this wasn’t completely bulletproof – an order came through for 1x flat white, but the system printed out 21x flat white.  It was then I new that I had to fix this once and for all.

For the last month I’ve been working on a fix, and it wasn’t until today that I stumbled across a blog post with the solution.

BinaryWriter has a method .Write() which takes a string as the input parameter.  Instead of just appending this to the internal buffer, it also (not helpfully) prepends the length of the string in the first byte.

From the blog post:

Now that I think about it, this makes perfect sense: strings in the .NET framework are typically not thought of as being null-terminated, they’ve got a length, and in order for theBinaryReader‘s Read(string) method to work, it’ll need to be able to know the length of the string to determine how many bytes to read.

In my case, I was writing data to an Epson TM-T88III receipt printer, and given the structure of the commands that the printer expects, it doesn’t need or want the length of the string in this way. Because I didn’t read the MSDN documentation closely, I was left scratching my head as to why weird characters were showing up or characters were being omitted in my output.

The solution? Replace .write(“Test”) with .write(Encoding.ASCII.GetBytes(“Test”))

The new receipts all fixed up and looking purdy:

Hopefully this helps someone out from weeks of frustration and programmer rage.

Extending Xero through their API

, posted: 2-Oct-2012 17:44

Xero is fantastic accounting software.  Through their API (Application Programming Interface) they allow third parties to integrate into their main accounting engine.  This allows developers to create more specific add-ons suited to their specific niches - there is already an extensive list of existing add-ons on the Xero site..

This post serves as an example of what can be achieved.  Please note this is not a product we are selling, it's purely something we've created for our own internal use.

A small part of our business is the web-hosting of our development clients.  With a few hundred clients, we were original using the re-occurring invoice function in Xero.  As this client base has grown, it's become harder and harder to administrate these clients, and make sure that everyone is billed correctly.

Using data pulled live from our servers, we match a client with a billing plan, and send out an invoice on the first day of every month.  An example of the email that's sent out is shown below (click to enlarge):


We've extended this over the default email out capabilities of Xero in the following way:

  • As this is a custom template, we have a lot more flexibility with formatting.
  • The invoice is always sent from our main accounts email (if one of our staff edited a reoccurring invoice in Xero, they would be set as the new sender next time the invoice was sent out, a very annoying quirk of Xero)
  • The subject line contains the invoice number and invoice reference
  • The body of the invoice contains the invoice number, the amount that is due, plus when the invoice is due.
  • We link directly to our payment gateway (powered by BNZ) which prepopulates all the values, and if a successful payment is made, creates a payment against this invoice in Xero, making bank reconciliation quick and painless.
  • If the client has overdue invoices, these are listed in a summary table, with a total shown at the top.
  • Each overdue invoice has a link which the client can click on to view the invoice as a PDF online
  • We stream down the original invoice from Xero and attach it to the email as a PDF

Hopefully this gives you some ideas of what the Xero API will allow you to do.  As always, (blatant plug), if you're after any custom Xero integration, contact us.

User accessibility, and keeping the bad guys out

, posted: 11-Jun-2012 06:00

As a developer, all the systems we create have end-users.  There is a delicate balance between make sure a user is who they say they are, and stopping unauthorised access.  Make it too easy and their data can be compromised - too difficult, and our helpdesk gets flooded daily with calls from users who can't legitimately get into their systems.  The tried-and-true method for user/pass combination is email address and a password.

As a user, I hate systems that impose ridiculously complex rules when it comes to me selecting a password.  If I pick a password that is ridiculously simple, I should suffer any adverse implications for my poor decision.  Making me remember a login that isn't my primary email address (such as a username/account ID) is just as annoying.

The worst offender for a system I use often is our credit card processor - if someone did get access to my account, the worst they could do is transfer funds to our company bank account.  Nothing else remotely useful is available, yet they enforce a very complex pattern, and make me change it every month.

Another good example of this is in a recent thread by Geekzone user Lurch - he highlights the issue of signing up to Vodafone's careers site:

Please note that the password must respect the following rules:

  • It must contain between 6 and 50 characters. Use only characters from the following set: ! # $ % & ( ) * + , - . / 0123456789 : ; < = > ? @ ABCDEFGHIJKLMNOPQRSTUVWXYZ [ \ ] _ ` abcdefghijklmnopqrstuvwxyz { | } ~
  • It must contain at least 2 letter(s) (ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz).
  • It must contain at least 1 numeric character(s) (0123456789).
  • It must contain at least 1 character(s) from the following set: ! # $ % & ( ) * + , - . / : ; < = > ? @ [ \ ] _ ` { | } ~
  • It must not contain more than 2 identical consecutive characters (AAA, iiii, $$$$$ ...).
  • It must not contain your user name.
  • It must not contain your email address.
  • It must not contain your first name.
  • It must not contain your last name.

Just to sign up to a careers site, you have to jump through all these hoops.  Over the top much?

I originally had a whole blog post here outlining what I think is a better solution, but instead micsco's post from xkcd sums it up far better than I can:


Visualising data on a map

, posted: 28-Dec-2010 18:34

Mapping data geospatially was the title I was going with originally - what I've gone with is the layman's way of describing this post.

It was at a training day for the Auckland SQL group (a group of SQL Server geeks) earlier this year that I realised how few developers knew what geospatial mapping was, meaning the decision makers in their businesses hadn't seen or didn't know about the vast benefits it can bring.  If you work with any data that involves addresses, you need to start mapping that data geospatially.

If you were given a list of addresses to visit, most people who pull out a map book to work out the best route; unless you were completely familiar with the addresses already, this is the easiest way to figure out a route.  Likewise, if you were trying to figure out the most central point to meet, a map would be very helpful.

Mapping data geospatially is taking addresses, converting them to their latitude/longitude, and then using them to achieve your outcome, whether it is putting them on a map, or calculating the distance between them (to name two very basic applications).

In June (yes I'm quick, I know), I posted a topic about the best places to eat, with the idea that this would give me data to help illustrate this post.  I took all the posts, geocoded the addresses (translated them into co-ordinates), and saved them to a database.  A screenshot of the list is below:

As a raw list, if you are looking for a place to eat, it's quite hard to determine anything.  If all these points are put on a map it becomes much easier (view live map):

Mapping provided by Geosmart (subsidiary of the AA), who also do maps for Navman and Tomtom GPS navigation units.

This is only a very basic application, to take this every further I could:

  • Allow you to enter an address and then show you the nearest food places and the distances to them (with driving directions).
  • List the food places based on the geographical location (rather than the random order they are currently in)
  • Give each different food place a different icon depending on it's type (so a coffee cup for cafes, a beer for pubs etc)
  • Figure out the most optimum way to visit a group of food places using Geosmart's clever routing engine (Route2GO optimisation).

Geospatially mapping makes visualising your geographical data much easier, and some of the savings that can be made, especially for delivery based industries (by using route optimisation) can be quite significant.

If you have any food places you want to add, please visit here and add your own.  Once I've checked it (and to prevent spam) it'll appear on the live list here.

My thanks to Geekzone users Antzzz, BurningBeard, coffeebaron, Ezzie, garvani, gehenna, jofizz, Lias, michaelmurfy, muppet, nickd, NonprayingMantis, oxnsox, rscole86, sarg, snonoz, timbosan, tomgeeknz, vinnieg, and xpd for their submissions.

Blatant self promotion: if you want to implement this or see what else is possible, contact 3Bit as we are certified Geosmart developers.

nate's profile

New Zealand

I'm Nate Dunn, and I work for 3Bit, and am a moderator here at Geekzone.

Use Autotask and Xero? Sync data between them with My Accounting Toolbox.

Use Xero and SagePay? Get your invoices paid faster using HostedPay.


The views and opinions represented on this blog are personal and belong solely to the blogger and do not represent in anyway those of 3Bit Solutions Limited or any other company.

Latest posts

Cyber attacks on NZ small busi...
How one database query can fix...
Review: Navman MiVUE680...
Review: Huawei P9...
Poor man’s automation - ...
App Review: WorldRemit...
eWay response codes as a file...
International podcast conferen...
Is the Nexus 6P the perfect An...
Review: Huawei G8...