61 lines
1.9 KiB
PHP
61 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
class TestCardRule implements ValidationRule
|
|
{
|
|
private $testCards = [
|
|
'4111111111111111',
|
|
'4242424242424242',
|
|
'5555555555554444',
|
|
'5105105105105100',
|
|
'378282246310005',
|
|
'371449635398431',
|
|
'6011111111111117',
|
|
'6011000990139424',
|
|
'30569309025904',
|
|
'38520000023237',
|
|
'3566002020360505',
|
|
'6200000000000005',
|
|
'6759649826438453',
|
|
'1234567890123456', // Generic test number
|
|
'2223003122003222', // Mastercard 2-series test number
|
|
'2223520043560014',
|
|
'5019717010103742', // Dankort (PBS)
|
|
'4000056655665556', // Visa (debit)
|
|
'5200828282828210', // Mastercard (debit)
|
|
'6011000990139424', // Discover
|
|
'3566002020360505', // JCB
|
|
'6200000000000005', // UnionPay
|
|
'6759649826438453', // Maestro
|
|
'6304000000000000', // Laser
|
|
'6304981111111111',
|
|
'2223000048400011', // Mastercard
|
|
'2223520043560014',
|
|
'4000000000003220', // Visa (all zeros with valid check digit)
|
|
'4111111111111111', // Visa (all ones)
|
|
'4012888888881881', // Visa
|
|
'4222222222222', // Visa (13 digit)
|
|
'5500000000000004', // Mastercard (odd length)
|
|
'5555555555554444', // Mastercard (even length)
|
|
'378282246310005', // American Express
|
|
'371449635398431',
|
|
'6011111111111117', // Discover
|
|
'3530111333300000', // JCB
|
|
'6304000000000000', // Maestro
|
|
];
|
|
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
// Remove any non-digit characters
|
|
$cardNumber = preg_replace('/\D/', '', $value);
|
|
|
|
if (in_array($cardNumber, $this->testCards)) {
|
|
$fail('Test cards are not allowed for real transactions.');
|
|
}
|
|
}
|
|
}
|