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

CreditCardValidator. Added MIR cards support #100

Open
wants to merge 1 commit 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 @@ -199,6 +199,10 @@ public CreditCardRange(final String low, final String high, final int [] lengths
@Deprecated
public static final long MASTERCARD_PRE_OCT2016 = 1 << 6; // CHECKSTYLE IGNORE MagicNumber

/**
* Option specifying that MIR cards are allowed
*/
public static final long MIR = 1 << 7;

/**
* The CreditCardTypes that are allowed to pass validation.
Expand Down Expand Up @@ -282,6 +286,7 @@ public CreditCardRange(final String low, final String high, final int [] lengths
*/
public static final CodeValidator VPAY_VALIDATOR = new CodeValidator("^(4)(\\d{12,18})$", LUHN_VALIDATOR);

public static final CodeValidator MIR_VALIDATOR = new CodeValidator("^(220\\d{13})$", LUHN_VALIDATOR);
/**
* Create a new CreditCardValidator with default options.
* The default options are:
Expand Down Expand Up @@ -325,6 +330,10 @@ public CreditCardValidator(final long options) {
if (isOn(options, DINERS)) {
this.cardTypes.add(DINERS_VALIDATOR);
}

if (isOn(options, MIR)) {
this.cardTypes.add(MIR_VALIDATOR);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class CreditCardValidatorTest extends TestCase {
private static final String VALID_VPAY = "4370000000000061"; // 16
private static final String VALID_VPAY2 = "4370000000000012";
private static final String ERROR_VPAY = "4370000000000069";
private static final String VALID_MIR = "2203368778544108";
private static final String ERROR_MIR = "2203368778544107";

private static final String [] VALID_CARDS = {
VALID_VISA,
Expand All @@ -55,6 +57,7 @@ public class CreditCardValidatorTest extends TestCase {
VALID_VPAY,
VALID_VPAY2,
"60115564485789458", // VALIDATOR-403
VALID_MIR
};

private static final String [] ERROR_CARDS = {
Expand All @@ -71,6 +74,7 @@ public class CreditCardValidatorTest extends TestCase {
"12345678901", // too short (11)
"12345678901234567890", // too long (20)
"4417123456789112", // invalid check digit
ERROR_MIR
};

/**
Expand Down Expand Up @@ -588,6 +592,7 @@ public void testRangeGenerator() {
CreditCardValidator.VISA_VALIDATOR,
CreditCardValidator.MASTERCARD_VALIDATOR,
CreditCardValidator.DISCOVER_VALIDATOR,
CreditCardValidator.MIR_VALIDATOR
},
// Add missing validator
new CreditCardRange[]{
Expand Down