|
|
@@ -1,89 +0,0 @@
|
|
|
-<?php
|
|
|
-
|
|
|
-declare(strict_types=1);
|
|
|
-
|
|
|
-namespace App\MessageHandler;
|
|
|
-
|
|
|
-use App\Message\StartArtistPremiumTrial;
|
|
|
-use App\Service\ApiLegacy\ApiLegacyRequestService;
|
|
|
-use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
|
|
-use Symfony\Component\HttpFoundation\Response;
|
|
|
-use Psr\Log\LoggerInterface;
|
|
|
-
|
|
|
-#[AsMessageHandler]
|
|
|
-class StartArtistPremiumTrialHandler
|
|
|
-{
|
|
|
- public function __construct(
|
|
|
- private readonly ApiLegacyRequestService $apiLegacyRequestService,
|
|
|
- private readonly LoggerInterface $logger,
|
|
|
- private readonly string $legacyBaseUrl
|
|
|
- ) {
|
|
|
- }
|
|
|
-
|
|
|
- public function __invoke(StartArtistPremiumTrial $message): void
|
|
|
- {
|
|
|
- $organization = $message->getOrganization();
|
|
|
- $representative = $message->getRepresentative();
|
|
|
- $person = $representative->getPerson();
|
|
|
-
|
|
|
- // Get the organization's address
|
|
|
- $organizationAddressPostal = null;
|
|
|
- foreach ($organization->getOrganizationAddressPostals() as $addressPostal) {
|
|
|
- $organizationAddressPostal = $addressPostal;
|
|
|
- break; // Get the first one
|
|
|
- }
|
|
|
-
|
|
|
- if (!$organizationAddressPostal) {
|
|
|
- $this->logger->error('Cannot start artist premium trial: organization has no address');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- $addressPostal = $organizationAddressPostal->getAddressPostal();
|
|
|
-
|
|
|
- // Get the representative's contact point
|
|
|
- $contactPoint = null;
|
|
|
- foreach ($person->getContactPoints() as $cp) {
|
|
|
- $contactPoint = $cp;
|
|
|
- break; // Get the first one
|
|
|
- }
|
|
|
-
|
|
|
- if (!$contactPoint) {
|
|
|
- $this->logger->error('Cannot start artist premium trial: representative has no contact point');
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // Prepare the request data
|
|
|
- $data = [
|
|
|
- "organization" => [
|
|
|
- "streetAddress" => $addressPostal->getStreetAddress(),
|
|
|
- "streetAddressSecond" => $addressPostal->getStreetAddressSecond(),
|
|
|
- "streetAddressThird" => $addressPostal->getStreetAddressThird(),
|
|
|
- "cp" => $addressPostal->getPostalCode(),
|
|
|
- "city" => $addressPostal->getAddressCity(),
|
|
|
- "organizationAddressPostalId" => "/api/organization_address_postals/" . $organizationAddressPostal->getId(),
|
|
|
- "name" => $organization->getName()
|
|
|
- ],
|
|
|
- "access" => [
|
|
|
- "isAdmin" => $representative->isAdminAccess(),
|
|
|
- "email" => $contactPoint->getEmail(),
|
|
|
- "contactPointId" => "/api/contactpoints/" . $contactPoint->getId(),
|
|
|
- "name" => $person->getName(),
|
|
|
- "givenName" => $person->getGivenName(),
|
|
|
- "function" => "representative",
|
|
|
- "telphone" => (string)$contactPoint->getTelphone()
|
|
|
- ]
|
|
|
- ];
|
|
|
-
|
|
|
- try {
|
|
|
- $response = $this->apiLegacyRequestService->get('/api/trial/artist_premium', $data);
|
|
|
-
|
|
|
- if ($response->getStatusCode() !== Response::HTTP_OK) {
|
|
|
- $this->logger->error('Failed to start artist premium trial: ' . $response->getContent());
|
|
|
- } else {
|
|
|
- $this->logger->info('Successfully started artist premium trial for organization ' . $organization->getId());
|
|
|
- }
|
|
|
- } catch (\Exception $e) {
|
|
|
- $this->logger->error('Exception while starting artist premium trial: ' . $e->getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-}
|