|
|
@@ -7,10 +7,8 @@ namespace App\Service\Dolibarr;
|
|
|
use App\Entity\Organization\Organization;
|
|
|
use App\Service\Rest\ApiRequestService;
|
|
|
use JetBrains\PhpStorm\Pure;
|
|
|
-use Symfony\Component\HttpClient\Exception\ClientException;
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
|
-use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
|
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
|
|
|
|
/**
|
|
|
@@ -185,44 +183,21 @@ class DolibarrApiService extends ApiRequestService
|
|
|
|
|
|
/**
|
|
|
* @param Organization $organization
|
|
|
- * @throws TransportExceptionInterface
|
|
|
+ * @return mixed
|
|
|
*/
|
|
|
- public function createSociety(Organization $organization): void
|
|
|
+ public function createSociety(Organization $organization): mixed
|
|
|
{
|
|
|
- try {
|
|
|
- $body = json_encode([
|
|
|
- 'name' => $organization->getName(),
|
|
|
- 'client' => 2,
|
|
|
- 'code_client' => -1,
|
|
|
- 'import_key' => 'crm',
|
|
|
- 'array_options' => ['options_2iopen_organization_id' => $organization->getId()]
|
|
|
- ]);
|
|
|
-
|
|
|
- $options = [
|
|
|
- 'headers' => [
|
|
|
- 'Accept'=> 'application/json',
|
|
|
- 'DOLAPIKEY' => "Bocc4zC0J186v8J6QCqu7DnoIw4I7mCJ"
|
|
|
- ],
|
|
|
- 'body' => $body
|
|
|
- ];
|
|
|
-
|
|
|
- /** @var Response $response */
|
|
|
- $response = $this->client->request('POST',
|
|
|
- "api/index.php/thirdparties",
|
|
|
- $options
|
|
|
- );
|
|
|
-
|
|
|
- // $content = json_decode($response->getBody()->getContents(), true);
|
|
|
-
|
|
|
- } catch (ClientException $exception) {
|
|
|
- switch ($exception->getResponse()->getStatusCode()) {
|
|
|
- case Response::HTTP_BAD_REQUEST:
|
|
|
- //throw new \Exception('errors', self::HTTP_ERROR);
|
|
|
- break;
|
|
|
- case Response::HTTP_NOT_FOUND:
|
|
|
- //throw new \Exception('credentials_incorrects', self::HTTP_UNAUTHORIZED);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
+ $body = [
|
|
|
+ 'name' => $organization->getName(),
|
|
|
+ 'client' => 2,
|
|
|
+ 'code_client' => -1,
|
|
|
+ 'import_key' => 'crm',
|
|
|
+ 'array_options' => ['options_2iopen_organization_id' => $organization->getId()]
|
|
|
+ ];
|
|
|
+
|
|
|
+ /** @var Response $response */
|
|
|
+ $response = $this->post("api/index.php/thirdparties", $body);
|
|
|
+
|
|
|
+ return json_decode($response->getContent(), true);
|
|
|
}
|
|
|
}
|