Get the response for a failed user verification.

@param  \Illuminate\Http\Request
@param  string $response
@return \Illuminate\Http\RedirectResponse
492590
protected function sendVerificationFailedResponse(Request $request, $response)
    {
        return redirect($this->redirectPath())->with('error', trans($response));
    }
338195
protected function getStatus($response)
    {
        if (isset($response['refunded']) && $response['refunded'] == true) {
            return new Status('refunded');
        }

        if (!isset($response['status']) && !isset($response['type'])) {
            return;
        }

        $status = isset($response['status']) ? $response['status'] : $response['type'];

        switch ($status) {
            case 'pending':
            case 'charge.pending':
                return new Status('pending');
            case 'success':
            case 'charge.success':
                return new Status('paid');
            case 'declined':
            case 'charge.declined':
                return new Status('failed');
            case 'deleted':
            case 'charge.deleted':
                return new Status('canceled');
            case 'expired':
            case 'charge.expired':
                return new Status('voided');
                break;
        }
    }
968238
private function whenSuccess($response, $method)
    {
        $this->makeSession($response, $method);
        return $this->result->setData([
            'success' => true,
            'payload' => [
                'redirect' => sprintf('%s%s', $this->baseUrl(), 'pagseguro/direct/success')
            ]
        ]);
    }
993151
public function failureAction(Request $request)
    {
        $orderId = $request
            ->query
            ->get('id', false);

        $failureRoute = $this
            ->redirectionRoutes
            ->getRedirectionRoute('failure');

        $redirectUrl = $this
            ->urlGenerator
            ->generate(
                $failureRoute->getRoute(),
                $failureRoute->getRouteAttributes(
                    $orderId
                )
            );

        return new RedirectResponse($redirectUrl);
    }
483684
private function captchaResponse($response)
    {
        $errors = ['g-recaptcha-response' => ['Oops, something went wrong']];
        foreach ($response->getErrorCodes() as $k => $code) {
            if ($code == 'missing-input-response') {
                $code = 'Please confirm you are not a robot.';
            }
            $errors['g-recaptcha-response'][$k] = $code;
        }

        return new JsonResponse($errors, 422);
    }
50690
public function handleResponse($response)
    {
        // recursion for batch
        if (is_array($response)) {
            $response_arr = array();
            foreach ($response as $res) {
                $response_arr[$res->id] = $this->handleResponse($res);
            }
            return $response_arr;
        }

        // return error response
        if (property_exists($response, 'error')) {
            return new Response(null, $response->id, $response->error->code, $response->error->message);
        }

        // return successful response
        return new Response($response->result, $response->id);
    }
187222
protected function respond($response)
    {
        $success = Arr::get($response, 'success');

        return $this->mapResponse($success, $response);
    }
1065864
private static function handleErrors($response)
    {
        switch ($response->getStatusCode()) {
            case 200:
                return json_decode($response->getBody());
                break;
            case 401:
                throw new UnauthorizedException('Unauthorized (Invalid API key or insufficient permissions)');
                break;
            case 404:
                throw new NotFoundException('Object not found within your account scope');
                break;
            case 406:
                throw new InvalidFormatException('Requested format is not supported - request JSON or XML only');
                break;
            case 422:
                throw new ValidationException('Validation error(s) for create or update method');
                break;
            case 500:
                throw new ServerException('Something went wrong on Challonge\'s end');
                break;
            default:
                $decodedResponse = json_decode($response->getBody());
                throw new UnexpectedErrorException($decodedResponse);
                break;
        }
    }
272357
public function getResponseArray($response)
    {
        $return = [];

        if (!($response instanceof Response)) {
            $this->errors[] = [
                // this error is coming from us, not the Chargify API response
                'source'    => 'client',
                'attribute' => null,
                'kind'      => 'networking',
                'message'   => 'no response'
            ];

            return $return;
        }

        /**
         * add error for bad status codes
         */
        $code       = $response->getStatusCode();
        $errorCodes = [404, 401, 500];
        if (in_array($code, $errorCodes)) {
            $this->errors[] = [
                // this error is coming from us, not the Chargify API response
                'source'    => 'client',
                'attribute' => null,
                'kind'      => 'status_code',
                'message'   => 'Bad status code: ' . $code
            ];
        }

        $body = $response->getBody();
        $body = trim((string)$body);

        /**
         * Return early if we have an empty body, which we can't turn into an array
         * anyway. This happens in cases where the API returns a 404, and possibly
         * other status codes.
         */
        if (empty($body)) {
            return $return;
        }

        $return = json_decode($body, true);

        // set errors, if any
        if (!empty($return['result']['errors'])) {
            foreach ($return['result']['errors'] as $error) {
                $this->errors[] = $error;
            }
        }

        /**
         * NOTE: There is also, maybe, an errors array nested in $return['meta']['errors']
         *       Why is this API so inconsistent???!!!!!
         */

        return $return;
    }
930661
public function detect($response)
    {
        if (stripos($response, '<error>') === false) {
            return $response;
        }

        $error = preg_replace('/^.*<error>([^<]+)<\/error>.*$/ims', '$1', $response);

        switch ($error) {
            case 'Banned':
                throw BannedException::banned();
            case 'Anime not found':
                throw NotFoundException::anime();
            default:
                throw ErrorException::error($error);
        }
    }
697075
public function validateRequest(RequestInterface $request, ResponseInterface $response)
    {
        if (!$request->request('code')) {
            $response->setError(400, 'invalid_request', 'Missing parameter: "code" is required');

            return false;
        }

        $code = $request->request('code');
        if (!$authCode = $this->storage->getAuthorizationCode($code)) {
            $response->setError(400, 'invalid_grant', 'Authorization code doesn\'t exist or is invalid for the client');

            return false;
        }

        /*
         * 4.1.3 - ensure that the "redirect_uri" parameter is present if the "redirect_uri" parameter was included in the initial authorization request
         * @uri - http://tools.ietf.org/html/rfc6749#section-4.1.3
         */
        if (isset($authCode['redirect_uri']) && $authCode['redirect_uri']) {
            if (!$request->request('redirect_uri') || urldecode($request->request('redirect_uri')) != urldecode($authCode['redirect_uri'])) {
                $response->setError(400, 'redirect_uri_mismatch', "The redirect URI is missing or do not match", "#section-4.1.3");

                return false;
            }
        }

        if (!isset($authCode['expires'])) {
            throw new \Exception('Storage must return authcode with a value for "expires"');
        }

        if ($authCode["expires"] < time()) {
            $response->setError(400, 'invalid_grant', "The authorization code has expired");

            return false;
        }

        if (!isset($authCode['code'])) {
            $authCode['code'] = $code; // used to expire the code after the access token is granted
        }

        $this->authCode = $authCode;

        return true;
    }
1039320
public function mapResponse($success, $response)
    {
        return (new Response())->setRaw($response)->map([
            'isRedirect'    => false,
            'success'       => $success,
            'reference'     => $success ? '12345' : null,
            'message'       => $success ? 'Approved' : 'Error',
            'test'          => false,
            'authorization' => $success ? '123' : '',
            'status'        => $success ? new Status('paid') : new Status('failed'),
            'errorCode'     => $success ? false : new ErrorCode('card_declined'),
            'type'          => 'charge',
        ]);
    }
767988
public function verify($response)
    {
        $result = $this->getVerificationResult($response);

        if ($result['success']) {
            return true;
        }

        if (!empty($result['error-codes'])) {
            $this->errors = $result['error-codes'];
        }

        return false;
    }
1158597
public function mapResponse($success, $response)
    {
        return (new Response())->setRaw($response)->map([
            'isRedirect'    => false,
            'success'       => $success,
            'reference'     => $success ? $response['id'] : null,
            'message'       => $success ? 'Transaction approved' : Arr::get($response, 'message'),
            'test'          => $this->getTest($response),
            'authorization' => $success ? $this->getAuthorization($response) : false,
            'status'        => $success ? $this->getStatus($response) : new Status('failed'),
            'errorCode'     => $success ? null : $this->getErrorCode(Arr::get($response, 'code')),
            'type'          => array_key_exists('type', $response) ? Arr::get($response, 'type') : Arr::get($response, 'object'),
        ]);
    }
71098
protected function needVerification(ResponseInterface $response)
    {
        return $response->getStatusCode() === static::WAIT_RESPONSE_CODE
            && in_array($response->getHeaderLine('Server'), static::SERVER_NAME, true);
    }
281370
public function mapResponse($success, $response)
    {
        return (new Response())->setRaw($response)->map([
            'isRedirect'    => false,
            'success'       => true,
            'reference'     => null,
            'message'       => null,
            'test'          => false,
            'authorization' => null,
            'status'        => $response['status'],
            'errorCode'     => false,
            'type'          => $response['type'],
        ]);
    }
469071
public function run(Request $request, Response $response) : Response {

		$strict = $this->getParam('STRICT_ROUTING');
		$case = $this->getParam('CASE_SENSITIVE');
		$method = $request->getMethod();
		$url = $request->getUri()->getPath();

		//Matching
		foreach($this->routes as $route) {
			if($route->match($url, $strict, $case) && $method == $route->getMethod()) {
				return $route->call($request, $response);
			} elseif($route->match($url, $strict, $case) && $method == 'HEAD') {
				$body = $response->getBody();
				$body->close();
				$response = $response->withBody($body);
				return $response;
			}
		}

		//Error
		$methods = array();
		foreach($this->routes as $route) {
			array_push($methods, $route->getMethod());
			if($route->match($url, $strict, $case) && $method != $route->getMethod() && in_array($method, self::$_METHODS))
				return call_user_func($this->httpErrors['405'], $request, $response);

			elseif($route->match($url, $strict, $case) && $method != $route->getMethod() && !in_array($method, self::$_METHODS))
				return call_user_func($this->httpErrors['400'], $request, $response);
		}

		if(!in_array($method, $methods) && !in_array($method, self::$_METHODS))
			return call_user_func($this->httpErrors['400'], $request, $response);
		else
			return call_user_func($this->httpErrors['404'], $request, $response);
		
	}