Skip to content

Commit

Permalink
Change response of API handlers to JsonApiResponse
Browse files Browse the repository at this point in the history
These changes are non breaking and were generated by rector. Check our
custom sets & rules -> remp/crm-rector.

- Changed return type of `handle()`:
  - from `Crm\ApiModule\Response\ApiResponseInterface`
  - to `Tomaj\NetteApi\Response\ResponseInterface`.
- Changed deprecated response:
  - from `Crm\ApiModule\Api\JsonResponse`
  - to `Tomaj\NetteApi\Response\JsonApiResponse`.

remp/crm#2330 & remp/crm#2342
  • Loading branch information
markoph committed Mar 29, 2022
1 parent 2875e00 commit 45c78a8
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/Api/IpnHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

namespace Crm\PrivatbankarModule\Api;

use Crm\ApiModule\Api\ApiHandler;
use Crm\ApiModule\Api\EmptyResponse;
use Crm\ApiModule\Api\JsonResponse;
use Crm\ApiModule\Params\InputParam;
use Crm\ApiModule\Params\ParamsProcessor;
use Crm\ApiModule\Response\ApiResponseInterface;
use Crm\PaymentsModule\PaymentProcessor;
use Crm\PaymentsModule\Repository\PaymentMetaRepository;
use Nette\Http\Response;
use Tomaj\NetteApi\Response\JsonApiResponse;
use Tomaj\NetteApi\Response\ResponseInterface;

class IpnHandler extends \Crm\ApiModule\Api\ApiHandler
class IpnHandler extends ApiHandler
{
private $paymentMetaRepository;

Expand All @@ -30,20 +31,18 @@ public function params(): array
];
}

public function handle(array $params): ApiResponseInterface
public function handle(array $params): ResponseInterface
{
$paramsProcessor = new ParamsProcessor($this->params());
if ($paramsProcessor->hasError()) {
$response = new JsonResponse(['status' => 'error', 'message' => $paramsProcessor->hasError()]);
$response->setHttpCode(Response::S400_BAD_REQUEST);
$response = new JsonApiResponse(Response::S400_BAD_REQUEST, ['status' => 'error', 'message' => $paramsProcessor->hasError()]);
return $response;
}
$params = $paramsProcessor->getValues();

$meta = $this->paymentMetaRepository->findByMeta('privatbankar_transaction_reference', $params['uuid']);
if (!$meta) {
$response = new JsonResponse(['status' => 'error', 'message' => 'payment not found: ' . $params['uuid']]);
$response->setHttpCode(Response::S404_NOT_FOUND);
$response = new JsonApiResponse(Response::S404_NOT_FOUND, ['status' => 'error', 'message' => 'payment not found: ' . $params['uuid']]);
return $response;
}

Expand All @@ -54,7 +53,7 @@ public function handle(array $params): ApiResponseInterface
});

$response = new EmptyResponse();
$response->setHttpCode(Response::S200_OK);
$response->setCode(Response::S200_OK);
return $response;
}
}

0 comments on commit 45c78a8

Please sign in to comment.