try around parsing upc data
[omsmith/pos-js.git] / www / assets / js / ui.js
index e4899a7..804780d 100644 (file)
@@ -76,12 +76,17 @@ function SelectionsViewModel () {
 
                var input = $(e.target);
                var cardData = input.val();
-               input.val('');
 
                var result = client.process(cardData, selected);
-               if (result === 2) {
-                       self.clearSelection();
-                       $('#checkout-modal').modal('hide');
+
+               input.val('');
+               self.clearSelection();
+               $('#checkout-modal').modal('hide');
+
+               if (result === E_PURCHASE_STATUS['EPS_FAIL']) {
+                       $('#fail-modal').modal();
+               } else if (result === E_PURCHASE_STATUS['EPS_NOMONEY']) {
+                       $('#nomoney-modal').modal();
                }
        };
 
@@ -105,5 +110,14 @@ ko.applyBindings(new SelectionsViewModel());
 
 function request_upc_data (upc, callback) {
        $.ajax( 'upc.php?upc=' + upc )
-               .done(function (data) { callback(JSON.parse(data)); });
+               .done(function (data) {
+                       var obj;
+                       try {
+                               obj = JSON.parse(data);
+                       } catch (e) {
+                               obj = { name:'unknown', size:'unknown' }
+                       }
+
+                       callback(obj);
+               });
 }