src/CompanyGroupBundle/Modules/Api/Controller/OrganizationIdentityController.php line 11

Open in your IDE?
  1. <?php
  2. namespace CompanyGroupBundle\Modules\Api\Controller;
  3. use ApplicationBundle\Controller\GenericController;
  4. use Symfony\Component\HttpFoundation\JsonResponse;
  5. use Symfony\Component\HttpFoundation\Request;
  6. class OrganizationIdentityController extends GenericController
  7. {
  8.     public function syncErpCustomerAction(Request $request): JsonResponse
  9.     {
  10.         $expectedSecret = (string)$this->container->getParameter('secret');
  11.         $providedSecret = (string)$request->headers->get('X-Honeybee-Internal-Secret'$request->get('internalSecret'''));
  12.         if ($expectedSecret === '' || !hash_equals($expectedSecret$providedSecret)) {
  13.             return new JsonResponse([
  14.                 'success' => false,
  15.                 'code' => 'HB_UNAUTHORIZED',
  16.                 'message' => 'Unauthorized customer identity sync request.',
  17.             ], 401);
  18.         }
  19.         $payload json_decode((string)$request->getContent(), true);
  20.         if (!is_array($payload)) {
  21.             $payload $request->request->all();
  22.         }
  23.         try {
  24.             $result $this->get('app.organization_identity_service')->linkErpCustomer($payload);
  25.         } catch (\InvalidArgumentException $e) {
  26.             return new JsonResponse([
  27.                 'success' => false,
  28.                 'code' => 'HB_VALIDATION_ERROR',
  29.                 'message' => $e->getMessage(),
  30.             ], 400);
  31.         } catch (\Throwable $e) {
  32.             return new JsonResponse([
  33.                 'success' => false,
  34.                 'code' => 'HB_SYNC_ERROR',
  35.                 'message' => $e->getMessage(),
  36.             ], 500);
  37.         }
  38.         return new JsonResponse([
  39.             'success' => true,
  40.             'code' => 'HB_OK',
  41.             'message' => 'Customer organization identity synchronized.',
  42.             'data' => $result,
  43.         ]);
  44.     }
  45. }