|
|
@@ -5,9 +5,8 @@ declare(strict_types=1);
|
|
|
namespace App\Service\HelloAsso;
|
|
|
|
|
|
use App\ApiResources\HelloAsso\AuthUrl;
|
|
|
-use App\ApiResources\HelloAsso\HelloAssoProfile;
|
|
|
use App\ApiResources\HelloAsso\EventForm;
|
|
|
-use App\Entity\Booking\Event;
|
|
|
+use App\ApiResources\HelloAsso\HelloAssoProfile;
|
|
|
use App\Entity\HelloAsso\HelloAsso;
|
|
|
use App\Entity\Organization\Organization;
|
|
|
use App\Repository\Booking\EventRepository;
|
|
|
@@ -16,13 +15,9 @@ use App\Service\Rest\ApiRequestService;
|
|
|
use App\Service\Security\OAuthPkceGenerator;
|
|
|
use App\Service\Utils\DatesUtils;
|
|
|
use App\Service\Utils\UrlBuilder;
|
|
|
-use Doctrine\Common\Collections\Collection;
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
-use Psr\Log\LoggerInterface;
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
|
-use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
-use Symfony\Contracts\HttpClient\ResponseInterface;
|
|
|
|
|
|
/**
|
|
|
* Service de connexion à HelloAsso.
|
|
|
@@ -67,7 +62,7 @@ class HelloAssoService extends ApiRequestService
|
|
|
*
|
|
|
* @see doc/helloasso.md#se-connecter-avec-helloasso
|
|
|
*
|
|
|
- * @param int $organizationId the ID of the organization to connect
|
|
|
+ * @param int $organizationId the ID of the organization to connect
|
|
|
*/
|
|
|
public function getAuthUrl(int $organizationId): AuthUrl
|
|
|
{
|
|
|
@@ -153,9 +148,6 @@ class HelloAssoService extends ApiRequestService
|
|
|
|
|
|
/**
|
|
|
* Génère le profil HelloAsso pour une organisation.
|
|
|
- *
|
|
|
- * @param int $organizationId
|
|
|
- * @return HelloAssoProfile
|
|
|
*/
|
|
|
public function makeHelloAssoProfile(int $organizationId): HelloAssoProfile
|
|
|
{
|
|
|
@@ -202,9 +194,11 @@ class HelloAssoService extends ApiRequestService
|
|
|
|
|
|
/**
|
|
|
* @param array<string> $routeParts
|
|
|
+ *
|
|
|
* @return array<string, mixed>
|
|
|
*/
|
|
|
- public function getResource(HelloAsso $helloAssoEntity, array $routeParts): array {
|
|
|
+ public function getResource(HelloAsso $helloAssoEntity, array $routeParts): array
|
|
|
+ {
|
|
|
if (!$helloAssoEntity->getOrganizationSlug() || !$helloAssoEntity->getToken()) {
|
|
|
throw new \RuntimeException('HelloAsso entity incomplete');
|
|
|
}
|
|
|
@@ -219,19 +213,15 @@ class HelloAssoService extends ApiRequestService
|
|
|
$response = $this->get(
|
|
|
$url,
|
|
|
[],
|
|
|
- ['headers' =>
|
|
|
- [
|
|
|
- 'accept' => 'application/json',
|
|
|
- 'authorization' => 'Bearer '.$helloAssoEntity->getToken(),
|
|
|
- ]
|
|
|
+ ['headers' => [
|
|
|
+ 'accept' => 'application/json',
|
|
|
+ 'authorization' => 'Bearer '.$helloAssoEntity->getToken(),
|
|
|
+ ],
|
|
|
]
|
|
|
);
|
|
|
|
|
|
if ($response->getStatusCode() !== 200) {
|
|
|
- throw new HttpException(
|
|
|
- 500,
|
|
|
- 'Failed to fetch resource: ['.$response->getStatusCode().'] '.$response->getContent(false)
|
|
|
- );
|
|
|
+ throw new HttpException(500, 'Failed to fetch resource: ['.$response->getStatusCode().'] '.$response->getContent(false));
|
|
|
}
|
|
|
|
|
|
return json_decode($response->getContent(), true, 512, JSON_THROW_ON_ERROR);
|
|
|
@@ -302,15 +292,17 @@ class HelloAssoService extends ApiRequestService
|
|
|
if ($shallHaveToken && (!$helloAssoEntity->getOrganizationSlug() || !$helloAssoEntity->getToken())) {
|
|
|
throw new \RuntimeException('HelloAsso entity incomplete');
|
|
|
}
|
|
|
+
|
|
|
return $helloAssoEntity;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Construit un objet EventForm à partir des données retournées par l'api HelloAsso.
|
|
|
+ *
|
|
|
* @param array<string, mixed> $formData
|
|
|
- * @return EventForm
|
|
|
*/
|
|
|
- protected function makeHelloAssoEventForm(array $formData): EventForm {
|
|
|
+ protected function makeHelloAssoEventForm(array $formData): EventForm
|
|
|
+ {
|
|
|
$form = new EventForm();
|
|
|
$form->setSlug($formData['formSlug']);
|
|
|
$form->setTitle($formData['title']);
|
|
|
@@ -320,9 +312,7 @@ class HelloAssoService extends ApiRequestService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Génère l'URL de rappel pour les callbacks suite à l'authentification HelloAsso
|
|
|
- *
|
|
|
- * @return string
|
|
|
+ * Génère l'URL de rappel pour les callbacks suite à l'authentification HelloAsso.
|
|
|
*/
|
|
|
protected function getCallbackUrl(): string
|
|
|
{
|
|
|
@@ -412,7 +402,8 @@ class HelloAssoService extends ApiRequestService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function refreshTokenIfNeeded(HelloAsso $helloAssoEntity): HelloAsso {
|
|
|
+ public function refreshTokenIfNeeded(HelloAsso $helloAssoEntity): HelloAsso
|
|
|
+ {
|
|
|
if (!$helloAssoEntity->getRefreshToken() || !$helloAssoEntity->getRefreshTokenCreatedAt()) {
|
|
|
throw new \RuntimeException('HelloAsso entity incomplete');
|
|
|
}
|
|
|
@@ -427,7 +418,8 @@ class HelloAssoService extends ApiRequestService
|
|
|
return $this->refreshTokens($helloAssoEntity);
|
|
|
}
|
|
|
|
|
|
- public function refreshTokens(HelloAsso $helloAssoEntity): HelloAsso {
|
|
|
+ public function refreshTokens(HelloAsso $helloAssoEntity): HelloAsso
|
|
|
+ {
|
|
|
if (!$helloAssoEntity->getRefreshToken() || !$helloAssoEntity->getRefreshTokenCreatedAt()) {
|
|
|
throw new \RuntimeException('HelloAsso entity incomplete');
|
|
|
}
|