diff --git a/examples/card-form/index.html b/examples/card-form/index.html index e4824ff6..2aff9d91 100644 --- a/examples/card-form/index.html +++ b/examples/card-form/index.html @@ -65,7 +65,7 @@ const radioGroup = document.createElement('div') radioGroup.className = 'combo-card-types' radioGroup.style.cssText = 'margin: 15px 0; padding: 15px; border: 1px solid #ddd; border-radius: 5px; background: #f9f9f9;' - + radioGroup.innerHTML = `

Select Card Type:

${cardInfo.combo_card_types.map((type, index) => ` @@ -75,11 +75,11 @@

Select Card Type:

`).join('')} ` - + // Insert before the Pay button const payButton = document.querySelector('.submit-button') payButton.parentNode.insertBefore(radioGroup, payButton) - + // Add event listener to track selection changes const radioButtons = radioGroup.querySelectorAll('input[name="cardType"]') radioButtons.forEach(radio => { @@ -88,7 +88,7 @@

Select Card Type:

console.log("User selected card type:", preferredCardType) }) }) - + // Set initial value preferredCardType = null } @@ -98,7 +98,7 @@

Select Card Type:

} ) } - + document.getElementById("errors").innerHTML = "" }) diff --git a/package.json b/package.json index 4b6112af..faa35f1b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "processout.js", - "version": "1.9.10", + "version": "1.9.11", "description": "ProcessOut.js is a JavaScript library for ProcessOut's payment processing API.", "scripts": { "build:processout": "tsc -p src/processout && uglifyjs --compress --keep-fnames --ie8 dist/processout.js -o dist/processout.js", diff --git a/src/dynamic-checkout/payment-methods/card.ts b/src/dynamic-checkout/payment-methods/card.ts index 7dfb18cc..4e7b92d7 100644 --- a/src/dynamic-checkout/payment-methods/card.ts +++ b/src/dynamic-checkout/payment-methods/card.ts @@ -661,7 +661,10 @@ module ProcessOut { const eventData = e.data ? JSON.parse(e.data) : {} if (eventData.action === "inputEvent") { - if (eventData.data && eventData.data.card_iin !== undefined) { + if ( + eventData.data && + (eventData.data.card_iin8 !== undefined || eventData.data.card_iin !== undefined) + ) { this.handleIinRestrictionFromMessage(eventData.data) } @@ -926,14 +929,21 @@ module ProcessOut { return } - const iin = data.card_iin || "" + // Prefer the 8-digit IIN when present so 8-digit allowlist entries can + // match; fall back to the legacy 6-digit card_iin. + const iin = data.card_iin8 || data.card_iin || "" if (iin.length === 0) { this.setCardRestrictionState(false) return } - const isAllowedIin = restrictToIins.indexOf(iin) !== -1 + // card_iin8 may carry more digits than the configured entries (IINs can + // be 6 or 8 digits), so match on prefix: an allowed entry matches when + // the detected IIN starts with it. + const isAllowedIin = restrictToIins.some(function (allowedIin) { + return allowedIin.length > 0 && iin.substring(0, allowedIin.length) === allowedIin + }) this.setCardRestrictionState(!isAllowedIin) } diff --git a/src/processout/card.ts b/src/processout/card.ts index 480d8789..795be0c3 100644 --- a/src/processout/card.ts +++ b/src/processout/card.ts @@ -461,6 +461,63 @@ module ProcessOut { return number.substring(0, l); } + /** + * GetIIN8 returns the IIN of the card number, exposing up to 8 digits + * when PCI rules allow it (scheme in the allow-list and a 16-digit + * PAN) and 6 digits otherwise. + * @param {string} number + * @return {string} + */ + public static getIIN8(number: string): string { + number = Card.parseNumber(number); // Remove potential spaces + + if (number.length < 6) + return number; + + if (Card.canExpose8DigitIIN(number)) + return number.substring(0, 8); + + return number.substring(0, 6); + } + + /** + * Schemes permitted to surface an 8-digit IIN, mirroring the backend + * allow-list in api (controllers/card_inn.go). Every other scheme - + * notably American Express - is capped at 6 digits. Note the JS + * scheme key "union-pay" maps to the backend's "china union pay". + */ + private static iin8DigitSchemes: Array = [ + "visa", "mastercard", "discover", "jcb", "union-pay", "carte bancaire" + ]; + + /** + * canExpose8DigitIIN reports whether an 8-digit IIN may be surfaced + * for the given card number. Mirrors binder's TruncateNumber: the PAN + * must be exactly 16 digits and every detected scheme must be in the + * allow-list. Conservative on co-badged or ambiguous prefixes (and + * unknown schemes), which fall back to 6 digits. + * @param {string} number + * @return {boolean} + */ + public static canExpose8DigitIIN(number: string): boolean { + number = Card.parseNumber(number); // Remove potential spaces + + // PCI: 8-digit BINs are only defined for 16-digit PANs. + if (number.length != 16) + return false; + + var schemes = Card.getPossibleSchemes(number); + if (schemes.length == 0) + return false; + + for (var i = 0; i < schemes.length; i++) { + if (Card.iin8DigitSchemes.indexOf(schemes[i]) === -1) + return false; + } + + return true; + } + /** * GetLast4Digits returns the last4 digits of the card number * @param {string} number diff --git a/src/processout/processout.ts b/src/processout/processout.ts index 2ae80956..d5a8df4c 100644 --- a/src/processout/processout.ts +++ b/src/processout/processout.ts @@ -1676,7 +1676,10 @@ module ProcessOut { return } - const iin = cardNumber.substring(0, 6) + // Support up to 8-digit IINs (some networks issue 8-digit IINs, which + // yield more accurate issuer information); fall back to whatever is + // available when fewer digits were provided. + const iin = cardNumber.substring(0, 8) const apiEndpoint = `iins/${iin}` this.apiRequest(