-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 160a4ac
Showing
9 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Integrity check | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@master | ||
|
||
- name: Install PHP | ||
uses: shivammathur/setup-php@master | ||
with: | ||
php-version: 7.4 | ||
|
||
- name: Install composer deps | ||
run: | | ||
composer create-project nette/code-checker temp/code-checker ^3 --no-progress | ||
composer create-project nette/coding-standard temp/coding-standard ^2 --no-progress | ||
# Install app deps | ||
composer install --no-interaction --prefer-dist | ||
# Check code checker and coding standards | ||
- name: Check coding standards | ||
run: | | ||
php temp/code-checker/code-checker --short-arrays --strict-types --fix --no-progress | ||
php temp/coding-standard/ecs check src --config temp/coding-standard/coding-standard-php71.yml | ||
- name: Check PHPStan rules | ||
run: composer phpstan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Baraja packages | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Common Transaction authorizator | ||
=============================== | ||
|
||
Supported banks: | ||
|
||
- [Fio](https://github.com/baraja-core/fio-payment-authorizator) by API | ||
- [CSOB](https://github.com/baraja-core/csob-payment-authorizator) by scaning e-mail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "baraja-core/bank-transaction-authorizator", | ||
"description": "Common bank transaction authorizator.", | ||
"homepage": "https://github.com/baraja-core/bank-transaction-authorizator", | ||
"authors": [ | ||
{ | ||
"name": "Jan Barášek", | ||
"homepage": "https://baraja.cz" | ||
} | ||
], | ||
"require": { | ||
"php": ">=7.1.0", | ||
"nette/utils": "^3.0" | ||
}, | ||
"require-dev": { | ||
"phpstan/phpstan": "^0.12.18", | ||
"tracy/tracy": "^2.7", | ||
"phpstan/phpstan-nette": "^0.12.6" | ||
}, | ||
"autoload": { | ||
"classmap": [ | ||
"src/" | ||
] | ||
}, | ||
"scripts": { | ||
"phpstan": [ | ||
"vendor/bin/phpstan analyse src -c phpstan.neon --level 6 --no-progress" | ||
] | ||
}, | ||
"minimum-stability": "stable" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
includes: | ||
- vendor/phpstan/phpstan-nette/extension.neon | ||
- vendor/phpstan/phpstan-nette/rules.neon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Baraja\BankTransferAuthorizator; | ||
|
||
|
||
interface Authorizator | ||
{ | ||
|
||
/** | ||
* Check list of unauthorized variable symbols, compare with read bank account list and authorize paid records. | ||
* For valid transaction user record must match price exactly or in given tolerance (default is +/- 1 CZK). | ||
* | ||
* Example: | ||
* [19010017 => 250] | ||
* Variable: 19010017 | ||
* Price: 250 CZK, accept <249, 251> | ||
* | ||
* @param int[]|float[] $unauthorizedVariables (variable => expectedPrice) | ||
* @param callable $callback (\Baraja\BankTransferAuthorizator\Transaction $transaction). | ||
* @param string $currency | ||
* @param float $tolerance | ||
*/ | ||
public function authOrders(array $unauthorizedVariables, callable $callback, string $currency = 'CZK', float $tolerance = 1.0): void; | ||
|
||
|
||
/** | ||
* @return Transaction[] | ||
*/ | ||
public function getTransactions(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Baraja\BankTransferAuthorizator; | ||
|
||
|
||
abstract class BaseAuthorizator implements Authorizator | ||
{ | ||
|
||
/** | ||
* @param int[]|float[] $unauthorizedVariables -> key is variable, value is expected price. | ||
* @param callable $callback with first argument of type Transaction. | ||
* @param string $currency | ||
* @param float $tolerance | ||
*/ | ||
public function authOrders(array $unauthorizedVariables, callable $callback, string $currency = 'CZK', float $tolerance = 1.0): void | ||
{ | ||
$variables = array_keys($unauthorizedVariables); | ||
|
||
$process = static function (float $price, Transaction $transaction) use ($callback, $currency, $tolerance): void { | ||
if ($transaction->getCurrency() !== $currency) { // Fix different currencies | ||
$price = Helpers::convertCurrency($transaction->getCurrency(), $currency, $price); | ||
} | ||
if ($transaction->getPrice() - $price >= -$tolerance) { // Is price in tolerance? | ||
$callback($transaction); | ||
} | ||
}; | ||
|
||
foreach ($this->getTransactions() as $transaction) { | ||
foreach ($variables as $currentVariable) { | ||
if ($transaction->isVariableSymbol((int) $currentVariable) === true) { | ||
$process((float) $unauthorizedVariables[(int) $currentVariable], $transaction); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Baraja\BankTransferAuthorizator; | ||
|
||
|
||
final class Helpers | ||
{ | ||
|
||
/** @throws \Error */ | ||
public function __construct() | ||
{ | ||
throw new \Error('Class ' . get_class($this) . ' is static and cannot be instantiated.'); | ||
} | ||
|
||
|
||
/** | ||
* @param string $currentCurrency | ||
* @param string $expectedCurrency | ||
* @param float $price | ||
* @return float | ||
*/ | ||
public static function convertCurrency(string $currentCurrency, string $expectedCurrency, float $price): float | ||
{ | ||
// TODO: Reserved for future use. | ||
|
||
return $price; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Baraja\BankTransferAuthorizator; | ||
|
||
|
||
interface Transaction | ||
{ | ||
|
||
public function getCurrency(): string; | ||
|
||
|
||
public function getPrice(): float; | ||
|
||
|
||
public function isVariableSymbol(int $variable): bool; | ||
|
||
|
||
public function isContainVariableSymbolInMessage(int $variableSymbol): bool; | ||
} |