<?php
declare(strict_types=1);
namespace App\Controller\Api\Payment;
use App\Exception\Global\InvalidParameterException;
use App\Exception\Global\ResourceNotFoundException;
use App\Repository\Payment\PaymentRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
class GetPaymentStatusController extends AbstractController
{
public function __construct(
private PaymentRepository $paymentRepository,
) {
}
public function __invoke(Request $request): JsonResponse
{
$shopToken = $request->headers->get('shop-token');
$externalId = $request->attributes->get('external_id');
if (null === $shopToken || null === $externalId) {
throw new InvalidParameterException();
}
$payment = $this->paymentRepository->findOneByExternalIdAndShopToken($externalId, $shopToken);
if (null === $payment) {
throw new ResourceNotFoundException();
}
return new JsonResponse(['state' => $payment->getState()], JsonResponse::HTTP_OK);
}
}