'Created Identification Document', 'message' => 'You have successfully created a new identification document' ]; } /** @var FetchesCompany */ private $fetchesCompany; /** @var CreatesDocument */ private $createsDocument; /** @var CreatesFiles */ private $createsFile; /** @var UpdatesCompanyStatus */ private $updatesCompanyStatus; /** @var CreateIdentificationDocumentOnExchangeProcessor */ private $createIdentificationDocumentOnExchangeProcessor; /** * CreateIdentificationDocumentLogic constructor. * @param FetchesCompany $fetchesCompany * @param CreatesDocument $createsDocument * @param CreatesFiles $createsFile * @param UpdatesCompanyStatus $updatesCompanyStatus * @param CreateIdentificationDocumentOnExchangeProcessor $createIdentificationDocumentOnExchangeProcessor */ public function __construct(FetchesCompany $fetchesCompany, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesCompanyStatus $updatesCompanyStatus, CreateIdentificationDocumentOnExchangeProcessor $createIdentificationDocumentOnExchangeProcessor) { $this->fetchesCompany = $fetchesCompany; $this->createsDocument = $createsDocument; $this->createsFile = $createsFile; $this->updatesCompanyStatus = $updatesCompanyStatus; $this->createIdentificationDocumentOnExchangeProcessor = $createIdentificationDocumentOnExchangeProcessor; } /** * @param Request $request * @return JsonResponse * @throws \App\Classes\Exceptions\MalformedRequestException */ public function logic(Request $request) : JsonResponse { if ($request->route('exchange_company_id')) { $companyModule = ExchangeCompanyConnection::where('exchange_company_id', $request->route('exchange_company_id'))->first()->companyModule; $companyId = $companyModule->company_id; } else { $companyId = $request->route('id'); } /** @var Company $company */ $company = $this->fetchesCompany->execute(['id' => $companyId]); $object = new DocumentObject($company->type === CompanyType::COMPANY_BUSINESS ? DocumentType::SSM_REGISTRATION : DocumentType::IDENTITY_CARD, $request->input('files'), $request->input('identification_no'), ApprovalStatus::PENDING_VERIFICATION, 'identifications'); /** @var Document $document */ $document = $this->createsDocument->execute($company, $object); $this->createsFile->execute($document, $object); $this->updatesCompanyStatus->execute($company, ApprovalStatus::PENDING_VERIFICATION); // create identification on exchange if this request not coming from exchange $companyModule = $company->companyModules()->first(); if (!$request->route('exchange_company_id') && $companyModule->exchangeCompanyConnection()->first()) { $this->createIdentificationDocumentOnExchangeProcessor->execute($request, $companyModule->id); } return $this->response([]); } }