Skip to content
Open
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Require the package in `composer.json`

```json
"require": {
"inacho/php-credit-card-validator": "1.*"
"habil/php-credit-card-validator": "1.*"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably stay inacho since it's referring to this repo.

},
```

Expand All @@ -24,7 +24,7 @@ If you are using Laravel, add an alias in `config/app.php`
...
'View' => 'Illuminate\Support\Facades\View',

'CreditCard' => 'Inacho\CreditCard',
'CreditCard' => 'Sivax\CreditCard',

),
```
Expand Down Expand Up @@ -98,3 +98,6 @@ bool(false)
Execute the following command to run the unit tests:

vendor/bin/phpunit

### Disclaimer
Many thanks to [inacho](https://github.com/inacho "inacho"). This repository based on it's [PHP Credit Card Validator](https://github.com/inacho/php-credit-card-validator "PHP Credit Card Validator") repository.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "inacho/php-credit-card-validator",
"name": "habil/php-credit-card-validator",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should stay "inacho".

"type": "library",
"description": "Validates popular debit and credit cards numbers against regular expressions and Luhn algorithm. Also validates the CVC and the expiration date",
"keywords": ["creditcard", "creditcards", "debit", "credit", "card", "cards", "validator", "cvc", "laravel"],
Expand All @@ -20,7 +20,7 @@
},
"autoload": {
"psr-4": {
"Inacho\\": "src/"
"Sivax\\": "src/"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should stay "Inacho".

}
}
}
61 changes: 31 additions & 30 deletions src/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
* @copyright 2014 Ignacio de Tomás (http://inacho.es)
*/

namespace Inacho;
namespace Sivax;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong namespace


/**
* Class CreditCard
* @package Inacho
* @package Sivax
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong package name

*/
class CreditCard
{
Expand Down Expand Up @@ -124,7 +124,7 @@ class CreditCard
);

/**
* @param string $number
* @param string $number
* @param null $type
*
* @return array
Expand Down Expand Up @@ -162,8 +162,8 @@ public static function validCreditCard($number, $type = null)
}

/**
* @param string $cvc
* @param string $type
* @param string $cvc
* @param string $type
*
* @return bool
*/
Expand All @@ -173,20 +173,20 @@ public static function validCvc($cvc, $type)
}

/**
* @param int $year
* @param int $month
* @param int $year
* @param int $month
*
* @return bool
*/
public static function validDate($year, $month)
{
$month = str_pad($month, 2, '0', STR_PAD_LEFT);

if (! preg_match('/^20\d\d$/', $year)) {
if (!preg_match('/^20\d\d$/', $year)) {
return false;
}

if (! preg_match('/^(0[1-9]|1[0-2])$/', $month)) {
if (!preg_match('/^(0[1-9]|1[0-2])$/', $month)) {
return false;
}

Expand All @@ -199,9 +199,9 @@ public static function validDate($year, $month)
}

/**
* @param string $number
* @param string $number
*
* @return int|string
* @return string
*/
protected static function creditCardType($number)
{
Expand All @@ -215,7 +215,7 @@ protected static function creditCardType($number)
}

/**
* @param string $bin
* @param string $bin
*
* @return string|null
*/
Expand All @@ -227,19 +227,20 @@ public static function determineCreditCardType($bin)
}

/**
* @param string $number
* @param string $type
* @param string $number
* @param string $type
*
* @return bool
*/
protected static function validCard($number, $type)
{
return (self::validPattern($number, $type) && self::validLength($number, $type) && self::validLuhn($number, $type));
return (self::validPattern($number, $type) && self::validLength($number, $type) && self::validLuhn($number,
$type));
}

/**
* @param string $number
* @param string $type
* @param string $number
* @param string $type
*
* @return false|int
*/
Expand All @@ -249,8 +250,8 @@ protected static function validPattern($number, $type)
}

/**
* @param string $number
* @param string $type
* @param string $number
* @param string $type
*
* @return bool
*/
Expand All @@ -266,8 +267,8 @@ protected static function validLength($number, $type)
}

/**
* @param string $cvc
* @param string $type
* @param string $cvc
* @param string $type
*
* @return bool
*/
Expand All @@ -283,39 +284,39 @@ protected static function validCvcLength($cvc, $type)
}

/**
* @param string $number
* @param string $type
* @param string $number
* @param string $type
*
* @return bool
*/
protected static function validLuhn($number, $type)
{
if (! self::$cards[$type]['luhn']) {
if (!self::$cards[$type]['luhn']) {
return true;
} else {
return self::luhnCheck($number);
}
}

/**
* @param string $number
* @param string $number
*
* @return bool
*/
protected static function luhnCheck($number)
{
$checksum = 0;
for ($i=(2-(strlen($number) % 2)); $i<=strlen($number); $i+=2) {
$checksum += (int) ($number{$i-1});
for ($i = (2 - (strlen($number) % 2)); $i <= strlen($number); $i += 2) {
$checksum += (int) ($number{$i - 1});
}

// Analyze odd digits in even length strings or even digits in odd length strings.
for ($i=(strlen($number)% 2) + 1; $i<strlen($number); $i+=2) {
$digit = (int) ($number{$i-1}) * 2;
for ($i = (strlen($number) % 2) + 1; $i < strlen($number); $i += 2) {
$digit = (int) ($number{$i - 1}) * 2;
if ($digit < 10) {
$checksum += $digit;
} else {
$checksum += ($digit-9);
$checksum += ($digit - 9);
}
}

Expand Down