|
|
@@ -14,13 +14,10 @@ use App\Enum\Organization\SettingsProductEnum;
|
|
|
use App\Enum\Shop\ShopRequestStatus;
|
|
|
use App\Enum\Shop\ShopRequestType;
|
|
|
use App\Message\Message\Shop\NewStructureArtistPremiumTrial;
|
|
|
-use App\Repository\Organization\OrganizationRepository;
|
|
|
-use App\Service\ApiLegacy\ApiLegacyRequestService;
|
|
|
use App\Service\Dolibarr\DolibarrApiService;
|
|
|
use App\Service\Dolibarr\DolibarrUtils;
|
|
|
use App\Service\Mailer\Mailer;
|
|
|
use App\Service\Mailer\Model\NewStructureArtistPremiumTrialRequestValidationModel;
|
|
|
-use App\Service\Mailer\Model\SubdomainChangeModel;
|
|
|
use App\Service\Organization\OrganizationFactory;
|
|
|
use App\Service\Utils\DatesUtils;
|
|
|
use App\Service\Utils\UrlBuilder;
|
|
|
@@ -28,11 +25,8 @@ use Doctrine\DBAL\Exception;
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
use Doctrine\ORM\Exception\ORMException;
|
|
|
use Doctrine\ORM\OptimisticLockException;
|
|
|
-use JsonException;
|
|
|
use libphonenumber\PhoneNumberUtil;
|
|
|
use Psr\Log\LoggerInterface;
|
|
|
-use RuntimeException;
|
|
|
-use Symfony\Component\HttpFoundation\Response;
|
|
|
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
|
|
use Symfony\Component\Messenger\Exception\ExceptionInterface;
|
|
|
use Symfony\Component\Messenger\MessageBusInterface;
|
|
|
@@ -56,14 +50,14 @@ class ShopService
|
|
|
|
|
|
public function __construct(
|
|
|
private EntityManagerInterface $entityManager,
|
|
|
- private Mailer $mailer,
|
|
|
- private string $publicBaseUrl,
|
|
|
- private OrganizationFactory $organizationFactory,
|
|
|
- private SerializerInterface $serializer,
|
|
|
- private LoggerInterface $logger,
|
|
|
- private DolibarrApiService $dolibarrApiService,
|
|
|
- private DolibarrUtils $dolibarrUtils,
|
|
|
- private MessageBusInterface $messageBus,
|
|
|
+ private Mailer $mailer,
|
|
|
+ private string $publicBaseUrl,
|
|
|
+ private OrganizationFactory $organizationFactory,
|
|
|
+ private SerializerInterface $serializer,
|
|
|
+ private LoggerInterface $logger,
|
|
|
+ private DolibarrApiService $dolibarrApiService,
|
|
|
+ private DolibarrUtils $dolibarrUtils,
|
|
|
+ private MessageBusInterface $messageBus,
|
|
|
) {
|
|
|
$this->phoneNumberUtil = PhoneNumberUtil::getInstance();
|
|
|
}
|
|
|
@@ -72,9 +66,8 @@ class ShopService
|
|
|
* A new shop request has been submitted.
|
|
|
* Register the request, and send the validation link by email.
|
|
|
*
|
|
|
- * @param ShopRequestType $type
|
|
|
* @param array<string, mixed> $data
|
|
|
- * @return ShopRequest
|
|
|
+ *
|
|
|
* @throws TransportExceptionInterface
|
|
|
*/
|
|
|
public function registerNewShopRequest(ShopRequestType $type, array $data): ShopRequest
|
|
|
@@ -91,24 +84,24 @@ class ShopService
|
|
|
* For NEW_STRUCTURE_ARTIST_PREMIUM_TRIAL, check if the organization already exists.
|
|
|
* For other types, throw an error.
|
|
|
*
|
|
|
- * @param ShopRequestType $type
|
|
|
* @param array<string, mixed> $data
|
|
|
*/
|
|
|
- protected function controlShopRequestData(ShopRequestType $type, array $data): void
|
|
|
+ protected function controlShopRequestData(ShopRequestType $type, NewStructureArtistPremiumTrialRequest|array $data): void
|
|
|
{
|
|
|
+ // @phpstan-ignore-next-line identical.alwaysTrue
|
|
|
if ($type === ShopRequestType::NEW_STRUCTURE_ARTIST_PREMIUM_TRIAL) {
|
|
|
/** @var NewStructureArtistPremiumTrialRequest $request */
|
|
|
$request = $data;
|
|
|
$this->validateNewStructureArtistPremiumTrialRequest($request);
|
|
|
} else {
|
|
|
- throw new RuntimeException('request type not supported');
|
|
|
+ throw new \RuntimeException('request type not supported');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Validate the request and dispatch the appropriate job based on the request type.
|
|
|
*
|
|
|
- * @throws RuntimeException|ExceptionInterface
|
|
|
+ * @throws \RuntimeException|ExceptionInterface
|
|
|
*/
|
|
|
public function processShopRequest(ShopRequest $shopRequest): void
|
|
|
{
|
|
|
@@ -120,7 +113,7 @@ class ShopService
|
|
|
);
|
|
|
break;
|
|
|
default:
|
|
|
- throw new RuntimeException('request type not supported');
|
|
|
+ throw new \RuntimeException('request type not supported');
|
|
|
}
|
|
|
|
|
|
$shopRequest->setStatus(ShopRequestStatus::VALIDATED);
|
|
|
@@ -130,9 +123,8 @@ class ShopService
|
|
|
|
|
|
/**
|
|
|
* Create and persist a new ShopRequest entity.
|
|
|
- * @param ShopRequestType $type
|
|
|
+ *
|
|
|
* @param array<string, mixed> $data
|
|
|
- * @return ShopRequest
|
|
|
*/
|
|
|
protected function createRequest(ShopRequestType $type, array $data): ShopRequest
|
|
|
{
|
|
|
@@ -163,13 +155,13 @@ class ShopService
|
|
|
|
|
|
$model = new NewStructureArtistPremiumTrialRequestValidationModel();
|
|
|
$model
|
|
|
- ->setSenderId(AccessIdsEnum::ADMIN_2IOPENSERVICE->value)
|
|
|
->setToken($shopRequest->getToken())
|
|
|
->setRepresentativeEmail($data['representativeEmail'] ?? '')
|
|
|
->setRepresentativeFirstName($data['representativeFirstName'] ?? '')
|
|
|
->setRepresentativeLastName($data['representativeLastName'] ?? '')
|
|
|
->setStructureName($data['structureName'] ?? '')
|
|
|
- ->setValidationUrl($validationUrl);
|
|
|
+ ->setValidationUrl($validationUrl)
|
|
|
+ ->setSenderId(AccessIdsEnum::ADMIN_2IOPENSERVICE->value);
|
|
|
|
|
|
$this->mailer->main($model);
|
|
|
|
|
|
@@ -181,17 +173,17 @@ class ShopService
|
|
|
/**
|
|
|
* Start an artist premium trial for an organization.
|
|
|
*
|
|
|
- * @param Organization $organization The organization to start the trial for
|
|
|
- * @param NewStructureArtistPremiumTrialRequest $request The trial request data
|
|
|
+ * @param Organization $organization The organization to start the trial for
|
|
|
+ * @param NewStructureArtistPremiumTrialRequest $request The trial request data
|
|
|
*
|
|
|
* @throws Exception
|
|
|
- * @throws JsonException
|
|
|
+ * @throws \JsonException
|
|
|
*/
|
|
|
protected function startArtistPremiumTrial(Organization $organization, NewStructureArtistPremiumTrialRequest $request): void
|
|
|
{
|
|
|
// Update settings
|
|
|
$settings = $organization->getSettings();
|
|
|
- $settings->setProductBeforeTrial( $organization->getSettings()->getProduct());
|
|
|
+ $settings->setProductBeforeTrial($organization->getSettings()->getProduct());
|
|
|
$settings->setTrialActive(true);
|
|
|
$settings->setLastTrialStartDate(DatesUtils::new());
|
|
|
$settings->setProduct(SettingsProductEnum::ARTIST_PREMIUM);
|
|
|
@@ -220,7 +212,7 @@ class ShopService
|
|
|
|
|
|
// Ajoute une entrée aux actions commerciales dolibarr
|
|
|
$message = sprintf(
|
|
|
- "Action réalisé par : %s %s.<br>Fonction : %s<br>Mail:%s<br>Tel:%s",
|
|
|
+ 'Action réalisé par : %s %s.<br>Fonction : %s<br>Mail:%s<br>Tel:%s',
|
|
|
$request->getRepresentativeFirstName(),
|
|
|
$request->getRepresentativeLastName(),
|
|
|
$request->getRepresentativeFunction(),
|
|
|
@@ -237,9 +229,9 @@ class ShopService
|
|
|
* Handles the processing of a new structure artist premium trial request.
|
|
|
*
|
|
|
* @param string $token The token identifying the shop request
|
|
|
- * @return void
|
|
|
+ *
|
|
|
* @throws Exception
|
|
|
- * @throws JsonException
|
|
|
+ * @throws \JsonException
|
|
|
* @throws ORMException
|
|
|
* @throws OptimisticLockException
|
|
|
*/
|
|
|
@@ -249,7 +241,8 @@ class ShopService
|
|
|
$shopRequest = $this->entityManager->find(ShopRequest::class, $token);
|
|
|
|
|
|
if (!$shopRequest) {
|
|
|
- $this->logger->error('Cannot find ShopRequest with token: ' . $token);
|
|
|
+ $this->logger->error('Cannot find ShopRequest with token: '.$token);
|
|
|
+
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -266,13 +259,14 @@ class ShopService
|
|
|
// Start the artist premium trial
|
|
|
$this->startArtistPremiumTrial($organization, $trialRequest);
|
|
|
|
|
|
- $this->logger->info('Successfully processed NewStructureArtistPremiumTrial for token: ' . $token);
|
|
|
+ $this->logger->info('Successfully processed NewStructureArtistPremiumTrial for token: '.$token);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Creates a new organization based on a trial request.
|
|
|
*
|
|
|
* @param NewStructureArtistPremiumTrialRequest $trialRequest The trial request containing organization data
|
|
|
+ *
|
|
|
* @return Organization The created organization
|
|
|
*/
|
|
|
protected function createOrganization(NewStructureArtistPremiumTrialRequest $trialRequest): Organization
|
|
|
@@ -309,6 +303,7 @@ class ShopService
|
|
|
* Generate a subdomain from a structure name.
|
|
|
*
|
|
|
* @param string $name The structure name to generate a subdomain from
|
|
|
+ *
|
|
|
* @return string The generated subdomain
|
|
|
*/
|
|
|
protected function generateSubdomain(string $name): string
|
|
|
@@ -346,27 +341,23 @@ class ShopService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Vérifie la validité d'une requête d'essai artist premium pour une nouvelle structure
|
|
|
- *
|
|
|
- * @param NewStructureArtistPremiumTrialRequest $request
|
|
|
- * @return void
|
|
|
+ * Vérifie la validité d'une requête d'essai artist premium pour une nouvelle structure.
|
|
|
*/
|
|
|
protected function validateNewStructureArtistPremiumTrialRequest(
|
|
|
- NewStructureArtistPremiumTrialRequest $request
|
|
|
- ): void
|
|
|
- {
|
|
|
+ NewStructureArtistPremiumTrialRequest $request,
|
|
|
+ ): void {
|
|
|
// Validate phone number
|
|
|
if (!$this->phoneNumberUtil->isPossibleNumber($request->getRepresentativePhone())) {
|
|
|
- throw new RuntimeException('Invalid phone number');
|
|
|
+ throw new \RuntimeException('Invalid phone number');
|
|
|
}
|
|
|
|
|
|
// Check if organization already exists
|
|
|
$organizationCreationRequest = new OrganizationCreationRequest();
|
|
|
- $organizationCreationRequest->setName($request->getStructureName() ?? '');
|
|
|
- $organizationCreationRequest->setCity($request->getCity() ?? '');
|
|
|
- $organizationCreationRequest->setPostalCode($request->getPostalCode() ?? '');
|
|
|
- $organizationCreationRequest->setStreetAddress1($request->getAddress() ?? '');
|
|
|
- $organizationCreationRequest->setStreetAddress2($request->getAddressComplement() ?? '');
|
|
|
+ $organizationCreationRequest->setName($request->getStructureName());
|
|
|
+ $organizationCreationRequest->setCity($request->getCity());
|
|
|
+ $organizationCreationRequest->setPostalCode($request->getPostalCode());
|
|
|
+ $organizationCreationRequest->setStreetAddress1($request->getAddress());
|
|
|
+ $organizationCreationRequest->setStreetAddress2($request->getAddressComplement());
|
|
|
$organizationCreationRequest->setStreetAddress3('');
|
|
|
$this->organizationFactory->interruptIfOrganizationExists($organizationCreationRequest);
|
|
|
}
|