'Approve Document', 'message' => 'You have successfully approved the Document' ]; } /** @var CanApproveDocument*/ private $canApproveDocument; /** @var ApprovesDocument */ private $approvesDocument; /** @var RejectsDocument */ private $rejectsDocument; /** @var FetchesDocument */ private $fetchesDocument; /** @var UpdatesCompanyStatus */ private $updatesCompanyStatus; /** @var UpdatesOrdersStatus */ private $updatesOrdersStatus; /** @var CreateNotificationProcessor */ private $createNotificationProcessor; /** @var ApproveIdentificationDocumentOnExchangeProcessor */ private $approveIdentificationDocumentOnExchangeProcessor; /** * ApproveIdentificationDocumentLogic constructor. * @param CanApproveDocument $canApproveDocument * @param ApprovesDocument $approvesDocument * @param RejectsDocument $rejectsDocument * @param FetchesDocument $fetchesDocument * @param UpdatesCompanyStatus $updatesCompanyStatus * @param UpdatesOrdersStatus $updatesOrdersStatus * @param CreateNotificationProcessor $createNotificationProcessor * @param ApproveIdentificationDocumentOnExchangeProcessor $approveIdentificationDocumentOnExchangeProcessor */ public function __construct(CanApproveDocument $canApproveDocument, ApprovesDocument $approvesDocument, RejectsDocument $rejectsDocument, FetchesDocument $fetchesDocument, UpdatesCompanyStatus $updatesCompanyStatus, UpdatesOrdersStatus $updatesOrdersStatus, CreateNotificationProcessor $createNotificationProcessor, ApproveIdentificationDocumentOnExchangeProcessor $approveIdentificationDocumentOnExchangeProcessor) { $this->canApproveDocument = $canApproveDocument; $this->approvesDocument = $approvesDocument; $this->rejectsDocument = $rejectsDocument; $this->fetchesDocument = $fetchesDocument; $this->updatesCompanyStatus = $updatesCompanyStatus; $this->updatesOrdersStatus = $updatesOrdersStatus; $this->createNotificationProcessor = $createNotificationProcessor; $this->approveIdentificationDocumentOnExchangeProcessor = $approveIdentificationDocumentOnExchangeProcessor; } /** * @param Request $request * @return JsonResponse * @throws \App\Classes\Exceptions\AccessForbiddenException * @throws \App\Classes\Exceptions\MalformedRequestException * @throws \App\Classes\Exceptions\RequestValidationException */ public function logic(Request $request) : JsonResponse { $documentId = $request->route('document_id'); if ($request->route('exchange_company_id')) { $companyModule = ExchangeCompanyConnection::where('exchange_company_id', $request->route('exchange_company_id'))->first()->companyModule; $company = $companyModule->company; $documentId = $company->documents()->whereIn('document_type', DocumentType::IDENTIFICATION_DOCUMENTS)->where('status', ApprovalStatus::PENDING_VERIFICATION)->first()->id; } $status = $request->route('status'); /** @var Document $document */ $document = $this->fetchesDocument->execute(['id' => $documentId]); $this->canApproveDocument->passes(); $document = $status === 'approve' ? $this->approvesDocument->execute($document) : $this->rejectsDocument->execute($document); $this->updatesCompanyStatus->execute($document->owner, $status === 'approve' ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED); // $object = new NotificationObject( // 'ID Verification ' . ( $status === 'approve' ? 'Approved' : 'Rejected' ), // ( $status === 'approve' ? 'Dear user, congratulations that your ' : 'Dear user, we are sorry to inform you that your ' ) . ( $document->type === 'IDENTITY_CARD' ? 'IC' : 'SSM' ) . ( $status === 'approve' ? ' has been approved. Start your first order now!' : ' has been rejected due to ' . ( $request->input('rejectRemark') ?? '' ) . ', please resubmit it for further action.' ), // $document->owner, // $document->owner->companyModules()->first()->employees()->first(), // $document, // ); // // $this->createNotificationProcessor->execute($object); if($status === 'approve'){ $orders = $this->updatesOrdersStatus->execute($document->owner, ApprovalStatus::APPROVED); } // if this request is not calling from exchange portal, then approve the document on exchange portal for this user $companyModule = $document->owner->companyModules()->first(); if (!$request->route('exchange_company_id') && $companyModule->exchangeCompanyConnection()->first()) { $this->approveIdentificationDocumentOnExchangeProcessor->execute($request, $companyModule->id, $status); } return $this->resourceResponse(new DocumentResource($document)); } }