Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 0 additions & 111 deletions .docs/README.md

This file was deleted.

117 changes: 109 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,126 @@
Website 🚀 <a href="https://contributte.org">contributte.org</a> | Contact 👨🏻‍💻 <a href="https://f3l1x.io">f3l1x.io</a> | Twitter 🐦 <a href="https://twitter.com/contributte">@contributte</a>
</p>

## Usage
Fio Bank API integration for Nette applications. Configure your Fio accounts and send domestic payments through a simple payment service.

## Versions

| State | Version | Branch | PHP |
|-------------|---------|----------|----------|
| development | `^0.4` | `master` | `>= 7.1` |
| stable | `^0.3` | `master` | `>= 7.1` |

## Installation

To install latest version of `contributte/fio` use [Composer](https://getcomposer.org).

```bash
composer require contributte/fio
```

## Documentation
## Requirements

For details on how to use this package, check out our [documentation](.docs).
You need your bank account and token generated in your e-banking. There is no special token for testing, so you have to use the same token for both testing and production. It is recommended to generate two tokens per account: one for sending payments to the bank and one for downloading payments from the bank. This package currently includes only sending payments.

## Versions
- **accountNumber**
- **accountToken**

| State | Version | Branch | PHP |
|-------------|---------|----------|----------|
| development | `^0.4` | `master` | `>= 7.1` |
| stable | `^0.3` | `master` | `>= 7.1` |
## Configuration

```neon
extensions:
fio: Contributte\Fio\DI\Nette\FioApiExtension

fio:
accounts:
czk-write:
account: %fioapi.account1%
token: %fioapi.token1%
czk-read:
account: %fioapi.account2%
token: %fioapi.token2%
```

## Usage

As this package is under development we haven't included downloading payments from bank yet. You can use our package for simply sending domestic payments to bank. You can send multiple payments at once but you can query bank api only once in 30 seconds (if you ping servers in shorter intervals it will return error). This package only supports domestic transactions but it is very easy to implement other types of payments. You only need to extend `Contributte\Fio\Entity\Transaction\Transaction` class and use it same way as Domestic Transaction class which has these mandatory properties:

- Sender account (automatically supplied from config)
- Currency
- Amount
- Recipient account
- Bank code
- Date

For more properties check the class itself.

From `FioManager` you get `PaymentService` which has two methods:

- `addPayment(Transaction $t)` - adds and verifies transaction
- `sendPayments()` - sends added transaction to bank and returns PaymentResponse

```php
<?php

namespace App;

use Contributte\Fio\Entity\Transaction\DomesticTransaction;
use Contributte\Fio\Exceptions\InvalidResponseException;
use Contributte\Fio\FioManager;
use Tracy\Debugger;

final class SendPaymentsControl extends BaseControl
{

private $fioManager;

public function __construct(FioManager $fioManager)
{
parent::__construct();
$this->fioManager = $fioManager;
}

public function handleSend(): void
{
// You somehow get your payments
$paymentsToSend = $this->findPayments();

// Get our payment service with proper account name
$paymentService = $this->fioManager->createPaymentService('czk-write');

foreach ($paymentsToSend as $p) {
// Create transaction object and fill it with data
$transaction = new DomesticTransaction();
$transaction->setAccountTo($p[0]); // string
$transaction->setBankCode($p[1]); // string
$transaction->setVs($p[2]); // string
$transaction->setAmount($p[3]); // float
$transaction->setDate($p[4]); // DateTimeInterface
$transaction->setMessageForRecipient($p[5]); // string

$paymentService->addPayment($transaction);
}

try {
// Send payments to bank
$response = $paymentService->sendPayments();

} catch (InvalidResponseException $e) {
// Bank returned unknown format of the response but you can get
// pure response by calling $e->getResult() and manually check what went wrong
Debugger::log($e->getResult());
}

// If response is in known format, check response from bank
if ($response->isOk()) {
// Great do whatever you want
} else {
// $response->getErrorCodeMessage()
}
}

}
```

## Development

Expand Down