PHPackages                             byrokrat/autogiro - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. byrokrat/autogiro

ActiveLibrary[File &amp; Storage](/categories/file-storage)

byrokrat/autogiro
=================

Read and write files for the swedish direct debit system autogirot

1.1.0(5y ago)1233.6k↓12.5%82GPL-3.0-or-laterPHPPHP ^7.3 || ^8.0

Since Dec 13Pushed 5y ago1 watchersCompare

[ Source](https://github.com/byrokrat/autogiro)[ Packagist](https://packagist.org/packages/byrokrat/autogiro)[ Docs](https://github.com/byrokrat/autogiro)[ RSS](/packages/byrokrat-autogiro/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (14)Used By (2)

[![byrokrat](res/logo.svg)](res/logo.svg)

Autogiro
========

[](#autogiro)

[![Packagist Version](https://camo.githubusercontent.com/1a88a5bbad52c0040b402489f7da20d15e1c0fa4b42c766e6a75f8e13d9b3065/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6279726f6b7261742f6175746f6769726f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/byrokrat/autogiro)[![Build Status](https://camo.githubusercontent.com/f001fd28a969ae17f38e57a42391a185beee8efe2ee16158bd670c89066c592a/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6279726f6b7261742f6175746f6769726f2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.com/github/byrokrat/autogiro)[![Quality Score](https://camo.githubusercontent.com/b309945181a9a75f70d7fd481c98d7b16d2bd596364112413079195c059f4da1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6279726f6b7261742f6175746f6769726f2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/byrokrat/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`](https://github.com/byrokrat/autogiro2xml).

Installation
------------

[](#installation)

```
composer require byrokrat/autogiro
```

Table of contents
-----------------

[](#table-of-contents)

1. [Autogiro specifications](#autogiro-specifications)
2. [Generating autogiro request files](#generating-autogiro-request-files)
3. [Parsing autogiro files](#parsing-autogiro-files)
4. [Accessing nodes using visitors](#accessing-nodes-using-visitors)
5. [Generating XML from node trees](#generating-xml-from-node-trees)
6. [Hacking](#hacking)

Autogiro specifications
-----------------------

[](#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](http://bgc.se).

Generating autogiro request files
---------------------------------

[](#generating-autogiro-request-files)

Create a writer by supplying your *bankgiro account number* and *BGC customer number* to [`WriterFactory`](/src/Writer/WriterFactory.php).

```
$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
----------------------

[](#parsing-autogiro-files)

Create a parser using the [`ParserFactory`](/src/Parser/ParserFactory.php).

```
$factory = new \byrokrat\autogiro\Parser\ParserFactory;
$parser = $factory->createParser();
```

The created parser will by default parse and validate [monetary amounts](https://github.com/moneyphp/money), [account numbers](https://github.com/byrokrat/banking) and [identification numbers](https://github.com/byrokrat/id). 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

[](#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

[](#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
------------------------------

[](#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

[](#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

[](#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
------------------------------

[](#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
-------

[](#hacking)

With [composer](https://getcomposer.org/) installed as `composer`

```
make
```

Or use something like

```
make COMPOSER_CMD=./composer.phar
```

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~92 days

Recently: every ~172 days

Total

13

Last Release

1970d ago

PHP version history (3 changes)1.0.0-alpha1PHP ^7.0

1.0.0-alpha2PHP &gt;=7.1

1.1.0PHP ^7.3 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b0af6567c7f4f5518a422192675445464fdcf18acbc9459b3205da9fd446f8d0?d=identicon)[hanneskod](/maintainers/hanneskod)

---

Top Contributors

[![hanneskod](https://avatars.githubusercontent.com/u/1369274?v=4)](https://github.com/hanneskod "hanneskod (174 commits)")

---

Tags

autogirobankingautogiro

### Embed Badge

![Health badge](/badges/byrokrat-autogiro/health.svg)

```
[![Health](https://phpackages.com/badges/byrokrat-autogiro/health.svg)](https://phpackages.com/packages/byrokrat-autogiro)
```

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15161.6M2.6k](/packages/illuminate-filesystem)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)[madnest/madzipper

Easier zip file handling for Laravel applications.

1382.3M6](/packages/madnest-madzipper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
