diff --git a/partner-cjk.js b/partner-cjk.js index 04afacf..572a6ed 100644 --- a/partner-cjk.js +++ b/partner-cjk.js @@ -69,7 +69,7 @@ function getSNFromMessage(message) { try { var sn_match = message.match(/SN: (\w+)/); logger.verbose('Got SN: ' + sn_match[1]); - return sn_match[1]; + return sn_match[1].trim(); } catch(err) { logger.verbose('Exception on getting sn from message', {err: err}); @@ -102,6 +102,15 @@ function supplierRcToST24Rc(rc) { } } +function getSNFromResponseObject(respObj) { + try { + return respObj.ciwaru.sn[0].trim(); + } + catch(err) { + return; + } +} + function topupResponseHandler(body, task) { //logger.info('Got reply from partner', {body: body}); xml2js(body, function(err, result) { @@ -125,9 +134,14 @@ function topupResponseHandler(body, task) { rc = '68'; } else if (hasSuccessKeywords(message)) { - var sn = getSNFromMessage(message); + var sn = getSNFromResponseObject(result); + if (!sn) { + sn = getSNFromMessage(message); + } + message = 'SN=' + sn + '; ' + message; rc = '00'; + } else { rc = supplierRcToST24Rc(result.ciwaru.rc[0]); if (!rc) {