Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Expand payment card types enum to recognise Maestro card #58

Open
wants to merge 2 commits into
base: master
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,35 @@ @implementation PTKCardNumberTest

- (void)testCardType
{
// Amex card detection
XCTAssertEqual([CNUMBER(@"378282246310005") cardType], PTKCardTypeAmex, @"Detects Amex");
XCTAssertEqual([CNUMBER(@"371449635398431") cardType], PTKCardTypeAmex, @"Detects Amex");

// Diners club detection
XCTAssertEqual([CNUMBER(@"30569309025904") cardType], PTKCardTypeDinersClub, @"Detects Diners Club");

// Discover card detection
XCTAssertEqual([CNUMBER(@"6011111111111117") cardType], PTKCardTypeDiscover, @"Detects Discover");
XCTAssertEqual([CNUMBER(@"6011000990139424") cardType], PTKCardTypeDiscover, @"Detects Discover");
XCTAssertEqual([CNUMBER(@"6441234567890123") cardType], PTKCardTypeDiscover, @"Detects Discover");
XCTAssertEqual([CNUMBER(@"6481234567890123") cardType], PTKCardTypeDiscover, @"Detects Discover");
XCTAssertEqual([CNUMBER(@"6491234567890123") cardType], PTKCardTypeDiscover, @"Detects Discover");

// JCB detection
XCTAssertEqual([CNUMBER(@"3530111333300000") cardType], PTKCardTypeJCB, @"Detects JCB");

// MasterCard detection
XCTAssertEqual([CNUMBER(@"5555555555554444") cardType], PTKCardTypeMasterCard, @"Detects MasterCard");

// Visa detection
XCTAssertEqual([CNUMBER(@"4111111111111111") cardType], PTKCardTypeVisa, @"Detects Visa");
XCTAssertEqual([CNUMBER(@"4012888888881881") cardType], PTKCardTypeVisa, @"Detects Visa");

// Maestro card detection
XCTAssertEqual([CNUMBER(@"5012345678901234") cardType], PTKCardTypeMaestro, @"Detects Maestro");
XCTAssertEqual([CNUMBER(@"6759649826438453") cardType], PTKCardTypeMaestro, @"Detects Maestro");
XCTAssertEqual([CNUMBER(@"5659649826438453") cardType], PTKCardTypeMaestro, @"Detects Maestro");
XCTAssertEqual([CNUMBER(@"6959649826438453") cardType], PTKCardTypeMaestro, @"Detects Maestro");
}

- (void)testLast4
Expand Down
4 changes: 3 additions & 1 deletion PaymentKit/PTKCardNumber.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ - (PTKCardType)cardType

if (range >= 40 && range <= 49) {
return PTKCardTypeVisa;
} else if (range >= 50 && range <= 59) {
} else if (range >= 51 && range <= 55) {
return PTKCardTypeMasterCard;
} else if (range == 34 || range == 37) {
return PTKCardTypeAmex;
Expand All @@ -51,6 +51,8 @@ - (PTKCardType)cardType
return PTKCardTypeJCB;
} else if (range == 30 || range == 36 || range == 38 || range == 39) {
return PTKCardTypeDinersClub;
} else if (range == 50 || (range >= 56 && range <= 69)) {
return PTKCardTypeMaestro;
} else {
return PTKCardTypeUnknown;
}
Expand Down
3 changes: 2 additions & 1 deletion PaymentKit/PTKCardType.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ typedef enum {
PTKCardTypeDiscover,
PTKCardTypeJCB,
PTKCardTypeDinersClub,
PTKCardTypeUnknown
PTKCardTypeMaestro,
PTKCardTypeUnknown,
} PTKCardType;

#endif