nets-service-sdk 1.1.8 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +47 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -374,13 +374,16 @@ var require_httpRequest = __commonJS({
374
374
  // src/payment/parser.js
375
375
  var require_parser = __commonJS({
376
376
  "src/payment/parser.js"(exports2, module2) {
377
+ var logger = require_winston()(module2);
377
378
  module2.exports.statusParser = (hexCode, ecn) => {
378
379
  const splitted = hexCode.split("1c");
379
380
  for (let i = 0; i < splitted.length; i++) {
380
- if (splitted[i].toAsciiString().indexOf(ecn) > -1) {
381
+ if (splitted[i]?.toAsciiString()?.indexOf(ecn) > -1) {
382
+ logger.log({ level: "info", message: `statusParser: ECN ${ecn} found in response` });
381
383
  return true;
382
384
  }
383
385
  }
386
+ logger.log({ level: "info", message: `statusParser: ECN ${ecn} NOT found in response` });
384
387
  return false;
385
388
  };
386
389
  module2.exports.logonParser = (hexCode, ecn) => {
@@ -390,13 +393,13 @@ var require_parser = __commonJS({
390
393
  const json = {};
391
394
  for (let i = 0; i < splitted.length; i++) {
392
395
  const ascii = splitted[i].toAsciiString();
393
- if (ascii.indexOf(ecn) > -1) {
396
+ if (ascii?.indexOf(ecn) > -1) {
394
397
  status = true;
395
398
  json["ECN"] = ascii.cleanUp();
396
399
  } else {
397
400
  const subStringArray = ascii.splitAtIndex(2);
398
- if (subStringArray.length > 1) {
399
- if (subStringArray[0] == "02" && subStringArray[0].indexOf("APPROVED") > -1) {
401
+ if (subStringArray.length > 0) {
402
+ if (subStringArray.length > 2 && subStringArray[0] == "02" && subStringArray[0]?.indexOf("APPROVED") > -1) {
400
403
  status = true;
401
404
  }
402
405
  const identifier = subStringArray[0].cleanUp();
@@ -407,8 +410,10 @@ var require_parser = __commonJS({
407
410
  }
408
411
  }
409
412
  }
413
+ logger.log({ level: "info", message: `logonParser completed for ECN ${ecn}: status ${status}` });
410
414
  return { status, json };
411
415
  } catch (e) {
416
+ logger.log({ level: "error", message: `Error in logonParser: ${e.message}`, stack: e.stack });
412
417
  throw e;
413
418
  }
414
419
  };
@@ -419,7 +424,7 @@ var require_parser = __commonJS({
419
424
  const json = {};
420
425
  for (let i = 0; i < splitted.length; i++) {
421
426
  const ascii = splitted[i].toAsciiString();
422
- if (ascii.indexOf(ecn) > -1) {
427
+ if (ascii?.indexOf(ecn) > -1) {
423
428
  json["ECN"] = ascii.cleanUp();
424
429
  } else {
425
430
  const subStringArray = ascii.splitAtIndex(2);
@@ -432,8 +437,10 @@ var require_parser = __commonJS({
432
437
  }
433
438
  }
434
439
  }
440
+ logger.log({ level: "info", message: `netsPaymentParser completed for ECN ${ecn}` });
435
441
  return json;
436
442
  } catch (e) {
443
+ logger.log({ level: "error", message: `Error in netsPaymentParser: ${e.message}`, stack: e.stack });
437
444
  throw e;
438
445
  }
439
446
  };
@@ -444,7 +451,7 @@ var require_parser = __commonJS({
444
451
  const json = {};
445
452
  for (let i = 0; i < splitted.length; i++) {
446
453
  const ascii = splitted[i].toAsciiString();
447
- if (ascii.indexOf(ecn) > -1) {
454
+ if (ascii?.indexOf(ecn) > -1) {
448
455
  json["ECN"] = ascii.cleanUp();
449
456
  } else {
450
457
  const subStringArray = ascii.splitAtIndex(2);
@@ -457,8 +464,10 @@ var require_parser = __commonJS({
457
464
  }
458
465
  }
459
466
  }
467
+ logger.log({ level: "info", message: `creditPaymentParser completed for ECN ${ecn}` });
460
468
  return json;
461
469
  } catch (e) {
470
+ logger.log({ level: "error", message: `Error in creditPaymentParser: ${e.message}`, stack: e.stack });
462
471
  throw e;
463
472
  }
464
473
  };
@@ -604,39 +613,40 @@ var require_parser = __commonJS({
604
613
  translatedJson["receiptTextFormat"] = obj[key];
605
614
  }
606
615
  });
616
+ logger.log({ level: "info", message: "jsonProcessor translated terminal response into JSON format." });
607
617
  return { translated: translatedJson, raw: obj };
608
618
  };
609
619
  function statusCheck(data) {
610
- if (data.indexOf("APPROVED") > -1) {
620
+ if (data?.indexOf("APPROVED") > -1) {
611
621
  const response = { status: "APPROVED", detail: "Payment Succeed" };
612
- if (data.indexOf("BAL:") > -1) {
622
+ if (data?.indexOf("BAL:") > -1) {
613
623
  const balance = data.split("BAL:");
614
624
  response.balance = balance[1].trim();
615
625
  }
616
626
  return response;
617
627
  }
618
- if (data.indexOf("INVALID CARD") > -1) {
628
+ if (data?.indexOf("INVALID CARD") > -1) {
619
629
  return { status: "INVALID_CARD", detail: "Invalid Card" };
620
630
  }
621
- if (data.indexOf("F3905-Parameter") > -1) {
631
+ if (data?.indexOf("F3905-Parameter") > -1) {
622
632
  return { status: "INVALID_CARD", detail: "Invalid Card" };
623
633
  }
624
- if (data.indexOf("DECLINED") > -1) {
634
+ if (data?.indexOf("DECLINED") > -1) {
625
635
  return { status: "DECLINED", detail: "Transaction Declined" };
626
636
  }
627
- if (data.indexOf("CARD NOT SUPPORTED") > -1) {
637
+ if (data?.indexOf("CARD NOT SUPPORTED") > -1) {
628
638
  return { status: "CARD_NOT_SUPPORTED", detail: "Card not supported" };
629
639
  }
630
640
  return null;
631
641
  }
632
642
  function CheckECNERROR(data) {
633
- if (data.indexOf("US") > -1) {
643
+ if (data?.indexOf("US") > -1) {
634
644
  return { status: "USER_CANCELLED", detail: "User Cancelled" };
635
645
  }
636
- if (data.indexOf("GX") > -1) {
646
+ if (data?.indexOf("GX") > -1) {
637
647
  return { status: "OUT_OF_PAPER", detail: "Out of Paper" };
638
648
  }
639
- if (data.indexOf("TO") > -1) {
649
+ if (data?.indexOf("TO") > -1) {
640
650
  return { status: "TIME_OUT", detail: "Time Out" };
641
651
  }
642
652
  return null;
@@ -1339,8 +1349,17 @@ var require_communication = __commonJS({
1339
1349
  stopBits: 1,
1340
1350
  parity: "none"
1341
1351
  });
1352
+ global.port.on("open", () => {
1353
+ logger.log({
1354
+ level: "info",
1355
+ message: `Port connected successfully on ${config.simulation ? config.simulationPort : config.com}`
1356
+ });
1357
+ });
1342
1358
  global.port.on("data", (data) => {
1343
- console.log(data);
1359
+ logger.log({
1360
+ level: "info",
1361
+ message: `Data received from terminal: ${data.toString("hex")}`
1362
+ });
1344
1363
  if (data.toString("hex").length == 2 && data.toString("hex") == "15") {
1345
1364
  count--;
1346
1365
  ackOrNack = data;
@@ -1375,6 +1394,10 @@ var require_communication = __commonJS({
1375
1394
  requestPayload = body;
1376
1395
  if (requestType == "STATUS_CHECK") {
1377
1396
  calculated = generateStatusReq();
1397
+ logger.log({
1398
+ level: "info",
1399
+ message: `Calculated STATUS_CHECK request: ${calculated.buffer.toString("hex")}`
1400
+ });
1378
1401
  try {
1379
1402
  createTransaction({
1380
1403
  ecn: calculated.ecn,
@@ -1396,6 +1419,10 @@ var require_communication = __commonJS({
1396
1419
  }
1397
1420
  if (requestType == "LOGON") {
1398
1421
  calculated = generateLogonRequest();
1422
+ logger.log({
1423
+ level: "info",
1424
+ message: `Calculated LOGON request: ${calculated.buffer.toString("hex")}`
1425
+ });
1399
1426
  try {
1400
1427
  createTransaction({
1401
1428
  ecn: calculated.ecn,
@@ -1418,7 +1445,10 @@ var require_communication = __commonJS({
1418
1445
  if (requestType == "PAYMENT" || requestType == "CREDIT_PAYMENT") {
1419
1446
  exports2.reset();
1420
1447
  calculated = generatePaymentRequest(body);
1421
- console.log(calculated);
1448
+ logger.log({
1449
+ level: "info",
1450
+ message: `Calculated payment request: ${calculated.hexString || calculated.buffer && calculated.buffer.toString("hex")}`
1451
+ });
1422
1452
  try {
1423
1453
  createTransaction({
1424
1454
  ecn: calculated.ecn,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nets-service-sdk",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "Utility functions for Nets Service",
5
5
  "source": "src/index.js",
6
6
  "main": "dist/index.js",