From 185827b6da971bd87f8aba04c06713ef9ed6c692 Mon Sep 17 00:00:00 2001 From: Kapil Raghuwanshi Date: Thu, 28 Apr 2022 09:41:02 +0530 Subject: [PATCH 1/2] Added Rupay card support, updated configs, added test cases --- src/__tests__/index.ts | 37 +++++++++++++++++++++++++------------ src/index.ts | 2 ++ src/lib/card-types.ts | 11 +++++++++++ src/types.ts | 6 ++++-- 4 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/__tests__/index.ts b/src/__tests__/index.ts index 348a2e9d..a17a9492 100644 --- a/src/__tests__/index.ts +++ b/src/__tests__/index.ts @@ -125,7 +125,7 @@ describe("creditCardType", () => { ["6221558812340000", "unionpay"], ["6269992058134322", "unionpay"], ["622018111111111111", "unionpay"], - ["8", "unionpay"], + ["8110", "unionpay"], ["8100513433325374", "unionpay"], ["8111700872004845", "unionpay"], ["8141618644273338", "unionpay"], @@ -148,6 +148,10 @@ describe("creditCardType", () => { ["637568", "hiper"], ["63737423", "hiper"], ["63743358", "hiper"], + + ["60000", "rupay"], + ["6073830123456789", "rupay"], + ["8273830123456789", "rupay"], ])("Matches %s to brand %s", (number, cardType) => { const actual = creditCardType(number); @@ -176,15 +180,19 @@ describe("creditCardType", () => { "mir", "hiper", "hipercard", + "rupay", ], ], ["2", ["mastercard", "jcb", "mir"]], ["3", ["american-express", "diners-club", "jcb"]], - ["5", ["mastercard", "maestro", "elo"]], - ["50", ["maestro", "elo"]], - ["6", ["discover", "unionpay", "maestro", "elo", "hiper", "hipercard"]], - ["60", ["discover", "maestro", "hipercard"]], - ["601", ["discover", "maestro"]], + ["5", ["mastercard", "maestro", "elo", "rupay"]], + ["50", ["maestro", "elo", "rupay"]], + [ + "6", + ["discover", "unionpay", "maestro", "elo", "hiper", "hipercard", "rupay"], + ], + ["60", ["discover", "maestro", "hipercard", "rupay"]], + ["601", ["discover", "maestro", "rupay"]], ["64", ["discover", "maestro"]], ["62", ["unionpay", "maestro", "elo"]], @@ -211,17 +219,21 @@ describe("creditCardType", () => { ["637374", ["maestro", "hiper"]], ["637433", ["maestro", "hiper"]], - ["606", ["maestro", "hipercard"]], + ["606", ["maestro", "hipercard", "rupay"]], ["627", ["unionpay", "maestro", "elo"]], - ["6062", ["maestro", "hipercard"]], + ["6062", ["maestro", "hipercard", "rupay"]], ["6370", ["maestro", "hiper"]], ["6376", ["maestro", "hiper"]], ["6375", ["maestro", "hiper"]], - ["65", ["discover", "maestro", "elo"]], - ["655", ["discover", "maestro", "elo"]], - ["6550", ["discover", "maestro", "elo"]], - ["65502", ["discover", "maestro", "elo"]], + ["65", ["discover", "maestro", "elo", "rupay"]], + ["655", ["discover", "maestro", "elo", "rupay"]], + ["6550", ["discover", "maestro", "elo", "rupay"]], + ["65502", ["discover", "maestro", "elo", "rupay"]], + + ["508", ["maestro", "rupay"]], + ["6085", ["rupay"]], + ["8199", ["rupay"]], ])("Matches %s to array %p", (number, expectedNames) => { const actualNames = creditCardType(number).map((cardType) => cardType.type); @@ -259,6 +271,7 @@ describe("creditCardType", () => { ["UnionPay", "6220558812340000", { size: 3, name: "CVN" }], ["Maestro", "6304000000000000", { size: 3, name: "CVC" }], ["Mir", "2200000000000000", { size: 3, name: "CVP2" }], + ["Rupay", "6073830123456789", { size: 3, name: "CVV" }], ])("returns security codes for %s", (brand, number, code) => { const parsedCode = creditCardType(number)[0].code; diff --git a/src/index.ts b/src/index.ts index 8b182033..32ffb702 100644 --- a/src/index.ts +++ b/src/index.ts @@ -24,6 +24,7 @@ const cardNames: Record = { MIR: "mir", HIPER: "hiper", HIPERCARD: "hipercard", + RUPAY: "rupay", }; const ORIGINAL_TEST_ORDER = [ @@ -39,6 +40,7 @@ const ORIGINAL_TEST_ORDER = [ cardNames.MIR, cardNames.HIPER, cardNames.HIPERCARD, + cardNames.RUPAY, ]; let testOrder = clone(ORIGINAL_TEST_ORDER) as string[]; diff --git a/src/lib/card-types.ts b/src/lib/card-types.ts index 2064d429..36b01315 100644 --- a/src/lib/card-types.ts +++ b/src/lib/card-types.ts @@ -191,6 +191,17 @@ const cardTypes: CardCollection = { size: 3, }, } as BuiltInCreditCardType, + rupay: { + niceType: "Rupay", + type: "rupay", + patterns: [60, 65, 81, 82, 508], + gaps: [4, 8, 12], + lengths: [16], + code: { + name: "CVV", + size: 3, + }, + } as BuiltInCreditCardType, }; export = cardTypes; diff --git a/src/types.ts b/src/types.ts index 698e3ed0..466ff048 100644 --- a/src/types.ts +++ b/src/types.ts @@ -10,7 +10,8 @@ export type CreditCardTypeCardBrandId = | "mastercard" | "mir" | "unionpay" - | "visa"; + | "visa" + | "rupay"; type CreditCardTypeCardBrandNiceType = | "American Express" @@ -24,7 +25,8 @@ type CreditCardTypeCardBrandNiceType = | "Mastercard" | "Mir" | "UnionPay" - | "Visa"; + | "Visa" + | "Rupay"; type CreditCardTypeSecurityCodeLabel = | "CVV" From 3a5ef0d4343c2bb4599a480fb0a425dd0e97924e Mon Sep 17 00:00:00 2001 From: kapilraghuwanshi Date: Sun, 28 Aug 2022 13:27:40 +0530 Subject: [PATCH 2/2] Upated README file --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 481d7fcc..9591b908 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ Named variables are provided for each of the supported card types: - `MIR` - `UNIONPAY` - `VISA` +- `RUPAY` #### `code` @@ -82,6 +83,7 @@ Card brands provide different nomenclature for their security codes as well as v | `Elo` | `CVE` | 3 | | `Hiper` | `CVC` | 3 | | `Hipercard` | `CVC` | 4 | +| `Rupay ` | `CVV` | 3 | A full response for a `Visa` card will look like this: @@ -190,6 +192,7 @@ Adding new cards puts them at the bottom of the priority for testing. Priority i creditCardType.types.MIR, creditCardType.types.HIPER, creditCardType.types.HIPERCARD, + creditCardType.types.RUPAY, ]; ```