diff --git a/.docs/README.md b/.docs/README.md deleted file mode 100644 index c054fd7..0000000 --- a/.docs/README.md +++ /dev/null @@ -1,111 +0,0 @@ -# Contributte Fio Api Integration - -## Content - -- [Requirements - what do you need](#requirements) -- [Installation - how to register an extension](#installation) -- [Usage - how to use it](#usage) - -## Requirements - -You need your bank account and token generated in your e-banking. There is no special token for testing. So you will 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 bank and the other one for downloading payments from bank (We only included sending payments feature yet.). - -* **accountNumber** -* **accountToken** - -## Installation - -```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 supplier 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 return PaymentResponse - -```php -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($[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() - } - } - -} -``` diff --git a/README.md b/README.md index ac6755a..7f153ca 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,16 @@ Website 🚀 contributte.org | Contact 👨🏻‍💻 f3l1x.io | Twitter 🐦 @contributte

-## 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). @@ -26,17 +35,109 @@ To install latest version of `contributte/fio` use [Composer](https://getcompose 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 +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