protected function generateServiceResponse(
        $flags,
        $omnipayData = null
    ) {
        $response = new ServiceResponse($this->payment, $flags);

        if ($omnipayData) {
            $response->setOmnipayResponse($omnipayData);
        }

        // redirects and notifications don't need a target URL.
        if (!$response->isNotification() && !$response->isRedirect()) {
            $response->setTargetUrl(
                ($response->isError() || $response->isCancelled())
                    ? $this->payment->FailureUrl
                    : $this->payment->SuccessUrl
            );
        }

        // Hook to update service response via extensions. This can be used to customize the service response
        ErrorHandling::safeExtend($this, 'updateServiceResponse', $response);

        return $response;
    }