1. Go to this page and download the library: Download larium/credit-card library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
larium / credit-card example snippets
use Larium\CreditCard\CreditCard;
use Larium\CreditCard\CreditCardValidator;
=> date('Y') + 1,
'brand' => CreditCard::VISA,
'number' => '4532875311640795',
'cvv' => '123',
);
$card = new CreditCard($data);
echo $card->getBrand(); # visa
//Auto uppercase holder name.
echo $card->getHolderName(); # JOHN DOE
$card = $card->withNumber('5284911033259148');
echo $card->getBrand(); # master
use Larium\CreditCard\CreditCard;
use Larium\CreditCard\CreditCardValidator;
use Larium\CreditCard\Token;
nd' => CreditCard::VISA,
'number' => '4532875311640795',
'cvv' => '123',
);
$card = new CreditCard($data);
# ... use credit card to obtain a token reference from a remote payment gateway.
$token = new Token('0123456789');
$card = $card->withToken($token);
# Now, credit card will use token for future payments
# and will mask any sensitive data as number and cvv.
echo $card->getCvv(); # null
echo $card->getNumber(); # XXXX-XXXX-XXXX-0795
echo $card->getToken(); # 0123456789
use Larium\CreditCard\Token;
ew DateTime('15 minutes'));
$token->isExpired() # false
$token = new Token('0123456789', new DateTime('15 minutes ago'));
$token->isExpired() # true
use Larium\CreditCard\CreditCard;
use Larium\CreditCard\CreditCardValidator;
r' => date('Y') + 1,
'brand' => CreditCard::VISA,
'number' => '4532875311640795',
'cvv' => '123',
);
$card = new CreditCard($data);
$validator = new CreditCardValidator();
$errors = $validator->validate($card);
$valid = count($errors) === 0; # true
$card = $card->withNumber('1');
$error = $validator->validate($card);
print_r($errors);
/*
Array
(
[number] => not a valid number
[brand] => not valid card type
)
*/
use Larium\CreditCard\CreditCard;
use Larium\CreditCard\CreditCardValidator;
use Larium\CreditCard\Token;
reditCardValidator(CreditCardValidator::CONTEXT_TOKEN);
$errors = $validator->validate($card);
$valid = count($errors) === 0; # true
$token = new Token('0123456789', new DateTime('15 minutes ago'));
$card = $card->withToken($token);
$validator->setContext(CreditCardValidator::CONTEXT_TOKEN);
$validator->validate($card);
$validator->getErrors();
/*
Array
(
[token] => token has been expired
)
*/
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.