PHP code example of byrokrat / banking

1. Go to this page and download the library: Download byrokrat/banking 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/ */

    

byrokrat / banking example snippets


$accountFactory = new \byrokrat\banking\AccountFactory;
$account = $accountFactory->createAccount('50001111116');
// Prints a formatted version of the validated number (5000,111111-6)
echo $account->getNumber();

// Prints 111111
echo $accountFactory->createAccount('5000,1111116')->equals($account);
echo $accountFactory->createAccount('5000-1111116')->equals($account);
echo $accountFactory->createAccount('5000,111111-6')->equals($account);
echo $accountFactory->createAccount('5000,111 111-6')->equals($account);
echo $accountFactory->createAccount('5000000001111116')->equals($account);
echo $accountFactory->createAccount('5000,000001111116')->equals($account);

$accountFactory = new \byrokrat\banking\AccountFactory(new \byrokrat\banking\StrictFactory);

// Will throw an exception as '-' is not a valid character in strict mode
$accountFactory->createAccount('5000-1111116');

$accountFactory = new \byrokrat\banking\AccountFactory(
    new \byrokrat\banking\StrictFactory,
    new \byrokrat\banking\Rewriter\RewriterContainer
);

// Will throw an exception as the serial number is too long and can not be trimmed.
$accountFactory->createAccount('5000,01111116');

$swedbank = $accountFactory->createAccount('8105-9,744202466');
echo $accountFactory->createAccount('81059,744202466')->equals($swedbank);

try {
    $accountFactory->createAccount('8105-8,744202464');
} catch (\byrokrat\banking\Exception $e) {
    echo $e->getMessage();
}

$account = (new \byrokrat\banking\PlusgiroFactory)->createAccount('58056201');
echo $account->getBankName() == \byrokrat\banking\BankNames::BANK_PLUSGIRO;

$account = (new \byrokrat\banking\BankgiroFactory)->createAccount('58056201');
echo $account->getBankName() == \byrokrat\banking\BankNames::BANK_BANKGIRO;

$factory = new \byrokrat\banking\DelegatingFactory(
    new \byrokrat\banking\AccountFactory,
    new \byrokrat\banking\BankgiroFactory
);

$account = $factory->createAccount('58056201');
echo $account->getBankName() == \byrokrat\banking\BankNames::BANK_BANKGIRO;

echo $account->getBankName();
echo $account->getBankName() == \byrokrat\banking\BankNames::BANK_SEB;

echo $account->getRawNumber();

echo $account->getNumber();
echo $account;

echo $account->prettyprint();

echo $account->get16();

echo $account->getClearingNumber();
echo $account->getClearingCheckDigit();
echo $account->getSerialNumber();
echo $account->getCheckDigit();

echo $account->equals($account);