byrokrat/banking
Composer 安装命令:
composer require byrokrat/banking
包简介
Data types for accounts in the swedish banking system
README 文档
README
Banking
Data types and factories for bank accounts in the swedish banking system, Handelsbanken, ICA-banken, Nordea, SEB, Skandiabanken, Swedbank, PlusGirot, Bankgirot among others.
Introduction
Banking provides a way of parsing and validating bank account numbers from the swedish banking system. It validates clearing numbers, the structure of the account number as well as check digits. It also defines value objects for account numbers, with formatting capabilities and methods for accessing the different parts of the account number and to identify the bank the number belongs to.
Installation
composer require byrokrat/banking
Banking has no user land dependencies.
Usage
The main entry point is the AccountFactory that is used to create AccountNumber objects.
$accountFactory = new \byrokrat\banking\AccountFactory; $account = $accountFactory->createAccount('50001111116'); // Prints a formatted version of the validated number (5000,111111-6) echo $account->getNumber();
The standard factory does its best to recognize different number formats.
- Spaces, hyphens and dots are ignored.
- An optional
,delimiter between clearing and serial numbers may be used. - Misplaced clearing-serial delimiters are ignored.
The following account numbers are all valid and considered equal to the account number of the previous example.
// 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);
Making the factory stricter
For a factory that only allows digits and correctly placed clearing-serial
delimiters (,) pass an instance of StrictFactory as the first argument to
AccountFactory::__construct().
$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');
Rewrites
When parsing an account number fails the standard factory attempts rewriting it to see if a valid account number can be produced.
- It tries to interpret the first digit of the serial number as a clearing check digit.
- It tries to trim left side ceros from the serial number.
- It tries to prepend the clearing number
3300to see if the account number is a valid Nordea personal account number.
If any of the rewrites (or any combination of rewrites) is successful the rewritten
number is used. Opt out of this behaviour by passing an empty RewriterContainer
as the second argument to AccountFactory::__construct().
$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');
Clearing number check digits for Swedbank accounts
Swedbank account numbers with clearing numbers starting with 8 may specify a
fifth clearing number check digit. The clearing number check digit is optional,
but if present the parser will use it to validate the clearing number.
$swedbank = $accountFactory->createAccount('8105-9,744202466'); echo $accountFactory->createAccount('81059,744202466')->equals($swedbank);
Please note that if the clearing check digit is
0and no comma (,) is used to separate the clearing and serial numbers the parser may not understand that the0is part of the clearing number, resulting in data loss. For this reason it is a good habit to always use a comma to separate the clearing and serial numbers.
Catching parser errors
When parsing fails an exception is thrown. Inspect the exception message for an in-depth description of the parser stages and where the error occurred.
try { $accountFactory->createAccount('8105-8,744202464'); } catch (\byrokrat\banking\Exception $e) { echo $e->getMessage(); }
Outputs something like:
Unable to parse account 8105-8,744202464 using format Swedbank:
* Clearing number 8105 is within range 8000 to 8999
* [FAIL] Invalid check digit 4, expected 6
* [FAIL] Invalid clearing number check digit 8, expected 9
* Valid serial length 8
Parsing Bankgiro and PlusGiro accounts
Use BankgiroFactory or PlusgiroFactory to parse bankgiro and plusgiro
account numbers. (As of version 2.0 it is no longer possible to parse bankgiro
or plusgiro account numbers using the regular AccountFactory.)
Note that the
-delimiter is optional when parsing Bankgiro and PlusGiro account numbers. When omitted it may not be possible determine if the raw number is indeed a Bankgiro or PlusGiro account number:5805-6201is a valid Bankgiro number and5805620-1is a valid PlusGiro number.
$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;
Creating a factory that can parse both regular accounts and bankgiro or plusgiro accounts
Use DelegatingFactory the create a factory that incorporates the functionality
of one or more factories in a single object.
$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;
The AccountNumber API
Created account objects implement the AccountNumber interface, which defines the following api.
getBankName()
Gets the name of the bank a number belongs to (for a list of bank identifiers see BankNames).
echo $account->getBankName(); echo $account->getBankName() == \byrokrat\banking\BankNames::BANK_SEB;
getRawNumber()
Gets the raw and unformatted number.
echo $account->getRawNumber();
getNumber()
Gets a formatted permutation of account number. Using PHPs magical __tostring()
method calls getNumber() internaly.
echo $account->getNumber(); echo $account;
prettyprint()
Gets a formatted permutation of account number with more eye candy.
echo $account->prettyprint();
get16()
Gets the generic 16 digit format as defined by BGC.
echo $account->get16();
getClearingNumber(), getClearingCheckDigit(), getSerialNumber() and getCheckDigit()
Gets the extracted account number parts.
echo $account->getClearingNumber(); echo $account->getClearingCheckDigit(); echo $account->getSerialNumber(); echo $account->getCheckDigit();
equals()
Validates that two account objects represents the same number.
echo $account->equals($account);
byrokrat/banking 适用场景与选型建议
byrokrat/banking 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 97.67k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2015 年 02 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「plusgiro」 「bankgiro」 「seb」 「Nordea」 「Swedbank」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 byrokrat/banking 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 byrokrat/banking 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 byrokrat/banking 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP banklink library to easily integrate Baltic banklinks.
Laravel Package for generating encrypted SEB (Safe Exam Browser) client configurations
Wrappers for accessing Swedish banks. Currently supports Handelsbanken and SEB.
Encode PHP values as Safe Exam Browser SEB-JSON for Config Key generation.
EveryPay payment gateway for Sylius 2 - card and Baltic bank-link payments (SEB, LHV, Swedbank / LHV Paytech) via the hosted payment page.
Command line utility for linting swedish bureaucratic content
统计信息
- 总下载量: 97.67k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 26
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: Unlicense
- 更新时间: 2015-02-04