SY_Transactions.js

This is the actual response handling and processing of the web service calls that are made by the MobiliserClient class.

1       /**
2        *  @overview
3        * This is the actual response handling and processing of the web service calls
4        * that are made by the MobiliserClient class. Any manipulation of the response,
5        * extraction of needed data and the making of Data Objects (DO) out of the XML
6        * document would be inserted here.
7        *
8        * @name SY_Transactions.js
9        * @author SAP AG
10       * @version 1.0
11       *
12       */
13      
14      /**
15        @function
16      
17        @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
18       */
19      var loginBack = function(r) {
20          var rCode = getStatusCode(r);
21          if (appstate == trans.TRAN_LOGIN) {
22              if(rCode == '0') {
23                  loginParseXML(r);
24                  return true;
25              } else {
26                  _alertBox(Str_alert_loignfailed + getErrorMessage(r));
27                  return false;
28              }
29          }
30      };
31      
32      /**
33        @function
34      
35        @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
36       */
37      var fbssologinBack = function(r) {
38          var rCode = getStatusCode(r);
39          if(rCode == '0') {
40              fbssloginParseXML(r);
41              return true;
42          } else {
43              _alertBox(Str_msg_failfacebooksso + getErrorMessage(r));
44              return false;
45          }
46      };
47      
48      /**
49        @function
50      
51        @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
52       */
53      var getRsaPublicKeyBack = function(r) {
54          var rCode = getStatusCode(r);
55          if("0" === rCode) {
56              if (!session.keys) {
57                  session.keys = [];
58              }
59              session.keys[session.keyType] = r.key;
60              return true;
61          } else {
62              _alertBox(Str_msg_failgetpublickey + getErrorMessage(r));
63              return false;
64          }
65      };
66      
67      /**
68        @function
69      
70        @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
71       */
72      var logoutBack = function(r) {
73          var rCode = getStatusCode(r);
74          if(rCode == '0') {
75              $.mobile.changePage("login.html", page_opt);
76              session = new LoginSession();
77              return true;
78          } else {
79              _alertBox(Str_alert_logoutfailed + getErrorMessage(r));
80              return false;
81          }
82      };
83      
84      /**
85        @function
86      
87        @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
88       */
89      var changeCredentialBack = function(r) {
90          hideProgress();
91      
92          var rCode = getStatusCode(r);
93          if (appstate == trans.TRAN_CHANGEPIN) {
94              if (rCode == '0') {
95                  // if succeeded then...
96                  $.mobile.changePage("changepindone.html", page_opt);
97              } else {
98                  // if failed then...
99                  _alertBox(Str_alert_changepinfailed + getErrorMessage(r));
100             }
101         }
102         appstate = trans.TRAN_IDLE;
103     };
104     
105     /**
106     @function
107     
108     @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
109     */
110     var checkCredentialBack = function(r) {
111         var rCode = getStatusCode(r);
112         if (rCode == '0') {
113             if (appstate == trans.TRAN_BLOCKACCOUNT) {
114                 mc.updateCustomerBlockAccount(updateCustomerBack);
115             } else {
116                 hideProgress();
117                 appstate = trans.TRAN_IDLE;
118                 _alertBox(Str_alert_correctpin);
119                 $.mobile.changePage("manage.html", page_opt);
120             }
121         } else {
122             hideProgress();
123             appstate = trans.TRAN_IDLE;
124             _alertBox(getErrorMessage(r));
125             $("#blockpin").val('');
126         }
127     };
128     
129     /**
130       @function
131     
132       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
133      */
134     var balanceInquiryBack = function(r) {
135         var rCode = getStatusCode(r);
136         if (rCode == '0') {
137             session.pibalance= parseReturnEntry(r, 'Balance');
138             return true;
139         } else {
140             _alertBox(Str_alert_balanceenqfailed + getErrorMessage(r));
141             return false;
142         }
143     };
144     
145     /**
146       @function
147     
148       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
149      */
150     var getWalletBack = function(r) {
151         //console.log("getWallet:" + JSON.stringify(r));
152         var rCode = getStatusCode(r);
153         if (rCode == '0') {
154             walletParseXML(r);
155             return true;
156         } else {
157             _alertBox(Str_alert_gettingwalletfailed + getErrorMessage(r));
158             return false;
159         }
160     };
161     
162     /**
163       @function
164     
165     @param  xmlHttpReq
166     */
167     var updateBankAccountBack = function(r) {
168         var rCode = getStatusCode(r);
169         if (rCode == '0') {
170             return true;
171         } else {
172             _alertBox(Str_alert_updatepayfailed + getErrorMessage(r));
173             return false;
174         }
175     };
176     
177     /**
178       @function
179     
180     @param  xmlHttpReq
181     */
182     var setPrimaryBack = function(r) {
183         var rCode = getStatusCode(r);
184         if (rCode == '0') {
185             return true;
186         } else {
187             _alertBox(Str_alert_primarywalletfail + getErrorMessage(r));
188             return false;
189         }
190     };
191     
192     /**
193       @function
194     
195       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
196      */
197     var createWalletEntryBack = function(r) {
198         var rCode = getStatusCode(r);
199         if (rCode == '0') {
200             return true;
201         } else {
202             _alertBox(Str_alert_addwalletentry + Str_alert_isfailed + getErrorMessage(r));
203             return false;
204         }
205     };
206     
207     /**
208       @function
209     
210       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
211      */
212     var updateWalletEntryBack = function(r) {
213         var rCode = getStatusCode(r);
214         if (rCode == '0') {
215             return true;
216         } else {
217             _alertBox(Str_alert_editwallet + Str_alert_isfailed + getErrorMessage(r));
218             return false;
219         }
220     };
221     
222     /**
223       @function
224     
225       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
226      */
227     var deleteBankWalletEntryBack = function(r) {
228         var rCode = getStatusCode(r);
229         if (rCode == '0') {
230             return true;
231         } else {
232             _alertBox(Str_alert_removewallet + Str_alert_isfailed + getErrorMessage(r));
233             return false;
234         }
235     };
236     
237     /**
238       @function
239     
240       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
241      */
242     var deleteCardWalletEntryBack = function(r) {
243         var rCode = getStatusCode(r);
244         if (rCode == '0') {
245             return true;
246         } else {
247             _alertBox(Str_alert_removecreditcard + Str_alert_isfailed + getErrorMessage(r));
248             return false;
249         }
250     };
251     
252     var deleteCustomerAlertByCustomerAndDataBack = function(r) {
253         var rCode = getStatusCode(r);
254         if (rCode == '0') {
255             return true;
256         } else {
257             _alertBox(Str_alert_assoalertfailed + getErrorMessage(r));
258             return false;
259         }
260     };
261     
262     /**
263       @function
264     
265       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
266      */
267      var createSmsTokenBack = function(r) {
268         hideProgress();
269     
270         var rCode = getStatusCode(r);
271         if (appstate == trans.TRAN_CREATESMSTOKEN) {
272             if (rCode == '0') {
273                 $.mobile.changePage("regpin.html", page_opt);
274             } else {
275                 _alertBox(Str_alert_smstokenfailed + getErrorMessage(r));
276             }
277         }
278         appstate = trans.TRAN_IDLE;
279     };
280     
281     /**
282       @function
283     
284       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
285      */
286     var createFullCustomerBack = function(r) {
287         hideProgress();
288     
289         var rCode = getStatusCode(r);
290         if (appstate == trans.TRAN_CREATECUSTOMER) {
291             if (rCode == '0') {
292                 var customerId = parseReturnEntry(r, 'customerId');
293                 $.mobile.changePage("regdone.html", page_opt);
294             } else {
295                 _alertBox(Str_alert_createcustomerfailed + getErrorMessage(r));
296             }
297         }
298         appstate = trans.TRAN_IDLE;
299     };
300     
301     /**
302       @function
303     
304       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
305      */
306     var updateCustomerBack = function(r) {
307         hideProgress();
308     
309         var rCode = getStatusCode(r);
310         if (appstate == trans.TRAN_BLOCKACCOUNT) {
311             if (rCode == '0') {
312                 _alertBox(Str_alert_accountblocked);
313                 $("#username").val('');
314                 $.mobile.changePage("login.html", page_opt);
315             } else {
316                 hideProgress();
317                 _alertBox(Str_alert_blockfailed + getErrorMessage(r));
318             }
319         } else if (appstate == trans.TRAN_NOTIFICATION) {
320             if (rCode == '0') {
321                 var mode = 0;
322                 if($('#checkbox-sms').is(':checked') && $('#marketpref').val() == "on")
323                     mode = mode | 1;
324                 if($('#checkbox-email').is(':checked') && $('#marketpref').val() == "on")
325                     mode = mode | 2;
326                 session.customer.modeId = mode;
327     
328                  _alertBox(Str_alert_notificationsaved);
329                  $.mobile.changePage("manage.html", page_opt);
330             } else {
331                 _alertBox(Str_alert_notificationfailed + getErrorMessage(r));
332             }
333         }
334         appstate = trans.TRAN_IDLE;
335     };
336     
337     /**
338       @function
339     
340       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
341      */
342     var createIdentificationBack = function(r) {
343         var rCode = getStatusCode(r);
344         if (appstate == trans.TRAN_CREATECUSTOMER) {
345             if (rCode == '0') {
346                 mc.setCredential(registerPinBack, parseReturnEntry(r, 'customerId'), $('#mobilepin').val(), "0");
347             } else {
348                 hideProgress();
349                 appstate = trans.TRAN_IDLE;
350                 _alertBox(Str_alert_identificationfailed + getErrorMessage(r));
351             }
352         }
353     };
354     
355     /**
356       @function
357     
358       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
359      */
360     var getIdentificationsBack = function(r) {
361         var rCode = getStatusCode(r);
362         //console.log("getIdentifications:" + JSON.stringify(r));
363         if (rCode == '0') {
364             session.msisdn = parseIdentification(r);
365             return true;
366         } else {
367             _alertBox(Str_alert_getidentificationfailed + getErrorMessage(r));
368             return false;
369         }
370     };
371     
372     /**
373       @function
374     
375       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
376      */
377     var registerPinBack = function(r) {
378         var rCode = getStatusCode(r);
379         if (appstate == trans.TRAN_CREATECUSTOMER) {
380             if (rCode == '0') {
381                 mc.setCredential(registerPasswordBack, session.customer.id, $('#webpwd').val(), "1");
382             } else {
383                 hideProgress();
384                 appstate = trans.TRAN_IDLE;
385                 _alertBox(Str_alert_registercustomerpinfailed + getErrorMessage(r));
386             }
387         }
388     };
389     
390     /**
391       @function
392     
393       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
394      */
395     var registerPasswordBack = function(r) {
396         var rCode = getStatusCode(r);
397         if (appstate == trans.TRAN_CREATECUSTOMER) {
398             if (rCode == '0') {
399                 mc.createIdentification(registerBack, session.customer.id, msisdnformat($('#phoneno').val()), "0");
400             } else {
401                 hideProgress();
402                 appstate = trans.TRAN_IDLE;
403                 _alertBox(Str_alert_customerpasswordfailed + getErrorMessage(r));
404             }
405         }
406     };
407     
408     /**
409       @function
410     
411       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
412      */
413     var registerBack = function(r) {
414         hideProgress();
415     
416         var rCode = getStatusCode(r);
417         if (appstate == trans.TRAN_CREATECUSTOMER) {
418             if (rCode == '0') {
419                 $.mobile.changePage("regpin.html", page_opt);
420             } else {
421                 _alertBox(Str_alert_createcustomerfailed + getErrorMessage(r));
422             }
423         }
424         appstate = trans.TRAN_IDLE;
425     };
426     
427     /**
428       @function
429     
430       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
431      */
432     var findTxnsBack = function(r) {
433         var rCode = getStatusCode(r);
434         if (appstate == trans.TRAN_TXN) {
435             if (rCode == '0') {
436                 if (txnsParseXML(r))
437                     return true;
438                 else {
439                     _alertBox(Str_alert_notransactionhistory);
440                     return false;
441                 }
442             } else {
443                 _alertBox(Str_alert_gettransactionhistoryfailed + getErrorMessage(r));
444                 return false;
445             }
446         }
447     };
448     
449     /**
450     @function
451     
452     @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
453     */
454     var getTxnDetailsBack = function(r) {
455         var rCode = getStatusCode(r);
456         if (appstate == trans.TRAN_TXN) {
457             if (rCode == '0') {
458                 session.transit_value = txnDetailParse(r);
459                 return true;
460             } else {
461                 _alertBox(Str_alert_transactiondetailfailed + getErrorMessage(r));
462                 return false;
463             }
464         }
465     };
466     
467     /**
468       @function
469     
470       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
471      */
472     var getInvoiceTypesByGroupBack = function(r) {
473         hideProgress();
474     
475         var rCode = getStatusCode(r);
476         if (appstate == trans.TRAN_TOPUP) {
477             if (rCode == '0') {
478                 if (parseGroupInvoiceTypes(r))
479                     $.mobile.changePage("prepaid.html", page_opt);
480                 else {
481                     appstate = trans.TRAN_IDLE;
482                     _alertBox(Str_alert_nooperatorregistered);
483                 }
484             } else {
485                 // if failed then...
486                 appstate = trans.TRAN_IDLE;
487                 _alertBox(Str_alert_getinvoicetypefailed + getErrorMessage(r));
488             }
489         }
490     };
491     
492     /**
493       @function
494     
495       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
496      */
497     var createInvoiceForInvoiceTypeBack = function(r) {
498         var rCode = getStatusCode(r);
499         if (appstate == trans.TRAN_TOPUP) {
500             if (rCode == '0') {
501                 mc.topUp(topUpCallBack, parseReturnEntry(r, 'invoiceId'));
502             } else {
503                 hideProgress();
504                 appstate = trans.TRAN_IDLE;
505                 _alertBox(Str_alert_getinvoicetypefailed + getErrorMessage(r));
506             }
507         }
508     };
509     
510     /**
511       @function
512     
513       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
514      */
515     var getBillTypeBack = function(r) {
516         var rCode = getStatusCode(r);
517         if (appstate == trans.TRAN_ENTERPAYBILL) {
518             if (rCode == '0') {
519                 session.billTypes = [];
520                 parseInvoiceTypes(r);
521                 mc.getRegisteredBills(registeredBillsBack, session.customer.id);
522             } else {
523                 hideProgress();
524                 appstate = trans.TRAN_IDLE;
525                 _alertBox(Str_alert_getbilltypefailed + getErrorMessage(r));
526             }
527         }
528     };
529     
530     /**
531       @function
532     
533       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
534      */
535     var registeredBillsBack = function(r) {
536         var rCode = getStatusCode(r);
537         if (rCode == '0') {
538             session.registeredbill = [];
539             userbills = parseRegisteredBills(r);
540     
541             if( appstate == trans.TRAN_ENTERPAYBILL ) {
542                 mc.getOpenInvoices(getOpenInvoicesBack, session.customer.id);
543             } else if ( appstate == trans.TRAN_PAYANEWBILL ) {
544                 hideProgress();
545                 appstate = trans.TRAN_IDLE;
546     
547                 if (userbills) {
548                     $.mobile.changePage("paybilldetail.html", page_opt);
549                 } else
550                     _alertBox(Str_alert_registerbill);
551             }
552         } else {
553             hideProgress();
554             appstate = trans.TRAN_IDLE;
555             _alertBox(Str_alert_registerbillfailed + getErrorMessage(r));
556         }
557     };
558     
559     /**
560       @function
561     
562       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
563      */
564     var registerSimpleBack = function(r) {
565         hideProgress();
566     
567         var rCode = getStatusCode(r);
568         if (appstate == trans.TRAN_REGISTERBILL) {
569             if (rCode == '0') {
570                 _alertBox(Str_alert_registerbillsuccess);
571                 $.mobile.changePage("paybill.html", page_opt);
572             } else {
573                 _alertBox(Str_alert_registersimplebackfailed + getErrorMessage(r));
574             }
575         }
576         appstate = trans.TRAN_IDLE;
577     };
578     
579     /**
580       @function
581     
582       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
583      */
584     var getOpenInvoicesBack = function(r) {
585         hideProgress();
586     
587         var rCode = getStatusCode(r);
588         if (rCode == '0') {
589             var h1 = 0;
590             var h2 = 0;
591             session.openRequestArray = [];
592             session.openBillArray = [];
593             parseOpenInvoices(r);
594     
595             if (appstate == trans.TRAN_ENTERPAYBILL)
596                 $.mobile.changePage("paybill.html", page_opt);
597             else if (appstate == trans.TRAN_SENDBILL)
598                 $.mobile.changePage("paybilldone.html", page_opt);
599         } else {
600             _alertBox(Str_alert_openinvoicefailed + getErrorMessage(r));
601         }
602         appstate = trans.TRAN_IDLE;
603     };
604     
605     /**
606       @function
607     
608       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
609      */
610     var createInvoiceBack = function(r) {
611         var rCode = getStatusCode(r);
612         if (appstate == trans.TRAN_SENDBILL) {
613             if (rCode == '0') {
614                 session.transit_value.invoiceId = parseReturnEntry(r, 'invoiceId');
615                 mc.payBill(payBillOrCancelBack, session.transit_value.invoiceId, $('#billfromaccount').val());
616             } else {
617                 appstate = trans.TRAN_IDLE;
618                 hideProgress();
619                 _alertBox(Str_alert_createinvoicefailed + getErrorMessage(r));
620             }
621         }
622     };
623     
624     /**
625       @function
626     
627       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
628      */
629     var preAuthoriseBack = function(r) {
630         var rCode = getStatusCode(r);
631         if (rCode == '0') {
632             session.transit_value.sysid = parseTransactionSystemId(r);
633             session.transit_value.referno = parseTransactionValue(r);
634             session.transit_value.payerFee = parseTransactionFee(r, "false");
635             session.transit_value.payeeFee = parseTransactionFee(r, "true");
636             return true;
637         } else if (rCode == '2501' && appstate == trans.TRAN_SENDMONEY) {
638             return rCode;
639         } else {
640             _alertBox(Str_alert_failedpreauthorise + getErrorMessage(r));
641             return false;
642         }
643     };
644     
645     /**
646       @function
647     
648       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
649      */
650     var startVoucherBack = function(r) {
651         var rCode = getStatusCode(r);
652         if (appstate == trans.TRAN_SENDMONEY) {
653             if (rCode == '0') {
654                 session.transit_value.sysid = parseTransactionSystemId(r);
655                 session.transit_value.referno = parseTransactionValue(r);
656                 session.transit_value.payerFee = parseTransactionFee(r, "false");
657                 session.transit_value.payeeFee = parseTransactionFee(r, "true");
658                 return true;
659             } else {
660                 _alertBox(Str_alert_startvoucherfailed + getErrorMessage(r));
661                 return false;
662             }
663         }
664     };
665     
666     /**
667       @function
668     
669       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
670     */
671     var confirmVoucherBack = function(r) {
672         var rCode = getStatusCode(r);
673         if (rCode == '0') {
674             session.transit_value.sysid = parseTransactionSystemId(r);
675             session.transit_value.referno = parsePickupCode(r);
676             return true;
677         } else {
678             _alertBox(Str_alert_failedtoconfirmvoucher + getErrorMessage(r));
679             return false;
680         }
681     };
682     
683     /**
684       @function
685     
686       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
687      */
688     var authoriseBack = function(r) {
689         var failureMsg;
690     
691         var rCode = getStatusCode(r);
692         if (appstate == trans.TRAN_SENDMONEY) {
693             failureMsg = Str_alert_sendmoneyfailed;
694         } else if (appstate == trans.TRAN_SENDREQUEST) {
695             failureMsg = Str_alert_sendrequestfailed;
696         } else if (appstate == trans.TRAN_LOADSVA) {
697             failureMsg = Str_alert_loadSVAfailed;
698         } else if (appstate == trans.TRAN_UNLOADSVA) {
699             failureMsg = Str_alert_unloadsvafailed;
700         }
701     
702         if (rCode == '0') {
703             session.transit_value.sysid = parseTransactionSystemId(r);
704             return true;
705         } else {
706             _alertBox(failureMsg + getErrorMessage(r));
707             return false;
708         }
709     };
710     
711     /**
712       @function
713     
714       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
715      */
716     var demandForPaymentBack = function(r) {
717         var rCode = getStatusCode(r);
718         if (appstate == trans.TRAN_SENDREQUEST) {
719             if (rCode == '0') {
720                 session.transit_value.sysid = parseReturnEntry(r, 'invoiceId');
721                 return true;
722             } else {
723                 _alertBox(Str_alert_sendrequestfailed + getErrorMessage(r));
724                 return false;
725             }
726         }
727     };
728     
729     /**
730       @function
731     
732       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
733      */
734     var topUpCallBack = function(r) {
735         _payBillOrCancelBack(r, true);
736     };
737     
738     /**
739       @function
740     
741       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
742      */
743     var payBillOrCancelBack = function(r) {
744         _payBillOrCancelBack(r, true);
745     };
746     
747     /**
748       @function
749     
750       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
751      */
752     var payBillBack = function(r) {
753         _payBillOrCancelBack(r, false);
754     };
755     
756     /**
757       @function
758     
759       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
760       @param  doCancel The flag to trigger cancel action.
761       */
762     function _payBillOrCancelBack(r, doCancel) {
763         var nextPage;
764         var errmsg = null;
765         if (appstate == trans.TRAN_SENDBILL) {
766             nextPage = "paybillconfirm";
767             errmsg = Str_alert_paybillfailed;
768         } else if (appstate == trans.TRAN_TOPUP) {
769             nextPage = "prepaidconfirm";
770             errmsg = Str_alert_topupfailed;
771         }
772     
773         var rCode = getStatusCode(r);
774         if (rCode == '0') {
775             session.transit_value.sysid = parseTransactionSystemId(r);
776             session.transit_value.referno = parseTransactionValue(r);
777             session.transit_value.payerFee = parseTransactionFee(r, "false");
778             session.transit_value.payeeFee = parseTransactionFee(r, "true");
779             $.mobile.changePage(nextPage + ".html", page_opt);
780             hideProgress();
781         } else {
782             if (trans.TRAN_TOPUP != appstate && doCancel) { //openbill TRAN_SENDBILL state
783                 _alertBox(errmsg + getErrorMessage(r) +'\n'+ Str_alert_cancelinvoiceno + session.transit_value.invoiceId);
784                 mc.cancelBill(cancelBillBack, session.transit_value.invoiceId);
785             } else {
786                 // if request fails to execute
787                 _alertBox(errmsg + getErrorMessage(r));
788                 hideProgress();
789                 appstate = trans.TRAN_IDLE;
790             }
791         }
792     }
793     
794     /**
795       @function
796     
797       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
798      */
799     var continuePayOrCancelBack = function(r) {
800         _continuePayInvoiceOrCancelBack(r, true);
801     };
802     
803     /**
804     @function
805     
806     @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
807     */
808     var continuePayBack = function(r) {
809         _continuePayInvoiceOrCancelBack(r, false);
810     };
811     
812     /**
813     @function
814     
815     @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
816     @param  doCancel The flag to trigger cancel action.
817     */
818     function _continuePayInvoiceOrCancelBack(r, doCancel) {
819         var nextPage;
820         var errmsg = null;
821         if (appstate == trans.TRAN_SENDBILL) {
822             nextPage = "paybilldone";
823             errmsg = Str_alert_paybillfailed;
824         } else if (appstate == trans.TRAN_TOPUP) {
825             nextPage = "prepaiddone";
826             errmsg = Str_alert_topupfailed;
827         }
828     
829         var rCode = getStatusCode(r);
830         if (rCode == '0') {
831             if (doCancel) {
832                 session.transit_value.sysid = parseTransactionSystemId(r);
833                 $.mobile.changePage(nextPage + ".html", page_opt);
834                 hideProgress();
835                 appstate = trans.TRAN_IDLE;
836             } else { //openbill TRAN_SENDBILL state
837                 mc.getOpenInvoices(getOpenInvoicesBack, session.customer.id);
838             }
839         } else {
840             if (doCancel) {
841                 _alertBox( errmsg + getErrorMessage(r) +'\n' + Str_alert_cancelinvoiceno + session.transit_value.invoiceId);
842                 mc.cancelBill(cancelBillBack, session.transit_value.invoiceId);
843             } else { // if request fails to execute
844                 _alertBox(errmsg + getErrorMessage(r));
845                 hideProgress();
846                 appstate = trans.TRAN_IDLE;
847             }
848         }
849     }
850     
851     /**
852       @function
853     
854       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
855      */
856     var cancelBillBack = function(r) {
857         hideProgress();
858     
859         var rCode = getStatusCode(r);
860         if (rCode != '0') {
861             _alertBox(Str_alert_calncelinvoicefailed + getErrorMessage(r));
862         }
863         appstate = trans.TRAN_IDLE;
864     };
865     
866     /**
867       @function
868     
869       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
870     */
871     var getBalanceAlertBack = function(r) {
872         var rCode = getStatusCode(r);
873         if (rCode == '0') {
874             parseBalanceAlert(r);
875             return true;
876         } else {
877             _alertBox(Str_alert_balancealertfailed + getErrorMessage(r));
878             return false;
879         }
880     };
881     
882     /**
883       @function
884     
885       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
886     */
887     var createBalanceAlertBack = function(r) {
888         var rCode = getStatusCode(r);
889         if (rCode == '0') {
890             return true;
891         } else {
892             _alertBox(Str_alert_addbalancealert + Str_alert_isfailed + getErrorMessage(r));
893             return false;
894         }
895     };
896     
897     /**
898       @function
899     
900       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
901     */
902     var updateBalanceAlertBack = function(r) {
903         var rCode = getStatusCode(r);
904         if (rCode == '0') {
905             return true;
906         } else {
907             _alertBox(Str_alert_editbalancealert + Str_alert_isfailed + getErrorMessage(r));
908             return false;
909         }
910     };
911     
912     /**
913       @function
914     
915       @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
916     */
917     var deleteBalanceAlertBack = function(r) {
918         var rCode = getStatusCode(r);
919         if (rCode == '0') {
920             return true;
921         } else {
922             _alertBox(Str_alert_removebalancealert + Str_alert_isfailed + getErrorMessage(r));
923             return false;
924         }
925     };
926     
927     /**
928         @ResponseBack Coupon Features
929      */
930     
931     /**
932     @function
933     
934     @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
935     */
936     var getMyCouponsBack = function(r) {
937         var rCode = getStatusCode(r);
938         if (rCode == '0') {
939             couponparseXML(r);
940             return true;
941         } else {
942             _alertBox(Str_alert_getcouponfailed + getErrorMessage(r));
943             return false;
944         }
945     };
946     
947     /**
948     @function
949     
950     @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
951     */
952     var deleteCouponBack = function(r) {
953         var rCode = getStatusCode(r);
954         if (rCode == '0') {
955             _alertBox(Str_alert_coupondeletedsuccussfully);
956             return true;
957         } else {
958             _alertBox(Str_alert_deletedcouponfailed + getErrorMessage(r));
959             return false;
960         }
961     };
962     
963     /**
964     @function
965     
966     @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
967     */
968     var purchaseCouponBack = function(r) {
969         var rCode = getStatusCode(r);
970         if (rCode == '0') {
971             _alertBox(Str_alert_couponpurchasesuccess);
972             return true;
973         } else {
974             _alertBox(Str_alert_couponpurchasefailed + getErrorMessage(r));
975             return false;
976         }
977     };
978     
979     /**
980     @function
981     
982     @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
983     */
984     var getRootCategoriesBack = function(r) {
985         var rCode = getStatusCode(r);
986         if (rCode == '0') {
987             getRootCategoriesParseXML(r);
988             return true;
989         } else {
990             _alertBox(Str_alert_rootcategoryfailed + getErrorMessage(r));
991             return false;
992         }
993     };
994     
995     /**
996     @function
997     
998     @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
999     */
1000    var getCategoryTreeBack = function(r) {
1001        var rCode = getStatusCode(r);
1002        if (rCode == '0') {
1003             if (!getCategoryTreeBackParseXML(r))
1004                 _alertBox(Str_alert_nocategoryavailable);
1005            return true;
1006        } else {
1007            _alertBox(Str_alert_rootcategoryfailed + getErrorMessage(r));
1008            return false;
1009        }
1010    };
1011    
1012    /**
1013    @function
1014    
1015    @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1016    */
1017    var getChildCategoriesBack = function(r) {
1018        var rCode = getStatusCode(r);
1019        if (rCode == '0') {
1020            getChildCategoriesParseXML(r);
1021            return true;
1022        } else {
1023            _alertBox(Str_alert_childcategoryfailed + getErrorMessage(r));
1024            return false;
1025        }
1026    };
1027    
1028    /**
1029    @function
1030    
1031    @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1032    */
1033    var getCouponTypesForCategoryBack = function(r) {
1034        var rCode = getStatusCode(r);
1035        if (rCode == '0') {
1036            getCouponTypesofCategoryParseXML(r);
1037            return true;
1038        } else {
1039            _alertBox(Str_alert_coupontypesfaild + getErrorMessage(r));
1040            return false;
1041        }
1042    };
1043    
1044    /**
1045    @function
1046    
1047    @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1048    */
1049    var assignCouponBack = function(r) {
1050        var rCode = getStatusCode(r);
1051        if (rCode == '0') {
1052            _alertBox(Str_alert_couponaddedsuccess);
1053            return true;
1054        } else {
1055            _alertBox(Str_alert_assigncouponfailed + getErrorMessage(r));
1056            return false;
1057        }
1058    };
1059    
1060    /**
1061    @function
1062    
1063    @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1064    */
1065    var findCouponTypesByTagsBack = function(r) {
1066        var rCode = getStatusCode(r);
1067        if (rCode == '0') {
1068            couponTypesByTagsparseXML(r);
1069            return true;
1070        } else {
1071            _alertBox(Str_alert_failedtogetcoupontypes + getErrorMessage(r));
1072            return false;
1073        }
1074    };
1075    
1076    
1077    /**
1078      @function retrieve upload URL
1079    
1080      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1081     */
1082    var getUploadPictureURLBack = function(r) {
1083        var rCode = getStatusCode(r);
1084        if (rCode == '0') {
1085            session.uploadUrl = parseReturnEntry(r, 'uploadUrl');
1086        } else {
1087            hideProgress();
1088            _alertBox(Str_alert_failgetuploadurl + getErrorMessage(r));
1089            appstate = trans.TRAN_IDLE;
1090        }
1091    };
1092    
1093    /**
1094      @function retrieve download URL
1095    
1096      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1097     */
1098    var downloadPictureURLBack = function(r) {
1099        var rCode = getStatusCode(r);
1100        if (rCode == '0') {
1101            session.downloads = [];
1102            if (r.pictures) {
1103                for (var i = 0, len = r.pictures.length, picture; i < len; i ++) {
1104                    picture = r.pictures[i];
1105                    session.downloads.push({url: picture.url, contentType: picture.contentType});
1106                }
1107            }
1108        } else
1109            _alertBox(Str_alert_failgetdownloadurl + getErrorMessage(r));
1110    };
1111    
1112    /**
1113      @function retrieve locations
1114    
1115      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1116     */
1117    var findNextAddressesBack = function(r) {
1118        var rCode = getStatusCode(r);
1119        if (rCode == '0') {
1120            session.locations = r.location;
1121        } else {
1122            hideProgress();
1123            _alertBox(Str_alert_failfindnextaddrs + getErrorMessage(r));
1124            appstate = trans.TRAN_IDLE;
1125        }
1126    };
1127    
1128    /**
1129      @function get Default TermAndConditions
1130    
1131      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1132     */
1133    var getDefaultTermAndConditionsBack = function(r) {
1134        var rCode = getStatusCode(r);
1135        if (rCode == '0') {
1136            session.defaultTermAndConditions = r.termAndCondition;
1137            return true;
1138        } else {
1139            _alertBox(Str_alert_failgetdefaulttandc + getErrorMessage(r));
1140            return false;
1141        }
1142    };
1143    
1144    /**
1145      @function get Open TermAndConditions
1146    
1147      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1148     */
1149    var getOpenTermAndConditionsBack = function(r) {
1150        var rCode = getStatusCode(r);
1151        if (rCode == '0') {
1152            session.openTermAndConditions = r.termAndCondition;
1153            return true;
1154        } else {
1155            _alertBox(Str_alert_failgetopentandc + getErrorMessage(r));
1156            return false;
1157        }
1158    };
1159    
1160    /**
1161      @function accept TermAndConditions
1162    
1163      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1164     */
1165    var acceptTermAndConditionsBack = function(r) {
1166        var rCode = getStatusCode(r);
1167        if (rCode == '0') {
1168            if (r.privileges)
1169                for (var i=0; i<r.privileges.length; i++)
1170                    session.customer.privileges.push(r.privileges[i]);
1171            return true;
1172        } else {
1173            _alertBox(Str_alert_failaccepttandc + getErrorMessage(r));
1174            return false;
1175        }
1176    };
1177    
1178    /**
1179    @function
1180    
1181    @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1182    */
1183    var findNextCouponTypesBack = function(r) {
1184        var rCode = getStatusCode(r);
1185        if (rCode == '0') {
1186            session.couponTypes = r.result;
1187            return true;
1188        } else {
1189            _alertBox(Str_alert_failedtogetcoupontypes + getErrorMessage(r));
1190            return false;
1191        }
1192    };
1193    
1194    /*****************************************************************************
1195     * Functions
1196     */
1197    
1198    /**
1199      @function
1200    
1201      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1202    */
1203    function getStatusCode(r) {
1204        return r.Status.code.toString();
1205    }
1206    
1207    /**
1208      @function
1209    
1210      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1211      @param  entryName This is string of the entry node name in XML document/JSON object.
1212    */
1213    function parseReturnEntry(r, entryName) {
1214        return r[entryName];
1215    }
1216    
1217    /**
1218      @function
1219    
1220      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1221      @param  entryName This is string of the entry node name in XML document/JSON object.
1222      @param  attrName This is string of attribute name of the entry node in XML document/JSON object.
1223    */
1224    function parseReturnEntryAttr(r, entryName, attrName) {
1225        return r[entryName][attrName].toString();
1226    }
1227    
1228    /**
1229      @function
1230    
1231      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1232    */
1233    function parseIdentification(r) {
1234        var msisdn = null;
1235        if (r.identifications && r.identifications.length) {
1236            for(var i = 0;i < r.identifications.length;i++) {
1237                if (r.identifications[i].type == 0) {
1238                    session.identification = r.identifications[i];
1239                    msisdn = r.identifications[i].identification;
1240                    break;
1241                }
1242            }
1243        }
1244        return msisdn;
1245    }
1246    
1247    /**
1248      @function
1249    
1250      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1251    */
1252    function parseTransactionSystemId(r) {
1253        if (r.Transaction && r.Transaction.systemId)
1254            return r.Transaction.systemId;
1255        else
1256            return null;
1257    }
1258    
1259    /**
1260      @function
1261    
1262      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1263    */
1264    function parseTransactionValue(r) {
1265        if (r.Transaction && r.Transaction.value)
1266            return r.Transaction.value;
1267        else
1268            return null;
1269    }
1270    
1271    /**
1272    @function
1273    
1274    @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1275    */
1276    function parseTransactionFee(r, isPayee) {
1277        var transactionfee = 0;
1278    
1279    	if (r.MoneyFee)
1280            for (var i=0; i<r.MoneyFee.length; i++)
1281                if (r.MoneyFee[i].payee == isPayee)
1282                    transactionfee += parseFloat(r.MoneyFee[i].value);
1283    
1284        return transactionfee;
1285    }
1286    
1287    /**
1288      @function
1289    
1290      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1291    */
1292    function parseGroupInvoiceTypes(r) {
1293        // Callback to application processing
1294        if (r.invoiceType !== null) {
1295            session.transit_value = r.invoiceType;
1296            return r.invoiceType.length;
1297        } else
1298            return 0;
1299    }
1300    
1301    /**
1302      @function
1303    
1304      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1305    */
1306    function parseInvoiceTypes(r) {
1307        if (r.invoiceType !== null) {
1308            for (var i=0; i<r.invoiceType.length; i++) {
1309                session.billTypes[i] = new BillTypes();
1310                session.billTypes[i].billTypeId = r.invoiceType[i].id;
1311                session.billTypes[i].billTypeName = r.invoiceType[i].name;
1312                session.billTypes[i].billTypeGroupId = r.invoiceType[i].groupId;
1313            }
1314        }
1315    }
1316    
1317    /**
1318      @function
1319    
1320      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1321    */
1322    function parseRegisteredBills(r) {
1323        var userbills_number = 0;
1324    
1325        if (r.invoiceConfiguration !== null) {
1326            for (var i=0; i<r.invoiceConfiguration.length; i++) {
1327                session.registeredbill[i] = new Registeredbill();
1328                session.registeredbill[i].billConfigId = r.invoiceConfiguration[i].id;
1329                session.registeredbill[i].billTypeId = r.invoiceConfiguration[i].invoiceTypeId;
1330                session.registeredbill[i].alias =
1331                    (r.invoiceConfiguration.alias === null) ? "" : r.invoiceConfiguration[i].alias;
1332                session.registeredbill[i].reference = r.invoiceConfiguration[i].reference;
1333                session.registeredbill[i].billTypeName = "";
1334                session.registeredbill[i].billTypeGroupId = "";
1335                for (var j=0; j<session.billTypes.length; j++) {
1336                    if (session.billTypes[j].billTypeId == session.registeredbill[i].billTypeId) {
1337                        session.registeredbill[i].billTypeName = session.billTypes[j].billTypeName;
1338                        session.registeredbill[i].billTypeGroupId = session.billTypes[j].billTypeGroupId;
1339                        if (session.billTypes[j].billTypeGroupId == 0) {
1340                            userbills_number++;
1341                        }
1342                        break;
1343                    }
1344                }
1345            }
1346        }
1347        return userbills_number;
1348    }
1349    
1350    /**
1351      @function
1352    
1353      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1354    */
1355    function parseOpenInvoices(r) {
1356        var h1=0;
1357        var h2=0;
1358    
1359        if (r.invoice !== null) {
1360            for (var i=0; i<r.invoice.length; i++) {
1361                var date = (r.invoice[i].data === null) ? "-" : epoch2UTC(r.invoice[i].date).split("T")[0];
1362    
1363                for (var j=0; j<session.registeredbill.length; j++) {
1364                    if (r.invoice[i].invoiceConfigurationId == session.registeredbill[j].billConfigId) {
1365                        var billTypeName = session.registeredbill[j].alias + ":" +
1366                                            session.registeredbill[j].billTypeName;
1367                        var invConfReference = session.registeredbill[j].reference;
1368    
1369                        if (session.registeredbill[j].billTypeGroupId == 3) {
1370                            session.openRequestArray[h1] = new OpenBill();
1371                            session.openRequestArray[h1].billId = r.invoice[i].id;
1372                            session.openRequestArray[h1].billTypeName = billTypeName;
1373                            session.openRequestArray[h1].dueDate = date;
1374                            session.openRequestArray[h1].amount = r.invoice[i].amount / 100;
1375                            session.openRequestArray[h1].reference = invConfReference;
1376                            session.openRequestArray[h1].billreference = r.invoice[i].reference;
1377                            h1++;
1378                        } else if (session.registeredbill[j].billTypeGroupId == 0) {
1379                            session.openBillArray[h2] = new OpenBill();
1380                            session.openBillArray[h2].billId = r.invoice[i].id;
1381                            session.openBillArray[h2].billTypeName = billTypeName;
1382                            session.openBillArray[h2].dueDate = date;
1383                            session.openBillArray[h2].amount = r.invoice[i].amount / 100;
1384                            session.openBillArray[h2].reference = invConfReference;
1385                            session.openBillArray[h2].billreference = r.invoice[i].reference;
1386                            h2++;
1387                        }
1388                        break;
1389                    }
1390                }
1391            }
1392        }
1393    }
1394    
1395    /**
1396      @function
1397    
1398      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1399    */
1400    function parsePickupCode(r) {
1401        for (var i=0; i<r.UnstructuredData.length; i++)
1402            if (r.UnstructuredData[i].Key == "PickupCode") {
1403                return r.UnstructuredData[i].Value;
1404                break;
1405            }
1406        return null;
1407    }
1408    
1409    /**
1410      @function
1411    
1412      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1413    */
1414    function parseBalanceAlert(r) {
1415        session.svaalert = [];
1416        for (var i=0; i<r.BalanceAlerts.length; i++) {
1417            session.svaalert[i] = new BalanceAlert();
1418            session.svaalert[i].id = r.BalanceAlerts[i].id;
1419            session.svaalert[i].paymentInstrumentId = r.BalanceAlerts[i].paymentInstrumentId;
1420            session.svaalert[i].threshold = r.BalanceAlerts[i].threshold / 100;
1421            session.svaalert[i].active = r.BalanceAlerts[i].active;
1422            session.svaalert[i].onlyTransition = r.BalanceAlerts[i].onlyTransition;
1423            session.svaalert[i].templateName = r.BalanceAlerts[i].templateName;
1424        }
1425    }
1426    
1427    /**
1428      @function
1429    
1430      @param  response This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1431     */
1432    function loginParseXML(response) {
1433        if (response.sessionId !== null)
1434            session.sessionId = response.sessionId;
1435        if (response.sessionTimeoutSeconds !== null)
1436            sessionTimeoutWindow = response.sessionTimeoutSeconds * 1000;
1437    
1438        if (response.customer !== null) {
1439            session.customer = response.customer;
1440        }
1441    }
1442    
1443    /**
1444    @function
1445    
1446    @param  response This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1447    */
1448    function fbssloginParseXML(response) {
1449        //console.log("fbssologin:" + JSON.stringify(response));
1450        if (response.sessionId !== null)
1451            session.sessionId = response.sessionId;
1452        if (response.sessionTimeoutSeconds !== null)
1453            sessionTimeoutWindow = response.sessionTimeoutSeconds * 1000;
1454    
1455        if (response.user !== null) {
1456            session.customer = response.user;
1457        }
1458    }
1459    
1460    /**
1461    @function
1462    
1463    @param  response This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1464    */
1465    function getRsaPublicKeyParseXML(response) {
1466      if (response.sessionId !== null)
1467          session.sessionId = response.sessionId;
1468      if (response.sessionTimeoutSeconds !== null)
1469          sessionTimeoutWindow = response.sessionTimeoutSeconds * 1000;
1470    
1471      if (response.user !== null) {
1472          //session.customer.customerId = response.user.id;
1473          //session.customer.orgUnitId = response.user.orgUnitId;
1474          //session.customer.blacklist = response.user.blackListReason;
1475          //session.customer.active = response.user.active;
1476          //session.customer.test = response.user.test;
1477          //session.customer.displayName = response.user.displayName;
1478          //session.customer.riskCategoryId = response.user.riskCategoryId;
1479          //session.customer.typeId = response.user.customerTypeId;
1480          //session.customer.cancelId = response.user.cancellationReasonId;
1481          //session.customer.modeId = response.user.txnReceiptModeId;
1482      }
1483    }
1484    
1485    /**
1486      @function
1487    
1488      @param  response This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1489     */
1490    function walletParseXML(response) {
1491        var j = 1, k = 0;
1492        session.accounts = [];
1493        session.totalaccounts = 0;
1494    
1495        for (var i=0; i<response.walletEntries.length; i++) {
1496            if (response.walletEntries[i].creditCard !== null) {
1497                session.accounts[j] = new Accounts();
1498                session.accounts[j].walletId = response.walletEntries[i].id;
1499                session.accounts[j].creditPriority = response.walletEntries[i].creditPriority;
1500                session.accounts[j].debitPriority = response.walletEntries[i].debitPriority;
1501                session.accounts[j].pIId = response.walletEntries[i].paymentInstrumentId;
1502                session.accounts[j].info = response.walletEntries[i].alias;
1503                session.accounts[j].type = "CreditCard";
1504                session.accounts[j].pIClass = 'creditcard';
1505                session.accounts[j].no = response.walletEntries[i].creditCard.cardNumber;
1506                session.accounts[j].acctHolderName = response.walletEntries[i].creditCard.cardHolderName;
1507                session.accounts[j].acctNumber = '';
1508                session.accounts[j].displayNumber = response.walletEntries[i].creditCard.displayNumber;
1509                session.accounts[j].extra1 = response.walletEntries[i].creditCard.cardType;
1510                session.accounts[j].extra2 = response.walletEntries[i].creditCard.securityNumber;
1511                session.accounts[j].extra3 = response.walletEntries[i].creditCard.yearExpiry;
1512                session.accounts[j].extra4 = response.walletEntries[i].creditCard.monthExpiry;
1513                j++;
1514            } else if (response.walletEntries[i].bankAccount !== null && response.walletEntries[i].bankAccount.status == 0) {
1515                session.accounts[j] = new Accounts();
1516                session.accounts[j].walletId = response.walletEntries[i].id;
1517                session.accounts[j].creditPriority = response.walletEntries[i].creditPriority;
1518                session.accounts[j].debitPriority = response.walletEntries[i].debitPriority;
1519                session.accounts[j].pIId = response.walletEntries[i].paymentInstrumentId;
1520                session.accounts[j].info = response.walletEntries[i].alias;
1521                session.accounts[j].type = "BankAccount";
1522                session.accounts[j].pIClass = 'bank';
1523                session.accounts[j].no = response.walletEntries[i].bankAccount.accountNumber;
1524                session.accounts[j].acctHolderName = response.walletEntries[i].bankAccount.accountHolderName;
1525                session.accounts[j].acctNumber = '';
1526                session.accounts[j].displayNumber = response.walletEntries[i].bankAccount.displayNumber;
1527                session.accounts[j].extra1 = response.walletEntries[i].bankAccount.bankCode;
1528                session.accounts[j].extra2 = response.walletEntries[i].bankAccount.branchCode;
1529                session.accounts[j].extra3 = response.walletEntries[i].bankAccount.bankName;
1530                session.accounts[j].extra4 = response.walletEntries[i].bankAccount.bankCountry;
1531                j++;
1532            } else if (response.walletEntries[i].sva !== null) {
1533                session.accounts[0] = new Accounts();
1534                session.accounts[0].walletId = response.walletEntries[i].id;
1535                session.accounts[0].creditPriority = response.walletEntries[i].creditPriority;
1536                session.accounts[0].debitPriority = response.walletEntries[i].debitPriority;
1537                session.accounts[0].pIId = response.walletEntries[i].paymentInstrumentId;
1538                session.accounts[0].info = response.walletEntries[i].sva.creditBalance -
1539                            response.walletEntries[i].sva.debitBalance;
1540                session.accounts[0].type = "SVA";
1541                session.accounts[0].pIClass = 'sva';
1542                session.accounts[0].no = '';
1543            } else if (response.walletEntries[i].offlineSva !== null) {
1544                session.offlinesvas[k] = new Accounts();
1545                session.offlinesvas[k].walletId = response.walletEntries[i].id;
1546                session.offlinesvas[k].creditPriority = response.walletEntries[i].creditPriority;
1547                session.offlinesvas[k].debitPriority = response.walletEntries[i].debitPriority;
1548                session.offlinesvas[k].pIId = response.walletEntries[i].paymentInstrumentId;
1549                session.offlinesvas[k].info = response.walletEntries[i].offlineSva.balanceAmount;
1550                session.offlinesvas[k].type = "OFFLINESVA";
1551                session.offlinesvas[k].pIClass = 'offlinesva';
1552                session.offlinesvas[k].no = response.walletEntries[i].offlineSva.svaCode;
1553                session.offlinesvas[k].displayNumber = response.walletEntries[i].offlineSva.svaCode;
1554                k++;
1555            }
1556        }
1557        session.totalaccounts = j;
1558    }
1559    
1560    /**
1561      @function
1562    
1563      @param  response This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1564     */
1565    function txnsParseXML(response) {
1566        var max = response.transactions.length < 10 ? response.transactions.length : 10;
1567    
1568        for (var i=0; i<max; i++) {
1569            session.transaction[i] = new Transaction();
1570    
1571            if (response.transactions[i].id !== null)
1572                session.transaction[i].transactionId = response.transactions[i].id;
1573    
1574            if (response.transactions[i].creationDate !== null)
1575                session.transaction[i].transactionDate = epoch2UTC(response.transactions[i].creationDate);
1576    
1577            if (response.transactions[i].amount !== null)
1578                session.transaction[i].amount = response.transactions[i].amount.value / 100;
1579    
1580            if (response.transactions[i].useCase !== null)
1581                session.transaction[i].usecase = response.transactions[i].useCase;
1582    
1583            switch (session.transaction[i].usecase) {
1584                case 174:
1585                case 193:
1586                case 194:
1587                case 191:
1588                case 202:
1589                    for (var j=0; j<session.totalaccounts; j++) {
1590                        if (response.transactions[i].payerPiId !== null &&
1591                            response.transactions[i].payerPiId == session.accounts[j].pIId)
1592                        session.transaction[i].amount *= -1;
1593                    }
1594                    break;
1595                case 173:
1596                case 161:
1597                case 500:
1598                case 502:
1599                    session.transaction[i].amount *= -1;
1600                    break;
1601            }
1602            session.transaction[i].amount = session.transaction[i].amount.toFixed(2);
1603        }
1604    
1605        return max;
1606    }
1607    
1608    /**
1609      @function
1610    
1611      @param  response This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1612    */
1613    function txnDetailParse(response) {
1614        if (response.transaction !== null) {
1615            var tranDate = new Date(response.transaction.creationDate);
1616            var txn = new Object();
1617            txn.Date = tranDate.getFullYear()+'-'+pad2(tranDate.getMonth()+1)+'-'+pad2(tranDate.getDate());
1618            txn.Time = pad2(tranDate.getHours())+':'+pad2(tranDate.getMinutes())+':'+pad2(tranDate.getSeconds());
1619            txn.Type = getUseCaseName(response.transaction.useCase);
1620            txn.Error = response.transaction.errorCode;
1621            txn.Name = (response.transaction.payerDisplayName == session.customer.displayName) ?
1622                          response.transaction.payeeDisplayName :
1623                          response.transaction.payerDisplayName;
1624            txn.Reference = response.transaction.authCode;
1625            txn.Details = "";
1626            if (response.transaction.text !== null)
1627                txn.Details = response.transaction.text;
1628            txn.Amount = response.transaction.amount.value/100;
1629            txn.Amount = txn.Amount.toFixed(2);
1630            txn.Fee = (response.transaction.payerDisplayName == session.customer.displayName) ?
1631                    (response.transaction.payerAmount.value/100) - txn.Amount :
1632                    txn.Amount - (response.transaction.payeeAmount.value/100);
1633            txn.Fee = txn.Fee.toFixed(2);
1634            return txn;
1635        }
1636    }
1637    
1638    /**
1639    @function
1640    
1641    @param  response This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1642    */
1643    function couponparseXML(response) {
1644        session.coupons = [];
1645        if (response.coupon) {
1646            for (var i=0; i<response.coupon.length; i++) {
1647                session.coupons[i] = new Coupon();
1648                session.coupons[i].id = response.coupon[i].id;
1649                session.coupons[i].customerId = response.coupon[i].customerId;
1650                if(session.coupons[i].couponType != null)
1651                {
1652                    session.coupons[i].couponType.id = response.coupon[i].couponType.id;
1653                    session.coupons[i].couponType.name = response.coupon[i].couponType.name;
1654                    session.coupons[i].couponType.purchasePrice = response.coupon[i].couponType.purchasePrice ? (response.coupon[i].couponType.purchasePrice/100) : 0;
1655                    session.coupons[i].couponType.purchaseCurrency = response.coupon[i].couponType.purchaseCurrency ? response.coupon[i].couponType.purchaseCurrency : '';
1656                    if(response.coupon[i].couponType.description != null)
1657                    {
1658                        session.coupons[i].couponType.description.caption = response.coupon[i].couponType.description.caption;
1659                        session.coupons[i].couponType.description.imageUrl = response.coupon[i].couponType.description.imageUrl;
1660                        session.coupons[i].couponType.description.thumbnailUrl = response.coupon[i].couponType.description.thumbnailUrl;
1661                    }
1662                }
1663                session.coupons[i].status = response.coupon[i].status;
1664                session.coupons[i].serialNumber = response.coupon[i].serialNumber;
1665                session.coupons[i].validTo = getDateFormatOfSring(response.coupon[i].validTo);
1666                session.coupons[i].code = response.coupon[i].code;
1667                session.coupons[i].views = response.coupon[i].views;
1668                session.coupons[i].uses = response.coupon[i].uses;
1669            }
1670        }
1671    }
1672    
1673    /**
1674    @function
1675    
1676    @param  response This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1677    */
1678    function getRootCategoriesParseXML(response) {
1679        session.categories = [];
1680        if(response.category != null) {
1681            for (var i=0; i<response.category.length; i++) {
1682                session.categories[i] = new Category();
1683                session.categories[i].id = response.category[i].id;
1684                session.categories[i].internalName = response.category[i].internalName;
1685                session.categories[i].caption = response.category[i].caption;
1686                session.categories[i].priority = response.category[i].priority;
1687                session.categories[i].noOfChildCategories = response.category[i].child;
1688                session.categories[i].parent = response.category[i].parent;
1689                session.categories[i].valid = false;
1690            }
1691            return true;
1692        } else
1693            return false;
1694    }
1695    
1696    /**
1697    @function
1698    
1699    @param  response This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1700    */
1701    function getChildCategoriesParseXML(response) {
1702        session.categories = [];
1703        if(response.category != null) {
1704            for (var i=0; i<response.category.length; i++) {
1705                session.categories[i] = new Category();
1706                session.categories[i].id = response.category[i].id;
1707                session.categories[i].internalName = response.category[i].internalName;
1708                session.categories[i].caption = response.category[i].caption;
1709                session.categories[i].priority = response.category[i].priority;
1710                session.categories[i].noOfChildCategories = response.category[i].child;
1711                session.categories[i].parent = response.category[i].parent;
1712                session.categories[i].valid = false;
1713            }
1714            return true;
1715        } else
1716            return false;
1717    }
1718    
1719    /**
1720    @function
1721    
1722    @param  response This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1723    */
1724    function getCouponTypesofCategoryParseXML(response) {
1725        session.couponTypes = [];
1726        if(response.couponType != null) {
1727            for (var i=0; i<response.couponType.length; i++) {
1728                session.couponTypes[i] = {};
1729                session.couponTypes[i].type = response.couponType[i];
1730                session.couponTypes[i].location = null;
1731                session.couponTypes[i].distance = null;
1732    /*
1733                session.couponTypes[i] = new CouponType();
1734                session.couponTypes[i].description = new CouponTypeDescription();
1735    
1736                session.couponTypes[i].id = response.couponType[i].id;
1737                session.couponTypes[i].name = response.couponType[i].name;
1738                session.couponTypes[i].purchasePrice = response.couponType[i].purchasePrice ? (response.couponType[i].purchasePrice/100) : 0;
1739                session.couponTypes[i].purchaseCurrency = response.couponType[i].purchaseCurrency ? response.couponType[i].purchaseCurrency : '';
1740                session.couponTypes[i].maxViews = response.couponType[i].maxViews;
1741                session.couponTypes[i].maxUses = response.couponType[i].maxUses;
1742                session.couponTypes[i].isRestorableByUser = response.couponType[i].isRestorableByUser;
1743                if(response.couponType[i].description != null) {
1744                    session.couponTypes[i].description.mimeType = response.couponType[i].description.mimeType;
1745                    session.couponTypes[i].description.caption = response.couponType[i].description.caption;
1746                    session.couponTypes[i].description.content = response.couponType[i].description.content;
1747                    session.couponTypes[i].description.thumbnailUrl = response.couponType[i].description.thumbnailUrl;
1748                    session.couponTypes[i].description.imageUrl = response.couponType[i].description.imageUrl;
1749                }
1750    */
1751            }
1752        }
1753    }
1754    
1755    
1756    /**
1757    @function
1758    
1759    @param  response This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1760    */
1761    function couponTypesByTagsparseXML(response){
1762        session.couponTypes = [];
1763        if(response.couponType != null) {
1764            for (var i=0; i<response.couponType.length; i++) {
1765                session.couponTypes[i] = {};
1766                session.couponTypes[i].type = response.couponType[i];
1767                session.couponTypes[i].location = null;
1768                session.couponTypes[i].distance = null;
1769    /*
1770                session.couponTypes[i] = new CouponType();
1771                session.couponTypes[i].id = response.couponType[i].id;
1772                session.couponTypes[i].name = response.couponType[i].name;
1773                session.couponTypes[i].purchasePrice = response.couponType[i].purchasePrice ? (response.couponType[i].purchasePrice/100) : 0;
1774                session.couponTypes[i].purchaseCurrency = response.couponType[i].purchaseCurrency ? response.couponType[i].purchaseCurrency : '';
1775                session.couponTypes[i].maxViews = response.couponType[i].maxViews;
1776                session.couponTypes[i].maxUses = response.couponType[i].maxUses;
1777                session.couponTypes[i].isRestorableByUser = response.couponType[i].isRestorableByUser;
1778                if(response.couponType[i].description != null) {
1779                    session.couponTypes[i].description.mimetype = response.couponType[i].description.mimetype;
1780                    session.couponTypes[i].description.caption = response.couponType[i].description.caption;
1781                    session.couponTypes[i].description.content = response.couponType[i].description.content;
1782                    session.couponTypes[i].description.thumbnailUrl = response.couponType[i].description.thumbnailUrl;
1783                    session.couponTypes[i].description.imageUrl = response.couponType[i].description.imageUrl;
1784                }
1785    */
1786            }
1787        }
1788    }
1789    
1790    function getCategoryTreeBackParseXML(response) {
1791        var categories = response.rootCategories;
1792        if (categories && categories.length) {
1793            for (var i=0; i<session.categories.length; i++) {
1794                // Used to retrive an array from category tree, which is having the id value, matching with category id value.
1795                var resp = getArrayOfObjects(categories, "id", session.categories[i].id);
1796                if(resp.length) {
1797                    session.categories[i].valid = true;
1798                    // here resp.length is used to identify an object availability and (resp[0]['child'] != null) is used to check an object is not null.
1799                    if(resp[0]['child'] != null)
1800                        session.categories[i].noOfChildCategories = resp[0]['child'].length;
1801                    else
1802                        session.categories[i].noOfChildCategories = 0;
1803                    
1804                }
1805            }
1806            return true;
1807        } else
1808            return false;
1809    }
1810    
1811    /**
1812      @function
1813    
1814      @param  usecase This is usecase number in the AJAX call response
1815    */
1816    function getUseCaseName(usecase) {
1817        var strname = "";
1818        usecase = usecase.toString();
1819        switch(usecase) {
1820            case '202': strname = "Demand4Payment"; break;
1821            case '194': strname = "Request Money"; break;
1822            case '193': strname = "P2P"; break;
1823            case '191': strname = "Pay Bill"; break;
1824            case '174': strname = "Send Voucher"; break;
1825            case '173': strname = "Airtime Topup"; break;
1826            case '161': strname = "SVA Unload"; break;
1827            case '160': strname = "SVA Load"; break;
1828            case '500': strname = "NFC Transaction"; break;
1829            case '501': strname = "OfflineSVA Load"; break;
1830            case '502': strname = "OfflineSVA Unload"; break;
1831            case '503': strname = "P2P NFC Transaction"; break;
1832            case '504': strname = "NFC Transaction"; break;
1833        }
1834        return strname;
1835    }
1836    
1837    /**
1838      @function
1839    
1840      @param  r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
1841    */
1842    function getErrorMessage(r) {
1843        var errValue = r.Status.value;
1844        var errCode = r.Status.code.toString();
1845        if(errValue !== null) {
1846            if (errCode == '329' || errCode == '201')
1847                return "Check your username or password and try again!";
1848            else if (errCode == '302')
1849                return "Your account is blocked! Please contact service provider.";
1850            else if(errCode == '2517')
1851                return "Payer has no valid wallet for this transaction";
1852            else if(errCode == '2507')
1853                return "Payee has no valid wallet for this transaction";
1854            else
1855                return r.Status.value;
1856        } else {
1857            var msg = '';
1858            switch (errCode) {
1859            case '1002': msg = "INVALID MSISDN: Indicates that (one of) the specified MSISDN(s) is invalid. MSISDNs always have to specified as +countryCodenetCodenumber"; break;
1860            case '1003': msg = "UNKNOWN TRANSACTION: Indicates that the (or a) transaction specified in the request does not exist."; break;
1861            case '1004': msg = "INVALID TRANSACTION: Indicates that the (or a) transaction specified in the request cannot be used/considered in the requested context."; break;
1862            case '1005': msg = "INVALID TRANSACTION STATUS: Indicates that the (or a) transaction specified in the request cannot be used/considered due to its status."; break;
1863            case '1006': msg = "INACTIVE CUSTOMER: Indicates that the (or a) customer specified in the request cannot be used/considered because he is inactive"; break;
1864            case '1008': msg = "BLACKLISTED CUSTOMER"; break;
1865            case '1050': msg = "The transaction is locked by another process and cannot be handled right now"; break;
1866            case '1112': msg = "INACTIVE USER: Indicates that the customer's status is inactive - see database CUSTOMER_STATUS.BOL_IS_ACTIVE."; break;
1867            case '1114': msg = "CUSTOMER BLOCKED: Indicates that the customer is currently blocked due to the number of times wrong credentials have been specified."; break;
1868            case '1115': msg = "BLACKLISTED USER: Indicates that the customer is blacklisted - see database CUSTOMER.ID_BLACKLISTREASON."; break;
1869            case '1121': msg = "CREDENTIALS EXPIRED: Indicates that the specified credentials have expired"; break;
1870            case '1250': msg = "TRANSACTION_EXPIRED: The transaction was pending in initial state too long and invalidated automatically."; break;
1871            case '1301': msg = "SESSION ACTIVE WARN: Indicates that a login failed because the customer has still an active session - this prevents logging in multiple times with just one customer."; break;
1872            case '2001': msg = "CREDIT LIMIT EXCEEDED: Indicates that the credit limit has been exceeded."; break;
1873            case '2002': msg = "DEBIT LIMIT EXCEEDED: Indicates that the debit limit has been exceeded."; break;
1874            case '201': msg = "MINIMUM CREDENTIAL LENGTH: Indicates that the credential (to create or update, presumably) exceeds the minimum credential length."; break;
1875            case '2011': msg = "RESERVATION EXPIRED: Indicates that the SVA resveration (to capture/cancel/...) expired."; break;
1876            case '202': msg = "MAXIMUM CREDENTIAL LENGTH: Indicates that the credential (to create or update, presumably) exceeds the maximum credential length."; break;
1877            case '203': msg = "CREDENTIAL REPEAT: Indicates that the credential (to create or update, presumably) is the same as any of the n previously used credentials."; break;
1878            case '204': msg = "CREDENTIAL WEAK ASCENDING: Indicates that the credential (to create or update, presumably) contains a block of ascending characters."; break;
1879            case '205': msg = "CREDENTIAL WEAK EQUALITY: Indicates that the credential (to create or update, presumably) contains a block of equal characters."; break;
1880            case '206': msg = "CREDENTIAL WEAK DESCENDING: Indicates that the credential (to create or update, presumably) contains a block of descending characters."; break;
1881            case '207': msg = "CREDENTIAL EQUALS IDENTIFICATION: Indicates that the specified credential is the same as one of the customers identifications."; break;
1882            case '208': msg = "CREDENTIAL REGEX MATCH: Indicates that the credential does or does not match one of the security poilicies'' regular expressions and thus is invalid."; break;
1883            case '2201': msg = "UNKNOWN TARGET: Indicates that the target customer is unknown."; break;
1884            case '2202': msg = "INVALID TARGET: Indicates that the target customer is invalid, i.e. not allowed/able to participate in the operation."; break;
1885            case '2214': msg = "FLOATING AMOUNT MISSING"; break;
1886            case '2215': msg = "FLOATING AMOUNT FALLS BELOW MIN PRICE"; break;
1887            case '2216': msg = "FLOATING AMOUNT EXCEEDS MAX PRICE"; break;
1888            case '2222': msg = "IN BUSY: Indicates that the IN is currently busy and cannot handle more requests."; break;
1889            case '2231': msg = "AIRTIME LIMIT EXCEEDED"; break;
1890            case '2232': msg = "CO-USER LIMIT EXCEEDED"; break;
1891            case '2259': msg = "VOUCHER SALE HANDLER FAILURE"; break;
1892            case '2299': msg = "TRANSACTION FAILED PERMANENTLY"; break;
1893            case '2405': msg = "NO COMM WITH MSG-GW: Send error, indicates that the Notification Services are not going to send the specified message (for whatever reason)"; break;
1894            case '2507': msg = "PAYEE PI UNKNOWN"; break;
1895            case '2511': msg = "UNKNOWN PAYER"; break;
1896            case '2512': msg = "INVALID PAYER"; break;
1897            case '2517': msg = "PAYER PI UNKNOWN"; break;
1898            case '2519': msg = "AUTHORIZATION EXPIRED"; break;
1899            case '2521': msg = "AUTHENTICATION REQUIRED: Indicates that the participant authentication has been initialized, but the authentication is asychronous"; break;
1900            case '2522': msg = "AUTHENTIVATION WRONG: Indicates that the supplied authentication was wrong"; break;
1901            case '2525': msg = "MANUAL DECISION REQUIRED: Indicates that the transaction processing has been stopped and a manual decission is needed"; break;
1902            case '2535': msg = "ERROR_PAYEE_OPEN_TRANSACTION"; break;
1903            case '2536': msg = "ERROR_PAYER_OPEN_TRANSACTION"; break;
1904            case '2537': msg = "ERROR_NO_OPEN_TRANSACTION"; break;
1905            case '2541': msg = "PAYER DENIED TRANSACTION"; break;
1906            case '2542': msg = "PAYER NOT REACHABLE"; break;
1907            case '2561': msg = "PAYEE ABSOLUTE LIMIT EXCEEDED: Indicates that the payee's absolute credit limit has been exceeded."; break;
1908            case '2562': msg = "PAYER ABSOLUTE LIMIT EXCEEDED: Indicates that the payer's absolute debit limit has been exceeded."; break;
1909            case '2563': msg = "PAYEE MONTHLY LIMIT EXCEEDED: Indicates that the payee's monthly credit limit has been exceeded."; break;
1910            case '2564': msg = "PAYER MONTHLY LIMIT EXCEEDED: Indicates that the payer's monthly debit limit has been exceeded."; break;
1911            case '2565': msg = "PAYEE DAILY LIMIT EXCEEDED: Indicates that the payee's daily credit limit has been exceeded."; break;
1912            case '2566': msg = "PAYER DAILY LIMIT EXCEEDED: Indicates that the payer's daily debit limit has been exceeded."; break;
1913            case '2571': msg = "PAYEE WALLET ABSOLUTE LIMIT EXCEEDED: Indicates that the payee's wallet absolute credit limit has been exceeded."; break;
1914            case '2572': msg = "PAYER WALLET ABSOLUTE LIMIT EXCEEDED: Indicates that the payer's wallet absolute debit limit has been exceeded."; break;
1915            case '2573': msg = "PAYEE WALLET MONTHLY LIMIT EXCEEDED: Indicates that the payee's wallet monthly credit limit has been exceeded."; break;
1916            case '2574': msg = "PAYER WALLET MONTHLY LIMIT EXCEEDED: Indicates that the payer's wallet monthly debit limit has been exceeded."; break;
1917            case '2575': msg = "PAYEE WALLET DAILY LIMIT EXCEEDED: Indicates that the payee's wallet daily credit limit has been exceeded."; break;
1918            case '2576': msg = "PAYER WALLET DAILY LIMIT EXCEEDED: Indicates that the payer's wallet daily debit limit has been exceeded."; break;
1919            case '2581': msg = "RESTRICTION PAYEE TRANSACTION AMOUNT: Indicates that a transaction restriction restricts the payee to participate in this transaction because the transaction amount is higher than allowed"; break;
1920            case '2582': msg = "RESTRICTION PAYER TRANSACTION AMOUNT: Indicates that a transaction restriction restricts the payer to participate in this transaction because the transaction amount is higher than allowed"; break;
1921            case '2583': msg = "RESTRICTION PAYEE TRANSACTION COUNT: Indicates that a restriction restricts the payee to participate in this transaction because the restricted number of transaction per timeframe is exceeded"; break;
1922            case '2584': msg = "RESTRICTION PAYER TRANSACTION COUNT: Indicates that a restriction restricts the payer to participate in this transaction because the restricted number of transaction per timeframe is exceeded"; break;
1923            case '2585': msg = "RESTRICTION PAYEE TRANSACTION SUM: Indicates that an transaction restrictions restricts the payee to participate in this transaction because the restricted transaction sum per timeframe is exceeded"; break;
1924            case '2586': msg = "RESTRICTION PAYER TRANSACTION SUM: Indicates that an transaction restrictions restricts the payee to participate in this transaction because the restricted transaction sum per timeframe is exceeded"; break;
1925            case '2587': msg = "RESTRICTION PAYEE TRANSACTION SUM MIN"; break;
1926            case '2588': msg = "RESTRICTION PAYER TRANSACTION SUM MIN"; break;
1927            case '2589': msg = "RESTRICTION INDIVIDUAL"; break;
1928            case '2604': msg = "PAYER PI IN INVALID STATE"; break;
1929            case '2605': msg = "PAYER PI NOT ALLOWED"; break;
1930            case '2607': msg = "PAYER PI DAILY LIMIT EXCEEDED: Indicates that the payer's payment instrument daily debit limit has been exceeded."; break;
1931            case '2608': msg = "PAYER PI MONTHLY LIMIT EXCEEDED: Indicates that the payer's payment instrument monthly debit limit has been exceeded."; break;
1932            case '2611': msg = "Balance of Payer's account is not enough for this transaction amount!"; break;
1933            case '2622': msg = "PAYER PI CAPTURE CANCEL FULL AMOUNT: Indicates that the payers payment instrument only allows cancelling the complete capture amount."; break;
1934            case '2631': msg = "Payer's account is BLOCKED"; break;
1935            case '2650': msg = "PICKUP CODE NOT FOUND: Indicates that the transaction has no pickup code attached."; break;
1936            case '2651': msg = "PICKUP MAX TRIES EXCEEDED: Indicates that the maximum number of tries has been exceeded."; break;
1937            case '2652': msg = "PICKUP CODE INVALID: Indicates that the pickup code is invalid."; break;
1938            case '2653': msg = "PICKUP ATTRIBUTE NOT UNIQUE: Indicates that the pickup code attribute attached to the transaction is not unique."; break;
1939            case '2654': msg = "PICKUP INTERNAL VOUCHER NOT FOUND: Indicates that the internal voucher associated with the transaction could not be found."; break;
1940            case '2655': msg = "PICKUP INTERNAL VOUCHER TXN NOT FOUND: Indicates that the internal voucher transaction associated with the given transaction could not be found."; break;
1941            case '2661': msg = "WALLET ENTRY INVALID ALIAS: Indicates that a wallet entry exists for the same customer with a different payment instrument."; break;
1942            case '2662': msg = "WALLET ENTRY INVALID PRIORITY: Indicates that a wallet entry exists for the same customer having the same debit or credit priority"; break;
1943            case '2704': msg = "PAYEE PI IN INVALID STATE"; break;
1944            case '2705': msg = "PAYEE PI NOT ALLOWED"; break;
1945            case '2707': msg = "PAYEE PI DAILY LIMIT EXCEEDED: Indicates that the payee's payment instrument daily credit limit has been exceeded."; break;
1946            case '2708': msg = "PAYEE PI MONTHLY LIMIT EXCEEDED: Indicates that the payee's payment instrument monthly credit limit has been exceeded."; break;
1947            case '2709': msg = "PAYEE PI ABSOLUTE LIMIT EXCEEDED: Indicates that the payee's payment instrument absolute credit limit has been exceeded."; break;
1948            case '2711': msg = "PAYEE PI LIMIT HIT"; break;
1949            case '2731': msg = "PAYEE PI BLOCKED"; break;
1950            case '2811': msg = "DISCONNECTED BY CUSTOMER"; break;
1951            case '2907': msg = "CUSTOMER MOBILE BUSY"; break;
1952            case '2908': msg = "NO ANSWER FROM CUSTOMER MOBILE"; break;
1953            case '2916': msg = "COULD NOT REACH CUSTOMERS MOBILE"; break;
1954            case '2920': msg = "3 TIMES WRONG PIN"; break;
1955            case '2921': msg = "3 TIMES NO RESPONSE"; break;
1956            case '2943': msg = "WRONG OR INVALID PIN"; break;
1957            case '2945': msg = "AUTHENTICATION DECLINED"; break;
1958            default: msg = "Unknown Error!"; break;
1959            }
1960            return msg;
1961        }
1962    }
1963    
1964    function epoch2UTC(epoch) {
1965        var utcDate = new Date(epoch);
1966        return utcDate.getFullYear()+'-'+pad2(utcDate.getMonth()+1)+'-'+pad2(utcDate.getDate())+
1967            'T'+pad2(utcDate.getHours())+':'+pad2(utcDate.getMinutes())+':'+pad2(utcDate.getSeconds());
1968    }
1969    
1970    /**
1971     *@description callback handler for receiving existing alerts
1972     */
1973    var getExistingAlertsBack = function(r) {
1974        hideProgress();
1975    
1976        var rCode = getStatusCode(r);
1977        if (rCode == '0') {
1978            //Parse
1979            session.transit_value = parseExistingAlerts(r);
1980            //Subsequent Server Calls
1981            fetchActiveAlertNotificationMessage();
1982        } else {
1983            _alertBox(Str_alert_failgetexistingalerts + getErrorMessage(r));
1984        }
1985        appstate = trans.TRAN_IDLE;
1986    };
1987    
1988    /**
1989     * @description Parsing the Alerts for Alert List
1990     */
1991    function parseExistingAlerts(r){
1992        var customerAlerts = new Array();
1993        if(r.customerAlert != null) {
1994            for(var i = 0;i < r.customerAlert.length;i++) {
1995                var ca = new CustomerAlert();
1996                ca.id = r.customerAlert[i].id;
1997                ca.customerId = r.customerAlert[i].customerId;
1998                ca.alertTypeId = r.customerAlert[i].alertTypeId;
1999                ca.active = r.customerAlert[i].active;
2000                ca.created = r.customerAlert[i].created;
2001                ca.alertDataList = [];
2002                if(r.customerAlert[i].alertDataList != null
2003                        && r.customerAlert[i].alertDataList != 'undefined'
2004                            && r.customerAlert[i].alertDataList.alertData != null
2005                            && r.customerAlert[i].alertDataList.alertData != 'undefined') {
2006                    for(var j = 0;j < r.customerAlert[i].alertDataList.alertData.length;j++) {
2007                        var ad = new AlertData();
2008                        ad.id = r.customerAlert[i].alertDataList.alertData[j].id;
2009                        ad.customerAlertId = r.customerAlert[i].alertDataList.alertData[j].customerAlertId;
2010                        ad.key = r.customerAlert[i].alertDataList.alertData[j].key;
2011                        ad.value = r.customerAlert[i].alertDataList.alertData[j].value;
2012                        ca.alertDataList.push(ad);
2013                    }
2014                }
2015    
2016                ca.contactPointList = [];
2017    
2018                if(r.customerAlert[i].contactPointList != null && r.customerAlert[i].contactPointList != 'undefined'
2019                    && r.customerAlert[i].contactPointList.contactPoint != null
2020                    && r.customerAlert[i].contactPointList.contactPoint != 'undefined') {
2021                    for(var k = 0;k < r.customerAlert[i].contactPointList.contactPoint.length;k++) {
2022                        if(r.customerAlert[i].contactPointList.contactPoint[k].otherIdentification) {
2023                            var oi = new OtherIdentification();
2024                            oi.id = r.customerAlert[i].contactPointList.contactPoint[k].otherIdentification.id;
2025                            oi.customerId = r.customerAlert[i].contactPointList.contactPoint[k].otherIdentification.customerId;
2026                            oi.type = r.customerAlert[i].contactPointList.contactPoint[k].otherIdentification.type;
2027                            oi.identification = r.customerAlert[i].contactPointList.contactPoint[k].otherIdentification.identification;
2028                            oi.nickname = r.customerAlert[i].contactPointList.contactPoint[k].otherIdentification.nickname;
2029                            oi.provider = r.customerAlert[i].contactPointList.contactPoint[k].otherIdentification.provider;
2030                            oi.status = r.customerAlert[i].contactPointList.contactPoint[k].otherIdentification.status;
2031                            oi.active = r.customerAlert[i].contactPointList.contactPoint[k].otherIdentification.active;
2032                            ca.contactPointList.push(oi);
2033                        } else if (r.customerAlert[i].contactPointList.contactPoint[k].identification) {
2034                            var iden = new Identification();
2035                            iden.id = r.customerAlert[i].contactPointList.contactPoint[k].identification.id;
2036                            iden.customerId = r.customerAlert[i].contactPointList.contactPoint[k].identification.customerId;
2037                            iden.type = r.customerAlert[i].contactPointList.contactPoint[k].identification.type;
2038                            iden.identification = r.customerAlert[i].contactPointList.contactPoint[k].identification.identification;
2039                            ca.contactPointList.push(iden);
2040                        }
2041                    }
2042                }
2043                customerAlerts.push(ca);
2044            }
2045        }
2046        //return customerAlerts.sortBy('created');
2047        return customerAlerts.sort(dynamicSort('created'));
2048    }
2049    
2050    /**
2051     * @description Call back handler for Deleting customer alert
2052     */
2053    var deleteCustomerAlertBack = function(r) {
2054        hideProgress();
2055    
2056        var rCode = getStatusCode(r);
2057        if (rCode == '0') {
2058            _alertBox(Str_msg_deletealert);
2059            $('#managealert').trigger('pageshow');
2060        } else {
2061            _alertBox(Str_msg_faildeletealert + getErrorMessage(r));
2062        }
2063        appstate = trans.TRAN_IDLE;
2064    };
2065    
2066    /**
2067     * @description This function layout the UI for other identifications
2068     */
2069    function listOtherIdentifications(oIdentifications, container) {
2070        $(container).empty();
2071        var identification = session.identification;
2072        var checked = checkOtherIdentificationInSelectedAlert(identification.id);
2073        $(container).append("<input type=\"checkbox\" name=\"aa_devices_"+identification.id+"\" id=\"aa_devices_"+identification.id+"\" class=\"custom check_add_alert\"" +
2074                    " value=\""+identification.id+"\" "+(checked?"checked":"")+" data-theme=\"g\" data-identification='true'>" +
2075                    "<label for=\"aa_devices_"+identification.id+"\">"+identification.identification+"</label>");
2076    
2077        if(oIdentifications) { //Check null or undefined
2078            for(i = 0;i < oIdentifications.length;i++){
2079                var oi = oIdentifications[i];
2080                checked = checkOtherIdentificationInSelectedAlert(oi.id);
2081                //console.log('Checked: ' + checked);
2082                $(container).append("<input type=\"checkbox\" name=\"aa_devices_"+oi.id+"\" id=\"aa_devices_"+oi.id+"\" class=\"custom check_add_alert\"" +
2083                        " value=\""+oi.id+"\" "+(checked?"checked":"")+" data-theme=\"g\">" +
2084                        "<label for=\"aa_devices_"+oi.id+"\">"+oi.nickname+": "+oi.identification+"</label>");
2085            }
2086        }
2087        $('#aad_otheridentifications_wrap').trigger('create');
2088        $(container).trigger('create');
2089        $(container + ' input:checkbox').checkboxradio('refresh');
2090    }
2091    
2092    /**
2093     * @description finds out if this OI is there in the alert
2094     * @return boolean depicting true if exists else false
2095     * @param oIId for an contact point
2096     */
2097    function checkOtherIdentificationInSelectedAlert(oIId) {
2098        var isExists = false;
2099        if(session.customerAlert != null) {
2100            if(session.customerAlert.contactPointList != null && session.customerAlert.contactPointList.length > 0) {
2101                for(var i = 0;i < session.customerAlert.contactPointList.length;i++) {
2102                    if(session.customerAlert.contactPointList[i].otherIdentification && session.customerAlert.contactPointList[i].otherIdentification.id == oIId) {
2103                        isExists = true;
2104                        break;
2105                    } else if (session.customerAlert.contactPointList[i].identification && session.customerAlert.contactPointList[i].identification.id == oIId) {
2106                        isExists = true;
2107                        break;
2108                    }
2109                }
2110            }
2111        }
2112        return isExists;
2113    }
2114    
2115    /**
2116     * @description Callback handler for Adding Alert
2117     */
2118    function createNewAlertBack(r) {
2119        hideProgress();
2120    
2121        var rCode = getStatusCode(r);
2122        if (rCode == '0') {
2123            $('#aas_title').html(Str_txt_addalert);
2124            //Get the newly created alertId
2125            session.transit_value = r.customerAlertId;
2126            $.mobile.changePage("addAlertSuccess.html", page_opt);
2127        } else {
2128            _alertBox(Str_msg_failcreatealert + getErrorMessage(r));
2129        }
2130        appstate = trans.TRAN_IDLE;
2131    }
2132    
2133    /**
2134     * @description Callback handler for Get Alert Detail service
2135     * @param r response data
2136     */
2137    function getAlertDetailsForEditBack(r) {
2138        hideProgress();
2139    
2140        var rCode = getStatusCode(r);
2141        if(rCode == '0') {
2142            //Parse customer alert
2143            var ca = parseCustomerAlert(r);
2144    
2145            session.customerAlert = ca;
2146            $('#addAlertDetails').attr("action", "edit");
2147            $('#txt_addalertdetail').text(Str_editalert);
2148    
2149            var alertTypeId = ca.alertTypeId;
2150    
2151            if(alertTypeId != null || alertTypeId != undefined) {
2152                $("#btn_ma_addnewcontinue").attr("alertTypeId", alertTypeId);
2153    
2154                var fieldArr = alerttypefieldsmapping[alertTypeId];
2155                $('#alertcontent').empty();
2156                var alertDataList = ca.alertDataList;
2157                for (i = 0; i < fieldArr.length; i++) {
2158                    var field = fieldArr[i];
2159                    var ad = findAlertDataInDataList(alertDataList, field);
2160                    var val = '';
2161                    if(ad != null) {
2162                        val = ad.value;
2163                    } else if (field == "frequency") {
2164                        var cnt = ca.notifMaxCnt;
2165                        var rec = ca.notifMaxRecur;
2166                        if(cnt > 0) {
2167                            val = rec + "_" + cnt;
2168                        } else {
2169                            val = cnt;
2170                        }
2171                    } else if (field == "msgtype") {
2172                        val = getNotificationTypeIdForAlertNotificationMessageId(ca.alertNotificationMsgId);
2173                    }
2174                    //console.log("Value of field: " + field + " is " + val);
2175                    var contentlist = getFieldLiContent(field, val);
2176                    $('#alertcontent').append(contentlist);
2177                }
2178            }
2179            $('#addalerttitle').html(Str_edit + " " +
2180                getAlertPageTitle(alertTypeId) + " " + Str_alert);
2181            $('#addAlertDetails .ui-droplist').trigger('create');
2182    
2183            $('#aa_msgtype_fs_wrap').trigger('create');
2184            $('#aa_msgtype_fs').trigger('create');
2185            $('#aa_msgtype_fs' + ' input:checkbox').checkboxradio('refresh');
2186    
2187            $('#addAlertDetails .aa_frequency_field').collapsible();
2188            $('#aa_frequency_num').textinput();
2189    
2190            $.mobile.changePage("addAlertDetails.html", page_opt);
2191        } else {
2192            _alertBox(Str_msg_failgetalertdetail + getErrorMessage(r));
2193        }
2194        appstate = trans.TRAN_IDLE;
2195    }
2196    
2197    /**
2198     * @description Iterate and find the key in the list and returns the object.
2199     * @param alertDataList list of alert data objects
2200     * @param field fieldName to be searched
2201     * @return AlertData or null
2202     */
2203    function findAlertDataInDataList(alertDataList, field) {
2204        var ad = null;
2205        if(alertDataList != null && alertDataList.length > 0) {
2206            for(var i = 0;i < alertDataList.length;i++) {
2207                //console.log(alertDataList[i].key + " == " + field);
2208                if(alertDataList[i].key == field) {
2209                    ad = alertDataList[i];
2210                    //console.log('AD Found ' + smartphoneService.toJSON(ad));
2211                    break;
2212                }
2213            }
2214        }
2215        return ad;
2216    }
2217    
2218    /**
2219     * @description parse customer alert data from the response
2220     * @param r
2221     * @returns CustomerAlert object
2222     */
2223    function parseCustomerAlert(r) {
2224        var ca = new CustomerAlert();
2225        ca.id = r.customerAlert.id;
2226        ca.customerId = r.customerAlert.customerId;
2227        ca.alertTypeId = r.customerAlert.alertTypeId;
2228        ca.active = r.customerAlert.active;
2229        ca.alertNotificationMsgId = r.customerAlert.alertNotificationMsgId;
2230        ca.notifMaxCnt = r.customerAlert.notifMaxCnt;
2231        ca.notifMaxRecur = r.customerAlert.notifMaxRecur;
2232        ca.created = r.customerAlert.created;
2233    
2234        if(r.customerAlert.alertDataList != null && r.customerAlert.alertDataList.alertData != null
2235                    && r.customerAlert.alertDataList.alertData.length > 0) { //Check for null values
2236            for(var i = 0;i < r.customerAlert.alertDataList.alertData.length;i++) {
2237                var tmpAd = r.customerAlert.alertDataList.alertData[i];
2238                var ad = new AlertData();
2239                ad.id = tmpAd.id;
2240                ad.customerAlertId = tmpAd.customerAlertId;
2241                ad.key = tmpAd.key;
2242                ad.value = tmpAd.value;
2243                ca.alertDataList.push(ad);
2244            }
2245        }
2246    
2247        var contactPointList = r.customerAlert.contactPointList;
2248        if(r.customerAlert.contactPointList != null && r.customerAlert.contactPointList.contactPoint != null
2249                    && r.customerAlert.contactPointList.contactPoint.length > 0) {
2250            for(var i = 0;i < r.customerAlert.contactPointList.contactPoint.length;i++) {
2251                var cp = new ContactPoint();
2252                cp.id = r.customerAlert.contactPointList.contactPoint[i].id;
2253                cp.customerAlertId = r.customerAlert.contactPointList.contactPoint[i].customerAlertId;
2254    
2255                if(r.customerAlert.contactPointList.contactPoint[i].otherIdentification) {
2256                    var otherIdentification = r.customerAlert.contactPointList.contactPoint[i].otherIdentification;
2257                    var oi = new OtherIdentification();
2258                    oi.id = otherIdentification.id;
2259                    oi.customerId = otherIdentification.customerId;
2260                    oi.type = otherIdentification.type;
2261                    oi.identification = otherIdentification.identification;
2262                    oi.nickname = otherIdentification.nickname;
2263    
2264                    cp.otherIdentification = oi;
2265                    delete cp.identification;
2266                } else {
2267                    var identification = r.customerAlert.contactPointList.contactPoint[i].identification;
2268                    var oi = new Identification();
2269                    oi.id = identification.id;
2270                    oi.customerId = identification.customerId;
2271                    oi.type = identification.type;
2272                    oi.identification = identification.identification;
2273    
2274                    cp.identification = oi;
2275                    delete cp.otherIdentification;
2276                }
2277    
2278                ca.contactPointList.push(cp);
2279            }
2280        }
2281    
2282        //Parsing Blackout should I?
2283        ca.blackoutList = r.customerAlert.blackoutList;
2284        return ca;
2285    }
2286    
2287    /**
2288     * @description Callback handler for Updating Alert
2289     */
2290    function updateExistingAlertBack(r) {
2291        hideProgress();
2292    
2293        var rCode = getStatusCode(r);
2294        if (rCode == '0') {
2295            $('#aas_title').html(Str_txt_editalert);
2296            $.mobile.changePage("addAlertSuccess.html", page_opt);
2297            $('#alertcontentSuccess').html(Str_txt_editalert);
2298            session.customerAlert = null; //Clear the alert data from the session to avoid misuse.
2299        } else {
2300            _alertBox(Str_msg_failupdatealert + getErrorMessage(r));
2301            $('#aas_title').html(Str_txt_titleeditalertfail);
2302        }
2303        appstate = trans.TRAN_IDLE;
2304    }
2305    
2306    /**
2307     * @description callback handler of getting the alert notification message id back from server
2308     * @param r
2309     */
2310    function getAlertNotificationMsgIdBack(r) {
2311        hideProgress();
2312    
2313        var rCode = getStatusCode(r);
2314        if (rCode == '0') {
2315            var alertNotificationMsgTypeId = parseAlertNotificationMessageTypeId(r);
2316            //console.log("Got AlertNotificationMessageId from server. it is " + alertNotificationMsgTypeId);
2317    
2318            var alertTypeId = $("#btn_ma_addnewcontinue").attr('alertTypeId');
2319            var existingAlertId = $("#btn_ma_addnewcontinue").attr('alertId');
2320    
2321            //Check whether we need to add a new alert or we need to update an existing one.
2322            if($('#addAlertDetails').attr("action") != "edit") {
2323                submitNewAddAlert(alertTypeId, alertNotificationMsgTypeId);
2324            } else {
2325                updateExistingAlert(alertTypeId, alertNotificationMsgTypeId, existingAlertId);
2326            }
2327        } else {
2328            _alertBox(Str_msg_failgetchequestatus + getErrorMessage(r));
2329        }
2330        appstate = trans.TRAN_IDLE;
2331    }
2332    
2333    /**
2334     * @description parsing logic for alertNotificationMessageTyepId
2335     * @param r response data to be parsed.
2336     * @returns parsed alert notification message type id
2337     */
2338    function parseAlertNotificationMessageTypeId(r) {
2339        var alertNotificationMessageId;
2340        if(r.alertNotificationMessage && r.alertNotificationMessage.length > 0)
2341                alertNotificationMessageId = r.alertNotificationMessage[0].id;
2342        return alertNotificationMessageId;
2343    }
2344    
2345    /**
2346     * @description callback handler for the active alert notification message mapping
2347     * web service call
2348     * @param r response data
2349     */
2350    function getActiveAlertNotificationMessagesBack(r) {
2351        hideProgress();
2352    
2353        var rCode = getStatusCode(r);
2354        if (rCode == '0') {
2355            var alertNotificationMessages = parseAlertNotificationMessages(r);
2356    //        if(alertNotificationMessages && alertNotificationMessages.length)
2357    //            console.log(alertNotificationMessages.length + " Alert notifications found.")
2358            
2359            $.mobile.changePage("managealert.html", page_opt);
2360        } else {
2361            _alertBox(Str_msg_failgetalertnoti + getErrorMessage(r));
2362            //TODO: Shall we push user back??
2363        }
2364        appstate = trans.TRAN_IDLE;
2365    }
2366    
2367    /**
2368     * @description Parser for alert notification messages response
2369     * @return the array of AlertNotificationMessage objects
2370     */
2371    function parseAlertNotificationMessages(r) {
2372        session.alertNotificationMessages = [];    //Remove old entries from the array.
2373        if(r.alertNotificationMessage != null) {
2374            for(var i = 0;i < r.alertNotificationMessage.length;i++) {
2375                var anm = new AlertNotificationMessage();
2376                //Parsing logic goes here
2377                anm.id = r.alertNotificationMessage[i].id;
2378                anm.alertTypeId = r.alertNotificationMessage[i].alertTypeId;
2379                anm.notificationMsgTypeId = r.alertNotificationMessage[i].notificationMsgTypeId;
2380                session.alertNotificationMessages.push(anm);
2381            }
2382        }
2383        return session.alertNotificationMessages;
2384    }
2385    
2386    var transactiontypefilter = {"Peer 2 Peer":"Send Money", "Standard C2C pull": "Request Money", "Standard Cash-In":"Cash In"
2387        ,"Standard Cash-Out": "Cash Out","Standard Credit Self":"Add Funds to SVA","Standard Debit Self":"Withdraw Funds from SVA"
2388        ,"Standard load internal voucher":"Load Internal Voucher","Send voucher to unknown":"Send Voucher",
2389        "CommissionSettlement":"Commission Settlement","Transfer Money":"Merchant to Merchant", "chequeBook":"Request Cheque Book"
2390        , "AccountInfo":"Account Info", "chequeStatus":"Cheque Status","chequeStop":"Stop Cheque Payment"};
2391    
2392    /**
2393     * @description Callback handler for getting the transaction types back
2394     * @param r
2395     */
2396    function getTransactionTypesBack(r) {
2397        hideProgress();
2398    
2399        var rCode = getStatusCode(r);
2400        if (rCode == '0') {
2401            transactiontypes = parseLookupEntities(r,transactiontypefilter);
2402            //console.log("Number of transactions found are " + transactiontypes.length);
2403            if(transactiontypes && transactiontypes.length > 0) {
2404                loadTransactions(transactiontypes.sort(dynamicSort('name')));
2405            } else {
2406                _alertBox(Str_msg_failnotrantype);
2407                goBack();
2408            }
2409        } else {
2410            _alertBox(Str_msg_failgettrantype + getErrorMessage(r));
2411            goBack();
2412        }
2413        appstate = trans.TRAN_IDLE;
2414    }
2415    
2416    /**
2417     * @description parser for currencies response
2418     * @param r response data
2419     * @param filter an optional array which maps a new string for name
2420     * @returns {Array} of parsed currecy objects with id and name properties
2421     */
2422    function parseLookupEntities(r, filter) {
2423        var entities = [];
2424        if(r.lookupEntities != null) {
2425            for(var i = 0;i < r.lookupEntities.length;i++) {
2426                var entity = {};
2427                entity.id = r.lookupEntities[i].id;
2428                //Check if filter is provided
2429                if(filter) {
2430                    //Check if filter contains the key
2431                    entity.name = filter[r.lookupEntities[i].name]?filter[r.lookupEntities[i].name]:r.lookupEntities[i].name;
2432                } else {
2433                    //No filter store the name as it is returned by service
2434                    entity.name = r.lookupEntities[i].name;
2435                }
2436                entities.push(entity);
2437            }
2438        }
2439        return entities;
2440    }
2441    
2442    /*
2443     * @description Call back handler for receiving other identification
2444     */
2445    function getOtherIdentificationsBack(r) {
2446        hideProgress();
2447    
2448        var rCode = getStatusCode(r);
2449        if (rCode == '0') {
2450            var oIdentifications = parseOtherIdentifications(r);
2451            listOtherIdentifications(oIdentifications, '#aad_otheridentifications');
2452            //If this is a transaction types alert than we need one more call to load type of transactions
2453            var alertTypeId = $('#btn_ma_addnewcontinue').attr("alertTypeId");
2454            if(alertTypeId == "9" && CACHE_TRANSACTIONS && transactiontypes.length > 0) {
2455                loadTransactions(transactiontypes.sort(dynamicSort('name')));
2456            } else {
2457                mc.getLookups(getTransactionTypesBack, "usecase");
2458                appstate = trans.TRAN_TRANSACTIONTYPES;
2459                showProgress();
2460            }
2461        } else {
2462            _alertBox(Str_msg_failgetotheridentmb + getErrorMessage(r));
2463        }
2464        appstate = trans.TRAN_IDLE;
2465    }
2466    
2467    /**
2468     * @description Parser for other identification web service
2469     */
2470    function parseOtherIdentifications(r) {
2471        session.otherIdentifications = [];    //Remove old entries from the array.
2472        if(r.otherIdentification != null) {
2473            for(var i = 0;i < r.otherIdentification.length;i++) {
2474                var type = r.otherIdentification[i].type;
2475                //console.log("Type found: " + type + " checking in Array " + ALLOWED_DEVICE_TYPES);
2476                if($.inArray(type, ALLOWED_DEVICE_TYPES) > -1) { //Collect only Email and Mobile
2477                    var oi = new OtherIdentification();
2478                    //Parsing logic goes here
2479                    oi.id = r.otherIdentification[i].id;
2480                    oi.nickname = r.otherIdentification[i].nickname;
2481                    oi.identification = r.otherIdentification[i].identification;
2482                    oi.type = r.otherIdentification[i].type;
2483                    oi.customerId = r.otherIdentification[i].customerId;
2484                    session.otherIdentifications.push(oi);
2485                } else {
2486                        //console.log("Ignoring CP due to unmatched types ");
2487                }
2488            }
2489        }
2490        return session.otherIdentifications;
2491    }