From a900396754e64660cc154523ee1d5fefaa9fcc24 Mon Sep 17 00:00:00 2001 From: Dominik Skerhak Date: Tue, 1 Sep 2020 10:28:00 +0000 Subject: [PATCH] Add PaymentGateway to VariableSymbolInterface::getNew() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - PaymentGateway can be used by generator of variable symbol `getNew()` to generate different variable symbol (transaction ID) series for different payment gateways - Payment gateway is always provided when new payment is added with `PaymentsRepository::add()`. - Argument is not optional but can be `null` (caller is forcing generator to work without gateway). Reason for this is admin `PaymentFormFactory` calling API `payments/variable-symbol` which doesn't work with gateway yet. Needs refactoring -> remp/crm#1440 remp/crm#1439 --- src/api/VariableSymbolApiHandler.php | 2 +- src/model/Repositories/PaymentsRepository.php | 2 +- src/model/Repositories/VariableSymbol.php | 3 ++- src/model/VariableSymbolInterface.php | 4 +++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/api/VariableSymbolApiHandler.php b/src/api/VariableSymbolApiHandler.php index 6e3a076..691ee45 100644 --- a/src/api/VariableSymbolApiHandler.php +++ b/src/api/VariableSymbolApiHandler.php @@ -29,7 +29,7 @@ public function params() */ public function handle(ApiAuthorizationInterface $authorization) { - $response = new JsonResponse(['status' => 'ok', 'variable_symbol' => $this->variableSymbol->getNew()]); + $response = new JsonResponse(['status' => 'ok', 'variable_symbol' => $this->variableSymbol->getNew(null)]); $response->setHttpCode(Response::S200_OK); return $response; diff --git a/src/model/Repositories/PaymentsRepository.php b/src/model/Repositories/PaymentsRepository.php index acd15f7..5cfb753 100644 --- a/src/model/Repositories/PaymentsRepository.php +++ b/src/model/Repositories/PaymentsRepository.php @@ -110,7 +110,7 @@ final public function add( 'status' => self::STATUS_FORM, 'created_at' => new DateTime(), 'modified_at' => new DateTime(), - 'variable_symbol' => $variableSymbol ? $variableSymbol : $this->variableSymbol->getNew(), + 'variable_symbol' => $variableSymbol ? $variableSymbol : $this->variableSymbol->getNew($paymentGateway), 'ip' => Request::getIp(), 'user_agent' => Request::getUserAgent(), 'referer' => $referer, diff --git a/src/model/Repositories/VariableSymbol.php b/src/model/Repositories/VariableSymbol.php index 3b8a105..bb74a1a 100644 --- a/src/model/Repositories/VariableSymbol.php +++ b/src/model/Repositories/VariableSymbol.php @@ -4,12 +4,13 @@ use Crm\ApplicationModule\Repository; use Crm\PaymentsModule\VariableSymbolInterface; +use Nette\Database\Table\ActiveRow; class VariableSymbol extends Repository implements VariableSymbolInterface { protected $tableName = 'variable_symbols'; - public function getNew(): string + public function getNew(?ActiveRow $paymentGateway): string { do { $variableSymbol = $this->generateRandom(); diff --git a/src/model/VariableSymbolInterface.php b/src/model/VariableSymbolInterface.php index 01c1ab6..9055a6f 100644 --- a/src/model/VariableSymbolInterface.php +++ b/src/model/VariableSymbolInterface.php @@ -2,7 +2,9 @@ namespace Crm\PaymentsModule; +use Nette\Database\Table\ActiveRow; + interface VariableSymbolInterface { - public function getNew(): string; + public function getNew(?ActiveRow $paymentGateway): string; }