Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Api\v1\Transactions\Verify;
- use App\Api\v1\Exceptions\NotFoundException;
- use App\Api\v1\Exceptions\ParameterNotFoundException;
- use App\Entity\Merchants;
- use App\Entity\Transactions;
- use App\Middleware\VerifyMiddleware;
- use Interop\Http\ServerMiddleware\DelegateInterface;
- use Psr\Http\Message\ServerRequestInterface;
- class ExistsMiddleware extends VerifyMiddleware
- {
- const URI_TOKEN = 'transactionid';
- /**
- * @param ServerRequestInterface $request
- * @param DelegateInterface $delegate
- * @return \Psr\Http\Message\ResponseInterface
- * @throws NotFoundException
- * @throws ParameterNotFoundException
- */
- public function process(ServerRequestInterface $request, DelegateInterface $delegate)
- {
- $this->isRequestVerified($request, \App\Api\v1\Merchants\Verify\ExistsMiddleware::class);
- $merchant = $request->getAttribute(Merchants::class);
- $transaction = $request->getAttribute(Transactions::class);
- if (!$transaction) {
- $transactionUuid = $this->getRouteParam($request, static::URI_TOKEN);
- $this->log('Get an information about one transtaction',
- ['transactionUuid' => $transactionUuid]
- );
- if ($transactionUuid) {
- $transaction = $this->getEm()->getRepository(Transactions::class)
- ->findOneBy([
- 'uuid' => $transactionUuid,
- 'merchant' => $merchant
- ]);
- $this->log('Request an information about one transtaction',
- $transaction->export()
- );
- $this->logTags([
- 'transaction' => $transaction->uuid,
- ]);
- if ($transaction) {
- $request = $request->withAttribute(Transactions::class, $transaction);
- }
- }
- }
- if (!is_array($transaction)) {
- $transactions = [$transaction];
- }
- else {
- $transactions = $transaction;
- }
- foreach ($transactions as $transaction) {
- if (!$transaction || $transaction->merchant->uuid != $merchant->uuid) {
- throw new ParameterNotFoundException('transaction');
- }
- }
- // @codeCoverageIgnoreStart
- // go next if the request had not been processed
- return $delegate->process(
- $this
- ->verifyRequest($request)
- );
- }// @codeCoverageIgnoreEnd
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement