Skip to content

Commit

Permalink
Add PaymentGateway to VariableSymbolInterface::getNew()
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
markoph authored and rootpd committed Sep 1, 2020
1 parent bd81971 commit a900396
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/api/VariableSymbolApiHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/model/Repositories/PaymentsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/model/Repositories/VariableSymbol.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion src/model/VariableSymbolInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Crm\PaymentsModule;

use Nette\Database\Table\ActiveRow;

interface VariableSymbolInterface
{
public function getNew(): string;
public function getNew(?ActiveRow $paymentGateway): string;
}

0 comments on commit a900396

Please sign in to comment.