nets-service-sdk 1.1.15 → 1.1.16
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.
- package/dist/index.js +71 -25
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -353,6 +353,40 @@ var require_httpRequest = __commonJS({
|
|
|
353
353
|
var require_parser = __commonJS({
|
|
354
354
|
"src/payment/parser.js"(exports2, module2) {
|
|
355
355
|
var logger = require_winston()(module2);
|
|
356
|
+
var RESPONSE_CODES = {
|
|
357
|
+
"00": { status: "APPROVED", detail: "SUCCESS", category: "SUCCESS" },
|
|
358
|
+
"04": { status: "DECLINED", detail: "PICKUP_CARD", category: "HARD_FAIL" },
|
|
359
|
+
"05": { status: "DECLINED", detail: "DO_NOT_HONOUR", category: "HARD_FAIL" },
|
|
360
|
+
"07": { status: "DECLINED", detail: "PICKUP_CARD_SPECIAL", category: "HARD_FAIL" },
|
|
361
|
+
"12": { status: "DECLINED", detail: "INVALID_TRANSACTION", category: "HARD_FAIL" },
|
|
362
|
+
"13": { status: "DECLINED", detail: "INVALID_AMOUNT", category: "HARD_FAIL" },
|
|
363
|
+
"14": { status: "DECLINED", detail: "INVALID_CARD", category: "HARD_FAIL" },
|
|
364
|
+
"30": { status: "DECLINED", detail: "FORMAT_ERROR", category: "HARD_FAIL" },
|
|
365
|
+
"41": { status: "DECLINED", detail: "LOST_CARD", category: "HARD_FAIL" },
|
|
366
|
+
"43": { status: "DECLINED", detail: "STOLEN_CARD", category: "HARD_FAIL" },
|
|
367
|
+
"51": { status: "DECLINED", detail: "INSUFFICIENT_FUNDS", category: "HARD_FAIL" },
|
|
368
|
+
"54": { status: "DECLINED", detail: "EXPIRED_CARD", category: "HARD_FAIL" },
|
|
369
|
+
"55": { status: "DECLINED", detail: "WRONG_PIN", category: "HARD_FAIL" },
|
|
370
|
+
"57": { status: "DECLINED", detail: "NOT_PERMITTED", category: "HARD_FAIL" },
|
|
371
|
+
"58": { status: "DECLINED", detail: "TERMINAL_NOT_ALLOWED", category: "HARD_FAIL" },
|
|
372
|
+
"61": { status: "DECLINED", detail: "LIMIT_EXCEEDED", category: "HARD_FAIL" },
|
|
373
|
+
"62": { status: "DECLINED", detail: "RESTRICTED_CARD", category: "HARD_FAIL" },
|
|
374
|
+
"63": { status: "DECLINED", detail: "SECURITY_ISSUE", category: "HARD_FAIL" },
|
|
375
|
+
"65": { status: "DECLINED", detail: "FREQUENCY_LIMIT", category: "HARD_FAIL" },
|
|
376
|
+
"68": { status: "RETRY", detail: "RESPONSE_RECEIVED_TOO_LATE", category: "RETRY" },
|
|
377
|
+
"75": { status: "DECLINED", detail: "PIN_LOCKED", category: "HARD_FAIL" },
|
|
378
|
+
"91": { status: "RETRY", detail: "ISSUER_UNAVAILABLE", category: "RETRY" },
|
|
379
|
+
"96": { status: "DECLINED", detail: "SYSTEM_ERROR", category: "HARD_FAIL" },
|
|
380
|
+
"TO": { status: "TIME_OUT", detail: "TIMEOUT", category: "RETRY" },
|
|
381
|
+
"CE": { status: "RETRY", detail: "COMMUNICATION_ERROR", category: "RETRY" },
|
|
382
|
+
"PE": { status: "DECLINED", detail: "PROTOCOL_ERROR", category: "HARD_FAIL" },
|
|
383
|
+
"NA": { status: "RETRY", detail: "NO_ACKNOWLEDGEMENT", category: "RETRY" },
|
|
384
|
+
"US": { status: "USER_CANCELLED", detail: "USER_CANCELLED", category: "HARD_FAIL" },
|
|
385
|
+
"GX": { status: "OUT_OF_PAPER", detail: "OUT_OF_PAPER", category: "HARD_FAIL" }
|
|
386
|
+
};
|
|
387
|
+
function getResponseFromCode(code) {
|
|
388
|
+
return RESPONSE_CODES[code] || null;
|
|
389
|
+
}
|
|
356
390
|
module2.exports.statusParser = (hexCode, ecn) => {
|
|
357
391
|
const splitted = hexCode.split("1C");
|
|
358
392
|
for (let i = 0; i < splitted.length; i++) {
|
|
@@ -377,11 +411,11 @@ var require_parser = __commonJS({
|
|
|
377
411
|
} else {
|
|
378
412
|
const subStringArray = ascii.splitAtIndex(2);
|
|
379
413
|
if (subStringArray.length > 0) {
|
|
380
|
-
if (subStringArray.length >
|
|
414
|
+
if (subStringArray.length > 1 && subStringArray[0].cleanUp() == "02" && subStringArray[1].cleanUp()?.indexOf("APPROVED") > -1) {
|
|
381
415
|
status = true;
|
|
382
416
|
}
|
|
383
417
|
const identifier = subStringArray[0].cleanUp();
|
|
384
|
-
const value = subStringArray[1]
|
|
418
|
+
const value = subStringArray[1]?.cleanUp();
|
|
385
419
|
if (identifier && value) {
|
|
386
420
|
json[identifier] = value;
|
|
387
421
|
}
|
|
@@ -465,6 +499,7 @@ var require_parser = __commonJS({
|
|
|
465
499
|
if (statusResponse) {
|
|
466
500
|
translatedJson.status = statusResponse.status;
|
|
467
501
|
translatedJson.description = statusResponse.detail;
|
|
502
|
+
translatedJson.category = statusResponse.category;
|
|
468
503
|
if (statusResponse.balance) {
|
|
469
504
|
translatedJson["balance"] = statusResponse.balance;
|
|
470
505
|
}
|
|
@@ -473,6 +508,7 @@ var require_parser = __commonJS({
|
|
|
473
508
|
if (ecnnError) {
|
|
474
509
|
translatedJson.status = ecnnError.status;
|
|
475
510
|
translatedJson.description = ecnnError.detail;
|
|
511
|
+
translatedJson.category = ecnnError.category;
|
|
476
512
|
}
|
|
477
513
|
translatedJson["responsetext"] = obj[key];
|
|
478
514
|
}
|
|
@@ -553,6 +589,12 @@ var require_parser = __commonJS({
|
|
|
553
589
|
}
|
|
554
590
|
if (key == "HC") {
|
|
555
591
|
translatedJson["hostResponseCode"] = obj[key];
|
|
592
|
+
const mapped = getResponseFromCode(obj[key]);
|
|
593
|
+
if (mapped) {
|
|
594
|
+
translatedJson.status = mapped.status;
|
|
595
|
+
translatedJson.description = mapped.detail;
|
|
596
|
+
translatedJson.category = mapped.category;
|
|
597
|
+
}
|
|
556
598
|
}
|
|
557
599
|
if (key == "HD") {
|
|
558
600
|
translatedJson["enhancedECRReferenceNumber"] = obj[key];
|
|
@@ -598,8 +640,19 @@ var require_parser = __commonJS({
|
|
|
598
640
|
return { translated: translatedJson, raw: obj };
|
|
599
641
|
};
|
|
600
642
|
function statusCheck(data) {
|
|
643
|
+
if (!data) return null;
|
|
644
|
+
const code = data.substring(0, 2);
|
|
645
|
+
const mapped = getResponseFromCode(code);
|
|
646
|
+
if (mapped) {
|
|
647
|
+
const result = { ...mapped };
|
|
648
|
+
if (code === "00" && data.indexOf("BAL:") > -1) {
|
|
649
|
+
const balance = data.split("BAL:");
|
|
650
|
+
result.balance = balance[1].trim();
|
|
651
|
+
}
|
|
652
|
+
return result;
|
|
653
|
+
}
|
|
601
654
|
if (data?.indexOf("APPROVED") > -1) {
|
|
602
|
-
const response = { status: "APPROVED", detail: "Payment Succeed" };
|
|
655
|
+
const response = { status: "APPROVED", detail: "Payment Succeed", category: "SUCCESS" };
|
|
603
656
|
if (data?.indexOf("BAL:") > -1) {
|
|
604
657
|
const balance = data.split("BAL:");
|
|
605
658
|
response.balance = balance[1].trim();
|
|
@@ -607,28 +660,25 @@ var require_parser = __commonJS({
|
|
|
607
660
|
return response;
|
|
608
661
|
}
|
|
609
662
|
if (data?.indexOf("INVALID CARD") > -1) {
|
|
610
|
-
return { status: "INVALID_CARD", detail: "Invalid Card" };
|
|
663
|
+
return { status: "INVALID_CARD", detail: "Invalid Card", category: "HARD_FAIL" };
|
|
611
664
|
}
|
|
612
665
|
if (data?.indexOf("F3905-Parameter") > -1) {
|
|
613
|
-
return { status: "INVALID_CARD", detail: "Invalid Card" };
|
|
666
|
+
return { status: "INVALID_CARD", detail: "Invalid Card", category: "HARD_FAIL" };
|
|
614
667
|
}
|
|
615
668
|
if (data?.indexOf("DECLINED") > -1) {
|
|
616
|
-
return { status: "DECLINED", detail: "Transaction Declined" };
|
|
669
|
+
return { status: "DECLINED", detail: "Transaction Declined", category: "HARD_FAIL" };
|
|
617
670
|
}
|
|
618
671
|
if (data?.indexOf("CARD NOT SUPPORTED") > -1) {
|
|
619
|
-
return { status: "CARD_NOT_SUPPORTED", detail: "Card not supported" };
|
|
672
|
+
return { status: "CARD_NOT_SUPPORTED", detail: "Card not supported", category: "HARD_FAIL" };
|
|
620
673
|
}
|
|
621
674
|
return null;
|
|
622
675
|
}
|
|
623
676
|
function CheckECNERROR(data) {
|
|
624
|
-
if (data
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
}
|
|
630
|
-
if (data?.indexOf("TO") > -1) {
|
|
631
|
-
return { status: "TIME_OUT", detail: "Time Out" };
|
|
677
|
+
if (!data) return null;
|
|
678
|
+
for (const code of ["US", "GX", "TO"]) {
|
|
679
|
+
if (data.indexOf(code) > -1) {
|
|
680
|
+
return getResponseFromCode(code);
|
|
681
|
+
}
|
|
632
682
|
}
|
|
633
683
|
return null;
|
|
634
684
|
}
|
|
@@ -770,7 +820,7 @@ var require_responseHandler = __commonJS({
|
|
|
770
820
|
activePaymentEcn = null;
|
|
771
821
|
}
|
|
772
822
|
if (response.translated) {
|
|
773
|
-
if (response.translated.status == "APPROVED") {
|
|
823
|
+
if (response.translated.category == "SUCCESS" || response.translated.status == "APPROVED") {
|
|
774
824
|
sendMessage2("clientRoom", "PAYMENT_MESSAGE", {
|
|
775
825
|
success: true,
|
|
776
826
|
status: "SUCCESS",
|
|
@@ -778,15 +828,13 @@ var require_responseHandler = __commonJS({
|
|
|
778
828
|
action: "COMPLETED"
|
|
779
829
|
});
|
|
780
830
|
sendPaymentResponseToCloud(response.translated);
|
|
781
|
-
}
|
|
782
|
-
if (response.translated.status == "TIME_OUT") {
|
|
831
|
+
} else if (response.translated.category == "RETRY" || response.translated.status == "TIME_OUT") {
|
|
783
832
|
sendMessage2("clientRoom", "PAYMENT_MESSAGE", {
|
|
784
833
|
status: "RETRY",
|
|
785
834
|
response,
|
|
786
835
|
action: "RETRY"
|
|
787
836
|
});
|
|
788
|
-
}
|
|
789
|
-
if (response.translated.status == "USER_CANCELLED" || response.translated.status == "OUT_OF_PAPER" || response.translated.status == "INVALID_CARD" || response.translated.status == "DECLINED" || response.translated.status == "CARD_NOT_SUPPORTED") {
|
|
837
|
+
} else {
|
|
790
838
|
sendMessage2("clientRoom", "PAYMENT_MESSAGE", {
|
|
791
839
|
status: "CANCELLED",
|
|
792
840
|
response,
|
|
@@ -803,7 +851,7 @@ var require_responseHandler = __commonJS({
|
|
|
803
851
|
activePaymentEcn = null;
|
|
804
852
|
}
|
|
805
853
|
if (response.translated) {
|
|
806
|
-
if (response.translated.status == "APPROVED") {
|
|
854
|
+
if (response.translated.category == "SUCCESS" || response.translated.status == "APPROVED") {
|
|
807
855
|
sendMessage2("clientRoom", "PAYMENT_MESSAGE", {
|
|
808
856
|
success: true,
|
|
809
857
|
status: "SUCCESS",
|
|
@@ -811,15 +859,13 @@ var require_responseHandler = __commonJS({
|
|
|
811
859
|
action: "COMPLETED"
|
|
812
860
|
});
|
|
813
861
|
sendPaymentResponseToCloud(response.translated);
|
|
814
|
-
}
|
|
815
|
-
if (response.translated.status == "TIME_OUT") {
|
|
862
|
+
} else if (response.translated.category == "RETRY" || response.translated.status == "TIME_OUT") {
|
|
816
863
|
sendMessage2("clientRoom", "PAYMENT_MESSAGE", {
|
|
817
864
|
status: "RETRY",
|
|
818
865
|
response,
|
|
819
866
|
action: "RETRY"
|
|
820
867
|
});
|
|
821
|
-
}
|
|
822
|
-
if (response.translated.status == "USER_CANCELLED" || response.translated.status == "OUT_OF_PAPER" || response.translated.status == "INVALID_CARD" || response.translated.status == "DECLINED" || response.translated.status == "CARD_NOT_SUPPORTED") {
|
|
868
|
+
} else {
|
|
823
869
|
sendMessage2("clientRoom", "PAYMENT_MESSAGE", {
|
|
824
870
|
status: "CANCELLED",
|
|
825
871
|
response,
|