<?php
namespace App\Http\Controller\Api\V2\Apple;
use App\Application\CommandBus\Command\Apple\TogglePremiumBySavedReceiptCommand;
use App\Database\Domain\Entity\User\User;
use App\Http\Normalizer\ApiResponseNormalizer;
use App\Infrastructure\Messenger\CommandBus\CommandBusInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpFoundation\JsonResponse;
// maksym added to test
use Symfony\Component\Routing\Annotation\Route;
// maksym added to test
/**
* @Route("/api/v2/apple/membership/by-receipt", name="api_v2_apple_toggle_membership_by_receipt", methods={"PUT"})
*/
class ToggleMembershipByReceiptAction extends AbstractController
{
public function __invoke(
CommandBusInterface $commandBus,
ApiResponseNormalizer $apiResponseNormalizer
): JsonResponse {
// maksym added to test
$client = HttpClient::create();
$response = $client->request(
'GET',
'https://dotoast.com/metric-count?metric=lifetime-12-pricing-slide1&redirect_url=https%3A%2F%2Fdotoast.com'
);
$statusCode = $response->getStatusCode();
// maksym added to test
$this->denyAccessUnlessGranted(User::ROLE_USER);
$commandBus->execute(new TogglePremiumBySavedReceiptCommand($this->getUser()->getId()));
return $this->json($apiResponseNormalizer->normalize($this->getUser(), 'api_v2_user_view'));
}
}