Skip to content

Commit b2ebfbd

Browse files
committed
Merge pull request #16 from lucasmichot/ccn-type-check
Ensure short number cannot be considered as valid credit card number
2 parents cf674c7 + cc6d284 commit b2ebfbd

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Omnipay/Common/CreditCard.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ public function validate()
248248
if (!Helper::validateLuhn($this->getNumber())) {
249249
throw new InvalidCreditCardException('Card number is invalid');
250250
}
251+
252+
if (!is_null($this->getNumber()) && !preg_match('/^\d{12,19}$/i', $this->getNumber())) {
253+
throw new InvalidCreditCardException('Card number should have 12 to 19 digits');
254+
}
251255
}
252256

253257
/**

tests/Omnipay/Common/CreditCardTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,4 +589,13 @@ public function testGender()
589589
$this->card->setGender('female');
590590
$this->assertEquals('female', $this->card->getGender());
591591
}
592+
593+
/**
594+
* @expectedException Omnipay\Common\Exception\InvalidCreditCardException
595+
*/
596+
public function testInvalidShortCard()
597+
{
598+
$this->card->setNumber('43');
599+
$this->card->validate();
600+
}
592601
}

0 commit comments

Comments
 (0)