service = $service; $this->actionRenderer = $actionRenderer; } /** * @throws BadRequest * @throws Error * @throws NotFound */ public function run(Request $request, Response $response): void { $id = $request->getQueryParam('id'); if (!$id) { throw new BadRequest(); } $result = $this->service->confirmOptIn($id); $action = null; if ($result->getStatus() === ConfirmResult::STATUS_EXPIRED) { $action = 'optInConfirmationExpired'; } if ($result->getStatus() === ConfirmResult::STATUS_SUCCESS) { $action = 'optInConfirmationSuccess'; } if (!$action) { throw new LogicException(); } $data = [ 'status' => $result->getStatus(), 'message' => $result->getMessage(), 'leadCaptureId' => $result->getLeadCaptureId(), 'leadCaptureName' => $result->getLeadCaptureName(), ]; $params = new ActionRenderer\Params('controllers/lead-capture-opt-in-confirmation', $action, $data); $this->actionRenderer->write($response, $params); } }