diff --git a/src/core/lib/Pan.mjs b/src/core/lib/Pan.mjs index 49b03e86..475b4fd0 100644 --- a/src/core/lib/Pan.mjs +++ b/src/core/lib/Pan.mjs @@ -220,11 +220,11 @@ function parsePan(pan) { return { pan: normalized, network: brand || "Unknown", - cardType: typeHint ? typeHint.likelyType : "Unknown", - cardTypeConfidence: typeHint ? typeHint.confidence : "low", - cardTypeNote: typeHint ? - typeHint.note : - "Card type cannot be determined — the PAN did not match a known network range.", + ...(typeHint && typeHint.confidence !== "low" ? { + cardType: typeHint.likelyType, + cardTypeConfidence: typeHint.confidence, + cardTypeNote: typeHint.note, + } : {}), majorIndustryIdentifier: mii, majorIndustryIdentifierDescription: MII_DESCRIPTIONS[mii] || "Unknown", issuerIdentificationNumber: normalized.substring(0, Math.min(8, normalized.length)), @@ -250,18 +250,17 @@ function finalizePan(body) { } /** - * Generates a numeric filler string. + * Generates random filler digits. * * @param {number} length * @returns {string} */ function fillerDigits(length) { - const seed = "12345678901234567890"; - return seed.repeat(Math.ceil(length / seed.length)).substring(0, length); + return Array.from({ length }, () => Math.floor(Math.random() * 10)).join(""); } /** - * Generates a deterministic brand-valid PAN. + * Generates a random brand-valid PAN. * * @param {string} brand * @param {number} requestedLength diff --git a/tests/operations/tests/Payment.mjs b/tests/operations/tests/Payment.mjs index ac56bd67..59da2a24 100644 --- a/tests/operations/tests/Payment.mjs +++ b/tests/operations/tests/Payment.mjs @@ -401,9 +401,6 @@ TestRegister.addTests([ pan: "4024140000000131", source: "Public Visa test PAN published in Mastercard AVS scenario documentation.", network: "Visa", - cardType: "Unknown", - cardTypeConfidence: "low", - cardTypeNote: "Visa issues credit, debit, and prepaid cards. The product type is determined by the issuer BIN, not the PAN prefix — a BIN database lookup is required.", majorIndustryIdentifier: "4", majorIndustryIdentifierDescription: "Banking and financial (Visa)", issuerIdentificationNumber: "40241400", @@ -424,13 +421,13 @@ TestRegister.addTests([ ] }, { - name: "Generate Test PAN: American Express generated sample", + name: "Generate Test PAN: American Express curated sample", input: "", - expectedOutput: "371234567890120", + expectedOutput: "371449635398431", recipeConfig: [ { op: "Generate Test PAN", - args: ["American Express", "Generated valid PAN", 15, false] + args: ["American Express", "Curated sample", 15, false] } ] },