One thing that really shocked me is how much companies charge for a credit card reading program. Since to use the credit card you already have to have an account with Authorize.Net or a similar company it makes sense to just use their secure web site and then automate it. You can buy an USB credit card swiper for as little as $25 off eBay. Just make sure you get one that sends ASCII text as if it were typed in from a keyboard.
When I go on the road and have to sell I usually bring a tethering program for my phone, so I can have internet connectivity, and then use the Authorize.Net account and my card swiper. It makes entering credit cards as fast as having a dedicated terminal. I have a very small Python program I then run which reads the data. Now I really ought put a more sophisticated UI on this. In the meantime this is a quick a dirty UI using wxWidgets.
First, when you swipe the card, wait until the first dialog box is open. It should read what looks like a bunch of gibberish into the text field. I then parse it to extract the credit card number and expiration date.
For the script to work you must be signed into Authorize.Net and have the entry screen up in Safari. I’d strongly suggest not automating this sign in from a purely security point of view. It most likely is against your banking terms of service to automate it as well. You simply shouldn’t have any passwords or credit card information stored anywhere on your computer.
Note that while this works at the time of this writing (July 18th) there’s always the likelihood that Authorize.Net changes their webpage in which case obviously the code will stop working. In that case just look at the HTML source code to see what the field names are so as to modify the code.
#!/usr/bin/python import string from appscript import * import wx def enter_cc(cc="12341234143", date="0911",amount=0): Safari = app(u'/Applications/Safari.app') FEdoc = Safari.documents[0].get() Safari.do_JavaScript("document.forms['payform']['x_card_num'].value = '" + cc + "'", in_=FEdoc) Safari.do_JavaScript("document.forms['payform']['x_exp_date'].value = '" + date + "'", in_=FEdoc) Safari.do_JavaScript("document.forms['payform']['x_amount'].value = '" + amount + "'", in_=FEdoc) def translate(): myapp = wx.PySimpleApp() dlg = wx.TextEntryDialog(None, "Credit Card:", "Credit Card", "1111", style=wx.OK|wx.CANCEL ) if dlg.ShowModal() == wx.ID_OK: response = dlg.GetValue() else: dlg.Destroy() myapp.Destroy() return dlg.Destroy() s = response cc = s[2:18] loc = string.rfind( s, "^") date_s = s[loc+1:loc+5] year = date_s[0:2] month = date_s[2:4] monthyear = month+year dlg = wx.TextEntryDialog(None, "Amount:", "Amount", "0.0", style=wx.OK|wx.CANCEL ) if dlg.ShowModal() == wx.ID_OK: response = dlg.GetValue() else: dlg.Destroy() myapp.Destroy() return dlg.Destroy() myapp.Destroy() amt = float(response) enter_cc(cc, monthyear, amt) if __name__=='__main__': translate()
The only part that needs explanation is the dialog box generation. This is basically a default dialog box that wx has for quick and dirty generation. You’ll need wxWidgets installed first, of course. There are numerous other ways you could have done this ranging from making a terminal app to using a dialog box via osax.
The data encoded on the credit card holds the number from positions 2-18. So we read that in. The date is not in a fixed place but follows the ^ character. It is stored as year, month whereas Authorize.Net requires it in the opposite order.
The final bit is the enter_cc function which simply uses to Appscript to inject some Javascript into Safari and set the appropriately named field.
Now if you’re going to use the above you’ll probably want to throw a nicer UI on. Further you can also add fields. (I’ve obviously simplified things a bit for you) But the above takes a couple of minutes to allow credit processing on your Mac and OSX without needing to purchase an expensive program. It would be fairly trivial to add a bit of Appscript to read your amount from a POS or Invoice program that supports Applescript.
Related posts:
.jpg)
#1 by Clark on 2010/02/01 - 1:52 pm
Note the above doesn’t work in Snow Leopard for some reason. I hopefully will have a fix soon.