Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Rupay card support, updated configs, added test cases #145

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Named variables are provided for each of the supported card types:
- `MIR`
- `UNIONPAY`
- `VISA`
- `RUPAY`

#### `code`

Expand All @@ -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:

Expand Down Expand Up @@ -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,
];
```

Expand Down
37 changes: 25 additions & 12 deletions src/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe("creditCardType", () => {
["6221558812340000", "unionpay"],
["6269992058134322", "unionpay"],
["622018111111111111", "unionpay"],
["8", "unionpay"],
["8110", "unionpay"],
["8100513433325374", "unionpay"],
["8111700872004845", "unionpay"],
["8141618644273338", "unionpay"],
Expand All @@ -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);

Expand Down Expand Up @@ -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"]],

Expand All @@ -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);

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const cardNames: Record<string, CreditCardTypeCardBrandId> = {
MIR: "mir",
HIPER: "hiper",
HIPERCARD: "hipercard",
RUPAY: "rupay",
};

const ORIGINAL_TEST_ORDER = [
Expand All @@ -39,6 +40,7 @@ const ORIGINAL_TEST_ORDER = [
cardNames.MIR,
cardNames.HIPER,
cardNames.HIPERCARD,
cardNames.RUPAY,
];

let testOrder = clone(ORIGINAL_TEST_ORDER) as string[];
Expand Down
11 changes: 11 additions & 0 deletions src/lib/card-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 4 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export type CreditCardTypeCardBrandId =
| "mastercard"
| "mir"
| "unionpay"
| "visa";
| "visa"
| "rupay";

type CreditCardTypeCardBrandNiceType =
| "American Express"
Expand All @@ -24,7 +25,8 @@ type CreditCardTypeCardBrandNiceType =
| "Mastercard"
| "Mir"
| "UnionPay"
| "Visa";
| "Visa"
| "Rupay";

type CreditCardTypeSecurityCodeLabel =
| "CVV"
Expand Down