byrokrat/autogiro
Composer 安装命令:
composer require byrokrat/autogiro
包简介
Read and write files for the swedish direct debit system autogirot
关键字:
README 文档
README
Autogiro
Read and write files for the swedish direct debit system autogirot.
For a command line utility that can convert autogiro files to XML see
autogiro2xml.
Installation
composer require byrokrat/autogiro
Table of contents
- Autogiro specifications
- Generating autogiro request files
- Parsing autogiro files
- Accessing nodes using visitors
- Generating XML from node trees
- Hacking
Autogiro specifications
This library is developed against the technichal manual (in swedish) of the direct debit system (autogirot) revised 2016-12-13. For later versions of this document see Bankgirocentralen.
Generating autogiro request files
Create a writer by supplying your bankgiro account number and
BGC customer number to WriterFactory.
$writer = (new \byrokrat\autogiro\Writer\WriterFactory)->createWriter( '123456', (new \byrokrat\banking\BankgiroFactory)->createAccount('1111-1119') );
Perform actions on the writer and generate file.
$writer->deleteMandate('1234567890'); $rawFile = $writer->getContent(); echo $rawFile;
Will output something like:
0120180114AUTOGIRO 1234560011111119
0300111111190000001234567890
Parsing autogiro files
Create a parser using the ParserFactory.
$factory = new \byrokrat\autogiro\Parser\ParserFactory; $parser = $factory->createParser();
The created parser will by default parse and validate monetary amounts, account numbers and identification numbers. Opt out of this functionality by using one of the visitor constants:
$factory->createParser(\byrokrat\autogiro\Parser\ParserFactory::VISITOR_IGNORE_OBJECTS);
Parsing a file creates a node object.
use byrokrat\autogiro\Tree\Node; /** @var Node */ $node = $parser->parse($rawFile);
Accessing special objects
Account, Amount, StateId and Date nodes are nested structures, where child
node Object contains constructed php objects. Access using something like:
$money = $node->getChild(Node::AMOUNT)->getObjectValue();
Walking the parse tree
A simpler way of doing this is by using visitors. See below.
Walk the tree by calling hasChild(), getChild() and getChildren().
echo $node->getChild(Node::MANDATE_REQUEST_SECTION) ->getChild(Node::DELETE_MANDATE_REQUEST) ->getChild(Node::PAYER_NUMBER) ->getValue();
Or access all Node::DELETE_MANDATE_REQUEST nodes.
$mandateRequests = $node->getChild(Node::MANDATE_REQUEST_SECTION); foreach ($mandateRequests->getChildren(Node::DELETE_MANDATE_REQUEST) as $deleteRequest) { // process... }
Trying to access a child that does not exist returns a NullNode.
echo $node->getChild('this-does-not-exist') ->getChild('and-neither-does-this') ->isNull();
Accessing nodes using visitors
With the use of visitors nodes can be accessed based on name or type.
class MyVisitor extends \byrokrat\autogiro\Visitor\Visitor { function beforeDeleteMandateRequest($node) { echo "Delete mandate request found!"; } } $visitor = new MyVisitor; $node->accept($visitor);
This can also be done dynamically.
$visitor = new \byrokrat\autogiro\Visitor\Visitor; $visitor->before(Node::DELETE_MANDATE_REQUEST, function ($node) { echo "Delete mandate request found!"; });
Finding mandate responses
$visitor->before(Node::MANDATE_RESPONSE, function ($node) { if ($node->hasChild(Node::CREATED_FLAG)) { // Mandate successfully created } if ($node->hasChild(Node::DELETED_FLAG)) { // Mandate successfully deleted } if ($node->hasChild(Node::ERROR_FLAG)) { // Mandate error state } });
Finding payment responses
$visitor->before(Node::SUCCESSFUL_INCOMING_PAYMENT_RESPONSE, function ($node) { // successfull payment.. }); $visitor->before(Node::FAILED_INCOMING_PAYMENT_RESPONSE, function ($node) { // failed payment.. });
Generating XML from node trees
Using this feature can be very helpful to understand how the parser interprets various layouts.
$xmlWriter = (new \byrokrat\autogiro\Xml\XmlWriterFactory)->createXmlWriter(); echo $xmlWriter->asXml( $parser->parse($rawFile) );
Hacking
With composer installed as composer
make
Or use something like
make COMPOSER_CMD=./composer.phar
byrokrat/autogiro 适用场景与选型建议
byrokrat/autogiro 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34.81k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2016 年 05 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「autogiro」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 byrokrat/autogiro 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 byrokrat/autogiro 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 byrokrat/autogiro 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 34.81k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 5
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2016-05-04