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_OB_Transactions.js
9 * @author SAP AG
10 * @version 1.0
11 *
12 */
13
14 /**
15 * @description Callback handler for Bank Details list service call
16 * @param r responseJSON
17 */
18 var getBankDetailsListBack = function(r) {
19 hideProgress();
20 var rCode = getStatusCode(r);
21 if (rCode == '0') {
22 orgunits = parseBankDetails(r);
23 updateOrgUnitList('#bankdroplist', orgunits);
24 } else {
25 _alertBox('Failed to get orgunits. ' + getErrorMessage(r));
26 }
27 appstate = trans.TRAN_IDLE;
28 };
29
30 /**
31 * @description Parser for results of getBankDetailsList
32 * @param r response data
33 * @returns array of orgunits
34 */
35 function parseBankDetails(r) {
36 orgunits = []; //Remove old entries from the array.
37 if(r.bankDetails != null) {
38 for(var i = 0;i < r.bankDetails.length;i++) {
39 var ou = new OrgUnit();
40 //Parsing logic goes here
41 ou.id = r.bankDetails[i].bankId;
42 ou.name = r.bankDetails[i].bankName;
43 ou.currency = r.bankDetails[i].currencyDisplaySymbol;
44 orgunits.push(ou);
45 }
46 }
47 return orgunits;
48 }
49
50 /**
51 @function
52
53 @param r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
54 */
55 var obLoginBack = function(r) {
56 var rCode = getStatusCode(r);
57 if (appstate == trans.TRAN_LOGIN) {
58 if(rCode == '0') {
59 loginParseXML(r);
60 session.userMsisdn = $('#username').val();
61 pl.userMsisdn = $('#username').val();
62 loginUpdateUI();
63
64 appstate = trans.TRAN_ACCOUNTLIST;
65 mc.getAccountList(getAccountListBack, "SA");
66 } else {
67 hideProgress();
68 appstate = trans.TRAN_IDLE;
69 _alertBox("Login failed! " + getErrorMessage(r));
70 }
71 $('#username').val('');
72 $('#password').val('');
73 }
74 };
75
76 /**
77 * @description callback handler for getAccountList openbank api call
78 * @param r responseXML
79 */
80 function getAccountListBack(r) {
81 hideProgress();
82 var rCode = getStatusCode(r);
83 if (rCode == '0') {
84 if(appstate == trans.TRAN_ACCOUNTLIST) {
85 session.accountList = parseAccountList(r);
86 if(session.accountList.length < 1) {
87 _alertBox("Failed to fetch any relevant account from the Bank, cheque management cannot be used.");
88 }
89 } else if (appstate == trans.TRAN_ACCOUNTLISTBYTYPE) {
90 var accountList = parseAccountList(r);
91 if(accountList.length < 1) {
92 _alertBox("Failed to fetch any relevant account from the Bank, cheque management cannot be used.");
93 } else {
94 listExistingAccounts(accountList);
95 $.mobile.changePage("accountlist.html", page_opt);
96 }
97 }
98 } else {
99 _alertBox('Failed to get account list for customer. ' + getErrorMessage(r));
100 }
101 appstate = trans.TRAN_IDLE;
102 }
103
104 /**
105 * @description callback handler for getTransactionList openbank api call
106 * @param r responseXML
107 */
108 function getAccountInfoBack(r) {
109 hideProgress();
110 var rCode = getStatusCode(r);
111 if (rCode == '0') {
112 //Todo parse and display transactions
113 var account = parseAccountInfo(r);
114 listBankAccount(account);
115 } else {
116 _alertBox('Failed to get account list for customer. ' + getErrorMessage(r));
117 }
118 appstate = trans.TRAN_IDLE;
119 }
120
121 /**
122 * @description callback handler for transferFund openbank api call
123 * @param r responseXML
124 */
125 function fundTransferBack(r) {
126 hideProgress();
127 var rCode = getStatusCode(r);
128 if (rCode == '0') {
129 updateTransactionDoneUI(r.fromAccountBalance, r.toAccountBalance, r.transactionId);
130 $.mobile.changePage("transferdone.html", page_opt);
131 } else {
132 _alertBox('Failed to complete the transaction. ' + getErrorMessage(r));
133 }
134 appstate = trans.TRAN_IDLE;
135 }
136
137 /**
138 * @description callback handler for getTransactionList openbank api call
139 * @param r responseXML
140 */
141 function getTransactionListBack(r) {
142 hideProgress();
143 var rCode = getStatusCode(r);
144 if (rCode == '0') {
145 session.txns = parseTransactionList(r);
146 txnsUpdateUI(session.txns);
147 } else {
148 _alertBox('Failed to get account list for customer. ' + getErrorMessage(r));
149 }
150 appstate = trans.TRAN_IDLE;
151 }
152
153 /**
154 * @description ResponseHandler for getCurrencies web service call
155 * @param r
156 */
157 function getCurrenciesBack(r) {
158 hideProgress();
159 var rCode = getStatusCode(r);
160 if (rCode == '0') {
161 currencies = parseCurrencies(r);
162 if(currencies && currencies.length > 0) {
163 listCurrencies('#fx_fromcurrency', currencies);
164 listCurrencies('#fx_tocurrency', currencies);
165 } else {
166 //TODO Show error message and go back??
167 }
168 } else {
169 _alertBox('Failed to get Currencies.\n' + getErrorMessage(r));
170 //TODO: Shall we push user back??
171 }
172 appstate = trans.TRAN_IDLE;
173 }
174
175
176 /**
177 * @description callback handler for getting the exchange rate back
178 * @param r response data
179 */
180 function getExchangeRateBack(r) {
181 hideProgress();
182 var rCode = getStatusCode(r);
183 if (rCode == '0') {
184 var exchangeRate = parseExchangeRate(r);
185 updateExchangeRateUI(exchangeRate);
186 $.mobile.changePage("fxresult.html", page_opt);
187 } else {
188 _alertBox('Failed to get Exchange rate.\n' + getErrorMessage(r));
189 //TODO: Shall we push user back??
190 }
191 appstate = trans.TRAN_IDLE;
192 }
193
194 /**
195 * @description callback handler for favouriteList openbank api call
196 * @param r responseXML
197 */
198 function favouriteListBack(r) {
199 hideProgress();
200 var rCode = getStatusCode(r);
201 if (rCode == '0') {
202 //code to be done
203 session.favourites = parseFavouriteList(r);
204 if(session.favourites.length < 1) {
205 _alertBox("No favourite list fetched for this user");
206 } else {
207 updateFavouiteList(session.favourites);
208 $.mobile.changePage("favouritelist.html", page_opt);
209 }
210 } else {
211 _alertBox('Failed to fetch favourite list for customer. ' + getErrorMessage(r));
212 }
213 appstate = trans.TRAN_FAVOURITELIST;
214 }
215 /**
216 * @description callback handler for favouriteInfo openbank api call
217 * @param r responseXML
218 */
219
220 function favouriteInfoBack(r) {
221 hideProgress();
222 var rCode = getStatusCode(r);
223 if (rCode == '0') {
224 $("#fav_type").text(r.favourite.favouriteType);
225 $("#fav_alias").text(r.favourite.alias);
226 if (r.favourite.details.toAccount) {
227 $("#fav_accnt_holder").text(r.favourite.details.accountHolder);
228 $("#fav_accnt_id").text(r.favourite.details.toAccount.accountIdentification);
229 $(".biller_details").hide();
230 } else if (r.favourite.details.billerInfo) {
231 $("#fav_biller_name").text(r.favourite.details.billerInfo.billerName);
232 $("#fav_biller_code").text(r.favourite.details.billerInfo.billerCode);
233 $(".account_details").hide();
234 }
235 $("#btn_fav_tranfer_money").unbind('click');
236 $("#btn_fav_tranfer_money").bind('click',function() {
237 //need to change
238 var obj= new Object();
239 obj.alias=r.favourite.alias;
240 obj.favId = r.favourite.favouriteIdentification;
241 obj.paymentType = r.favourite.details.paymentType;
242 if(r.favourite.details.toAccount){
243 obj.accountIdentification = r.favourite.details.toAccount.accountIdentification;
244 obj.paymentInstrumentId = r.favourite.details.toAccount.paymentInstrumentId;
245 obj.to_account_type = r.favourite.details.toAccount.type;
246 } else if (r.favourite.details.billerInfo) {
247 obj.billerName = r.favourite.details.billerInfo.billerName;
248 obj.paymentInstrumentId = r.favourite.details.billerInfo.billerPaymentInstrumentId;
249 obj.billerCode = r.favourite.details.billerInfo.billerCode;
250 }
251 favStartTransferMoney(obj,"false");
252 });
253 $.mobile.changePage("favouriteinfo.html", page_opt);
254 } else {
255 _alertBox('Failed to fetch favourite Information. ' + getErrorMessage(r));
256 }
257 appstate = trans.TRAN_FAVOURITEINFO;
258 }
259 /**
260 * @description callback handler for favouriteTransfer openbank api call
261 * @param r responseXML
262 */
263
264 function favouriteTransferBack(r) {
265 hideProgress();
266 var rCode = getStatusCode(r);
267 if (rCode == '0') {
268 $.mobile.changePage("favouritetransferdone.html", page_opt);
269 } else {
270 _alertBox('Error:\n' + getErrorMessage(r));
271 }
272 appstate = trans.TRAN_FAVOURITETRANSFER;
273
274 }
275
276 /**
277 * @description Parser for Bank Account List
278 * @param r responseJSON from the service
279 * @returns {Array} of Account objects
280 */
281 function parseAccountList(r) {
282 var al = [];
283 if(r.accounts) {
284 for(var i = 0;i < r.accounts.length;i++) {
285 var account = new Account();
286 account.accountIdentification = r.accounts[i].accountIdentification;
287 account.institutionCode = r.accounts[i].institutionCode;
288 account.type = r.accounts[i].type;
289 account.accountStatus = r.accounts[i].accountStatus;
290 if(r.accounts[i].linkedAccount)
291 account.linkedAccount = r.accounts[i].linkedAccount;
292 account.paymentInstrumentId = r.accounts[i].paymentInstrumentId;
293 if(r.accounts[i].branchCode)
294 account.branchCode = r.accounts[i].branchCode;
295 if(r.accounts[i].countryCode)
296 account.countryCode = r.accounts[i].countryCode;
297 account.currencyCode = r.accounts[i].currencyCode;
298 account.accountHolder = r.accounts[i].accountHolder;
299 if(r.accounts[i].alias)
300 account.alias = r.accounts[i].alias;
301 if(r.accounts[i].balance)
302 account.balance = r.accounts[i].balance;
303 if(r.accounts[i].availableFunds)
304 account.availableFunds = r.accounts[i].availableFunds;
305 if(r.accounts[i].outstandingAmount)
306 account.outstandingAmount = r.accounts[i].outstandingAmount;
307 if(r.accounts[i].minimumAmount)
308 account.minimumAmount = r.accounts[i].minimumAmount;
309 if(r.accounts[i].statementAmount)
310 account.statementAmount = r.accounts[i].statementAmount;
311 al.push(account);
312 }
313 }
314 return al;
315 }
316 /**
317 * @description Parser for Favourite List
318 * @param r responseJSON from the service
319 * @returns {Array} of Favourites objects
320 */
321
322 function parseAccountInfo(r) {
323 var account = new Account();
324 if(r.accountHolder)
325 account.accountHolder = r.accountHolder;
326 if(r.linkedAccount)
327 account.linkedAccount = r.linkedAccount;
328 if(r.balance)
329 account.balance = r.balance;
330 if(r.availableFunds)
331 account.availableFunds = r.availableFunds;
332 if(r.outstandingAmount)
333 account.outstandingAmount = r.outstandingAmount;
334 if(r.minimumAmount)
335 account.minimumAmount = r.minimumAmount;
336 if(r.statementAmount)
337 account.statementAmount = r.statementAmount;
338 return account;
339 }
340 /**
341 * @description Parser for Favourite List
342 * @param r responseJSON from the service
343 * @returns {Array} of Favourites objects
344 */
345
346 function parseFavouriteList(r){
347 var al = [];
348 if (r.favourites) {
349 for (var i = 0;i < r.favourites.length;i++) {
350 var favourite = new Favourites();
351 favourite.favId = r.favourites[i].favouriteIdentification;
352 favourite.favType = r.favourites[i].favouriteType;
353 favourite.alias = r.favourites[i].alias;
354 favourite.paymentType = r.favourites[i].details.paymentType;
355 if (r.favourites[i].details.toAccount) {
356 favourite.accountIdentification = r.favourites[i].details.toAccount.accountIdentification;
357 favourite.paymentInstrumentId = r.favourites[i].details.toAccount.paymentInstrumentId;
358 favourite.to_account_type = r.favourites[i].details.toAccount.type;
359 } else if (r.favourites[i].details.billerInfo) {
360 favourite.billerName = r.favourites[i].details.billerInfo.billerName;
361 favourite.paymentInstrumentId = r.favourites[i].details.billerInfo.billerPaymentInstrumentId;
362 favourite.billerCode = r.favourites[i].details.billerInfo.billerCode;
363 }
364 al.push(favourite);
365 }
366 }
367 return al;
368
369 }
370
371 /**
372 @function
373
374 @param response This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
375 */
376 if(loginParseXML)
377 delete loginParseXML;
378
379 function loginParseXML(response) {
380 if (response.customerId !== null) {
381 session.customerId = response.customer.id;
382 session.userId = response.userId;
383 pl.userId = response.userId;
384 session.customerSupportNo = response.customerSupportNo;
385 session.idNumber = response.idNumber;
386 pl.idNumber = response.idNumber;
387 session.idType = response.idType;
388 pl.idType = response.idType;
389 session.authentication = new Authentication();
390 //session.authentication.pin = response.authentication.pin;
391 session.authentication.token = response.authentication.token;
392 pl.authentication = session.authentication;
393 if(response.customer) {
394 var c = new Customer();
395 c.customerId = response.customer.id;
396 c.orgUnitId = response.customer.orgUnitId;
397 session.bankId = response.customer.orgUnitId;
398 c.blacklist = response.customer.blackListReason;
399 c.active = response.customer.active;
400 c.test = response.customer.test;
401 c.displayName = response.customer.displayName;
402 c.language = response.customer.language;
403 c.timezone = response.customer.timeZone;
404 c.typeId = response.customer.customerTypeId;
405 c.cancelId = response.customer.cancellationReasonId;
406 c.modeId = response.customer.txnReceiptModeId;
407
408 session.customer = c;
409 }
410 }
411 }
412
413 /**
414 * @description Parser for Transaction List
415 * @param r responseJSON from the service
416 * @returns {Array} of Transaction objects
417 */
418 function parseTransactionList(r) {
419 var txns = [];
420 if(r.transaction) {
421 for(var i = 0;i < r.transaction.length;i++) {
422 var txn = new Transaction();
423 txn.id = r.transaction[i].id;
424 txn.debitCredit = r.transaction[i].debitCredit;
425 txn.amount.value = r.transaction[i].amount.value;
426 txn.amount.currency = r.transaction[i].amount.currency;
427 txn.date = r.transaction[i].date;
428 txn.postingDate = r.transaction[i].postingDate;
429 txn.account.accountIdentification = r.transaction[i].account.accountIdentification;
430 txn.account.institutionCode = r.transaction[i].account.institutionCode;
431 txn.account.type = r.transaction[i].account.type;
432 txn.account.paymentInstrumentId = r.transaction[i].account.paymentInstrumentId;
433 txn.account.code = r.transaction[i].account.code;
434 txn.balance.value = r.transaction[i].balance.value;
435 txn.balance.currency = r.transaction[i].balance.currency;
436 txn.chequeNumber = r.transaction[i].chequeNumber;
437 txn.text1 = r.transaction[i].text1;
438 txn.text2 = r.transaction[i].text2;
439 txn.text3 = r.transaction[i].text3;
440 txn.text4 = r.transaction[i].text4;
441
442 txns.push(txn);
443 }
444 }
445 return txns;
446 }
447
448 /**
449 * @description parser for currencies response
450 * @param r response data
451 * @returns {Array} of parsed currecy objects with id and name properties
452 */
453 function parseCurrencies(r) {
454 var currencies = [];
455 if(r.lookupEntities != null) {
456 for(var i = 0;i < r.lookupEntities.length;i++) {
457 var currency = {};
458 currency.id = r.lookupEntities[i].id;
459 currency.name = r.lookupEntities[i].name;
460 currencies.push(currency);
461 }
462 }
463 return currencies;
464 }
465
466 /**
467 * @description parses the exchange rate fields from the server.
468 * @param r
469 * @returns {Object} containing exchange rate fields
470 */
471 function parseExchangeRate(r) {
472 var er = {};
473 if(r.exchangeRate != null) {
474 er["From Amount"] = r.exchangeRate.fromAmount;
475 er["To Amount"] = r.exchangeRate.toAmount;
476 er["Rate"] = r.exchangeRate.rate;
477 er["From Currency"] = r.exchangeRate.fromCurrency;
478 er["To Currency"] = r.exchangeRate.toCurrency;
479 }
480 return er;
481 }
482
483
484 /**
485 * @description response handler for cheque status web service calls
486 * @param r responseXML/JSON
487 */
488 function getChequeStatusResponse(r) {
489 hideProgress();
490 var rCode = getStatusCode(r);
491 if (rCode == '0') {
492 var status = parseChequeStatus(r);
493 $('#csr_status').html(status);
494 $.mobile.changePage("chequestatusresult.html", page_opt);
495 } else {
496 _alertBox('Failed to get cheque status.\n' + getErrorMessage(r));
497 }
498 appstate = trans.TRAN_IDLE;
499 }
500
501 /**
502 * @description Parser for cheque status call response
503 * @param r
504 * @returns {String}
505 */
506 function parseChequeStatus(r) {
507 return r.chequeStatus?r.chequeStatus:"UNKNOWN";
508 }
509
510 /**
511 * @description response handler for cheque stop payment request
512 * @param r
513 */
514 function getChequeStopResponse(r) {
515 hideProgress();
516 var rCode = getStatusCode(r);
517 if (rCode == '0') {
518 _alertBox('Stop cheque request have been placed successfully.');
519 $.mobile.changePage("chequemgt.html", page_opt);
520 } else {
521 _alertBox('Error:\n' + getErrorMessage(r));
522 }
523 appstate = trans.TRAN_IDLE;
524 }
525
526 /**
527 * @description Callback handler for Chequebook placements
528 * @param r
529 */
530 function placeChequeBookRequestBack(r) {
531 hideProgress();
532 var rCode = getStatusCode(r);
533 if (rCode == '0') {
534 _alertBox('Cheque book request have been placed successfully.');
535 goMBBack();
536 } else {
537 _alertBox('Failed to place cheque book request.\n' + getErrorMessage(r));
538 }
539 appstate = trans.TRAN_IDLE;
540 }
541
542 /**
543 @function
544
545 @param r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
546 */
547 var logoutBack = function(r) {
548 hideProgress();
549
550 var rCode = getStatusCode(r);
551 if (appstate == trans.TRAN_LOGOUT) {
552 if(rCode == '0') {
553 $.mobile.changePage("login.html", page_opt);
554 session = new LoginSession();
555 } else if (rCode == '353') {
556 _alertBox('Logout failed! ' + getErrorMessage(r));
557 $.mobile.changePage("login.html", page_opt);
558 session = new LoginSession();
559 } else {
560 _alertBox('Logout failed! ' + getErrorMessage(r));
561 }
562 }
563 appstate = trans.TRAN_IDLE;
564 };
565
566 /*****************************************************************************
567 * Functions
568 */
569
570 /**
571 @function
572
573 @param r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
574 */
575 function getStatusCode(r) {
576 return r.Status.code.toString();
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 @param entryName This is string of the entry node name in XML document/JSON object.
584 */
585 function parseReturnEntry(r, entryName) {
586 return r[entryName];
587 }
588
589 /**
590 @function
591
592 @param r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
593 @param entryName This is string of the entry node name in XML document/JSON object.
594 @param attrName This is string of attribute name of the entry node in XML document/JSON object.
595 */
596 function parseReturnEntryAttr(r, entryName, attrName) {
597 return r[entryName][attrName].toString();
598 }
599
600 /**
601 @function
602
603 @param r This is the XML document/JSON object that is returned by the AJAX call made by the MobiliserClient.
604 */
605 function getErrorMessage(r) {
606 var errValue = r.Status.value;
607 var errCode = r.Status.code.toString();
608 if(errValue !== null) {
609 if (errCode == '329' || errCode == '201')
610 return "Check your username or password and try again!";
611 else if (errCode == '302')
612 return "Your account is blocked! Please contact service provider.";
613 else if(errCode == '2517')
614 return "Payer has no valid wallet for this transaction";
615 else if(errCode == '2507')
616 return "Payee has no valid wallet for this transaction";
617 else
618 return r.Status.value;
619 } else {
620 var msg = '';
621 switch (errCode) {
622 case '1002': msg = "INVALID MSISDN: Indicates that (one of) the specified MSISDN(s) is invalid. MSISDNs always have to specified as +countryCodenetCodenumber"; break;
623 case '1003': msg = "UNKNOWN TRANSACTION: Indicates that the (or a) transaction specified in the request does not exist."; break;
624 case '1004': msg = "INVALID TRANSACTION: Indicates that the (or a) transaction specified in the request cannot be used/considered in the requested context."; break;
625 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;
626 case '1006': msg = "INACTIVE CUSTOMER: Indicates that the (or a) customer specified in the request cannot be used/considered because he is inactive"; break;
627 case '1008': msg = "BLACKLISTED CUSTOMER"; break;
628 case '1050': msg = "The transaction is locked by another process and cannot be handled right now"; break;
629 case '1112': msg = "INACTIVE USER: Indicates that the customer's status is inactive - see database CUSTOMER_STATUS.BOL_IS_ACTIVE."; break;
630 case '1114': msg = "CUSTOMER BLOCKED: Indicates that the customer is currently blocked due to the number of times wrong credentials have been specified."; break;
631 case '1115': msg = "BLACKLISTED USER: Indicates that the customer is blacklisted - see database CUSTOMER.ID_BLACKLISTREASON."; break;
632 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;
633 case '2231': msg = "AIRTIME LIMIT EXCEEDED"; break;
634 case '2232': msg = "CO-USER LIMIT EXCEEDED"; break;
635 case '2259': msg = "VOUCHER SALE HANDLER FAILURE"; break;
636 case '2299': msg = "TRANSACTION FAILED PERMANENTLY"; break;
637
638 //mBanking error
639
640 case '3100': msg = Str_do_not_honor; break;
641 case '3102': msg = Str_suspected_fraud; break;
642 case '3110': msg = Str_already_registerd; break;
643 case '3115': msg = Str_request_function; break;
644 case '3116': msg = Str_no_sufficient_fund; break;
645 case '3117': msg = Str_incorrect_pin; break;
646 case '3119': msg = Str_transaction_not_permitted; break;
647 case '3120': msg = Str_not_permitted_to_terminal; break;
648 case '3125': msg = Str_retry_exceeded; break;
649 case '3126': msg = Str_invalid_pin_block; break;
650 case '3127': msg = Str_pin_length; break;
651 case '3129': msg = Str_suspected_card; break;
652 case '3180': msg = Str_unknown_userid; break;
653 case '3181': msg = Str_mbanking_session; break;
654 case '3200': msg = Str_request_in_progress; break;
655 case '3210': msg = Str_invalid_amount; break;
656 case '3211': msg = Str_withdrawal_amount; break;
657 case '3212': msg = Str_withdrawal_frequency; break;
658 case '3220': msg = Str_invalid_account; break;
659 case '3221': msg = Str_no_credit_account; break;
660 case '3222': msg = Str_no_investment_account; break;
661 case '3223': msg = Str_no_current_account; break;
662 case '3224': msg = Str_no_saving_account; break;
663 case '3250': msg = Str_completed_partially; break;
664 case '3300': msg = Str_account_suspended; break;
665 case '3301': msg = Str_suspected_malfunction; break;
666 case '3302': msg = Str_technical_problem; break;
667 case '3310': msg = Str_card_frequency; break;
668 case '3320': msg = Str_bill_payment_frequency; break;
669 case '3330': msg = Str_own_account_frequency; break;
670 case '3331': msg = Str_other_account_frequency; break;
671 case '3332': msg = Str_interbank_frequency; break;
672 case '3340': msg = Str_mobile_reload_frequency; break;
673 case '3341': msg = Str_mobile_transfer_intrabank; break;
674 case '3342': msg = Str_mobile_transfer_interbank; break;
675 case '3350': msg = Str_stop_cheque_frequency; break;
676 case '3351': msg = Str_requset_check_frequency; break;
677 case '3901': msg = Str_invalid_response; break;
678 case '3902': msg = Str_invalid_transaction; break;
679 case '3904': msg = Str_format_error; break;
680 case '3907': msg = Str_card_issuer_switch_inoperative; break;
681 case '3911': msg = Str_invalid_request; break;
682 case '3913': msg = Str_duplicate_transmission; break;
683 case '3915': msg = Str_response_recieved_late; break;
684
685 default: msg = "Unknown Error!"; break;
686 }
687 return msg;
688 }
689 }
690
691 function epoch2UTC(epoch) {
692 var utcDate = new Date(epoch);
693 return utcDate.getFullYear()+'-'+pad2(utcDate.getMonth()+1)+'-'+pad2(utcDate.getDate())+
694 'T'+pad2(utcDate.getHours())+':'+pad2(utcDate.getMinutes())+':'+pad2(utcDate.getSeconds());
695 }
696
697 /**
698 @function
699 @description This function can be used for debugging purposes to display the contents of an XML message.
700 Depending on the browser capabilities, the data will be serialized.
701
702 @param xmlDoc This is the XML data that will be shown in the alert box.
703 */
704 function alertXML(xmlDoc) {
705 if (xmlDoc.xml) // IE
706 _alertBox(xmlHttpReq.responseXML.xml);
707 else // MOZ
708 _alertBox((new XMLSerializer()).serializeToString(xmlDoc));
709 }
710
711 /**
712 @param message Message to display in the alert box
713 */
714 function _alertBox(message) {
715 if (typeof navigator.notification != 'undefined' && typeof navigator.notification.alert == 'function')
716 navigator.notification.alert(message,null,"Mobiliser Smartphone","OK");
717 else
718 alert(message); // default alert function to be used
719 }
720
721 /**
722 @param message Message to display in the confirm box
723 */
724 function _confirmBox(message, confirmCallback) {
725 if (typeof navigator.notification != 'undefined' && typeof navigator.notification.confirm == 'function')
726 navigator.notification.confirm(message, confirmCallback,"Mobiliser Smartphone","OK,Cancel");
727 else {
728 confirmCallback(confirm(message));
729 }
730 }
731
732
733 /**
734 * @description parser for currencies response
735 * @param r response data
736 * @param filter an optional array which maps a new string for name
737 * @returns {Array} of parsed currecy objects with id and name properties
738 */
739 function parseLookupEntities(r, filter) {
740 var entities = [];
741 if(r.lookupEntities != null) {
742 for(var i = 0;i < r.lookupEntities.length;i++) {
743 var entity = {};
744 entity.id = r.lookupEntities[i].id;
745 //Check if filter is provided
746 if(filter) {
747 //Check if filter contains the key
748 entity.name = filter[r.lookupEntities[i].name]?filter[r.lookupEntities[i].name]:r.lookupEntities[i].name;
749 } else {
750 //No filter store the name as it is returned by service
751 entity.name = r.lookupEntities[i].name;
752 }
753 entities.push(entity);
754 }
755 }
756 return entities;
757 }
758
759 /**
760 * @description Mbanking TopUp
761 */
762 function MBankingTopUpBack(r) {
763 hideProgress();
764 var rCode = getStatusCode(r);
765 if (rCode == '0') {
766 $.mobile.changePage("prepaiddone.html", page_opt);
767 $('#tp_fromaccountbal').text(r.fromAccountBalance.currency + " " + r.fromAccountBalance.value/100);
768 $('#refno3').text(r.transactionId);
769 } else {
770 _alertBox("Failed to top up! " + getErrorMessage(r));
771 }
772 }
773
774 /**
775 * @description Callback handler for Mbanking denominations
776 * @param r responseJSON containing products
777 */
778 function denominationsBack(r){
779 hideProgress();
780 var rCode = getStatusCode(r);
781 if (rCode == '0') {
782 session.denominations = parseDenomination(r);
783 if(session.denominations.length < 1) {
784 _alertBox("No products found for you.");
785 } else {
786 populateDenominations('#topup_denomination', session.denominations);
787 }
788 } else {
789 _alertBox('getting denominations failed! ' + getErrorMessage(r));
790 }
791 }
792
793
794
795 /**
796 * @description parser for denomimation response
797 * @param r response data
798 * @returns {Array} of parsed denomination objects with id and name properties
799 */
800 function parseDenomination(r) {
801 var denominations = [];
802 if(r.denomination) {
803 for(var i = 0;i <r.denomination.length;i++) {
804 var denomination = new Denomination();
805 denomination.id = r.denomination[i].denominationId;
806 denomination.amount = r.denomination[i].amount;
807 denomination.description = r.denomination[i].description;
808 denomination.code = r.denomination[i].code;
809 denomination.subcode = r.denomination[i].subCode;
810 denominations.push(denomination);
811 }
812 }
813 return denominations;
814 }