sexy data-binding with knockout.js. huzzah it doing work for me
[omsmith/pos-js.git] / www / assets / js / client.js
1 PosClientWrapper = function (authKey, serverLocation) {
2         var _authKey = 'balls';
3
4         var _transport = new Thrift.Transport('http://home.omsmith.ca/api/');
5         var _protocol = new Thrift.Protocol(_transport);
6         var _client = new PosBookieClient(_protocol);
7
8         var _getAuthString = function () {
9                 var salt = _client.getSalt();
10
11                 return Sha1.hash(salt+_authKey);
12         }
13
14         this.getPrice = function (upc, callback) {
15                 if (callback === undefined) {
16                         return _client.getUPCPrice(upc) / 100;
17                 }
18
19                 _client.getUPCPrice(upc, function (p) {
20                         callback(p/100);
21                 });
22         }
23
24         this.process = function (cardData, selection) {
25                 var upcs = [];
26
27                 for (var i in selection) {
28                         for (var q = 0; q < selection[i].quantity; q++) {
29                                 upcs.push(selection[i].upc);
30                         }
31                 }
32
33                 return _client.purchaseItems(_getAuthString(), cardData, upcs);
34         }
35
36         try {
37                 _transport.open();
38                 _client.ping();
39         } catch (e) {
40                 location.reload(true);
41         }
42 };