Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Added a new type of Russian bank card - "MIR". #203

Merged
merged 3 commits into from
Feb 1, 2018
Merged
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
1 change: 1 addition & 0 deletions doc/book/validators/credit-card.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The following issuing institutes are accepted:
- Solo
- Visa
- Visa Electron
- Russia Mir

> ### Invalid institutes
>
Expand Down
4 changes: 4 additions & 0 deletions src/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class CreditCard extends AbstractValidator
const MASTERCARD = 'Mastercard';
const SOLO = 'Solo';
const VISA = 'Visa';
const MIR = 'Mir';

const CHECKSUM = 'creditcardChecksum';
const CONTENT = 'creditcardContent';
Expand Down Expand Up @@ -72,6 +73,7 @@ class CreditCard extends AbstractValidator
8 => self::SOLO,
9 => self::UNIONPAY,
10 => self::VISA,
11 => self::MIR,
];

/**
Expand All @@ -91,6 +93,7 @@ class CreditCard extends AbstractValidator
self::SOLO => [16, 18, 19],
self::UNIONPAY => [16, 17, 18, 19],
self::VISA => [13, 16, 19],
self::MIR => [13, 16],
];

/**
Expand Down Expand Up @@ -122,6 +125,7 @@ class CreditCard extends AbstractValidator
'6224', '6225', '6226', '6227', '6228', '62290', '62291',
'622920', '622921', '622922', '622923', '622924', '622925'],
self::VISA => ['4'],
self::MIR => ['2200', '2201', '2202', '2203', '2204'],
];

/**
Expand Down
41 changes: 40 additions & 1 deletion test/CreditCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testGetMessages()
public function testGetSetType()
{
$validator = new CreditCard();
$this->assertEquals(11, count($validator->getType()));
$this->assertEquals(12, count($validator->getType()));

$validator->setType(CreditCard::MAESTRO);
$this->assertEquals([CreditCard::MAESTRO], $validator->getType());
Expand Down Expand Up @@ -253,6 +253,45 @@ public function testMastercardCard($input, $expected)
$this->assertEquals($expected, $validator->isValid($input));
}

/**
* Data provider
*
* @return string[][]|bool[][]
*/
public function mirValues()
{
return [
['3011111111111000', false],
['2031343323344731', false],
['2200312032822721', true],
['2209993834549400', false],
['2204001882200999', true],
['2202000312124573', true],
['2203921957923012', true],
['2204150479254495', true],
['2201123406612104', true],
['2900008996056', false],
['2201969950494', true],
['2201342387927', true],
['2205969950494', false],
];
}

/**
* Test mir card number validity
*
* @dataProvider mirValues
*
* @param string $input
* @param bool $expected
*/
public function testMirCard($input, $expected)
{
$validator = new CreditCard(['type' => CreditCard::MIR]);

$this->assertEquals($expected, $validator->isValid($input));
}

/**
* Test an invalid service class
*
Expand Down