Map Conekta response to error code object.

@param array $response

@return \Shoperti\PayMe\ErrorCode
347187
protected function getErrorCode($response)
    {
        $code = isset($response['details']) ? $response['details'][0]['code'] : null;

        switch ($code) {
            case 'conekta.errors.processing.bank.declined':
            case 'conekta.errors.processing.bank_bindings.declined':
                return new ErrorCode('card_declined');

            case 'conekta.errors.processing.bank.insufficient_funds':
            case 'conekta.errors.processing.bank_bindings.insufficient_funds':
                return new ErrorCode('insufficient_funds');

            case 'conekta.errors.processing.charge.card_payment.suspicious_behaviour':
                return new ErrorCode('suspected_fraud');

            case 'conekta.errors.parameter_validation.expiration_date.expired':
                return new ErrorCode('invalid_expiry_date');

            case 'conekta.errors.parameter_validation.card.number':
                return new ErrorCode('invalid_number');

            case 'conekta.errors.parameter_validation.card.cvc':
                return new ErrorCode('invalid_cvc');
        }

        $code = Arr::get($response, 'type');

        return new ErrorCode($code === 'processing_error' ? $code : 'config_error');
    }
550867
public function convertMap(Response $response)
    {
        $value = $response->value;
        $map   = new RiakMap($value);

        return $map;
    }
536585
public function error(RESTfulAPIError $error)
    {
        $answer = new HTTPResponse();

        $body = $this->serializer->serialize($error->body);
        $answer->setBody($body);

        $answer->setStatusCode($error->code, $error->message);
        $answer->addHeader('Content-Type', $this->serializer->getcontentType());

        $answer = $this->setAnswerCORS($answer);

        // save controller's response then return/output
        $this->response = $answer;

        return $answer;
    }
301190
public static function failedCompletelyException($response)
    {
        $message = '';
        foreach ($response as $key => $item) {
            if ($item['status'] === 'error') {
                $message .= $key == 0? "" : "\r\n";
                $message .= $item['message'];
            }
        }

        return new static($message);
    }
1250956
protected function wrapResponse($response)
    {
        $statusCode = 200;
        $headers = [];

        if (false !== (strpos($response, "\r\n\r\n")) && false !== strpos($this->scheme, 'http')) {
            list($responseHeaders, $response) = explode("\r\n\r\n", $response, 2);
            $responseHeaders = preg_split('/\r\n/', $responseHeaders, null, PREG_SPLIT_NO_EMPTY);

            $code = array_shift($responseHeaders);
            list(, $statusCode) = explode(' ', $code);
            $headers = [];
            array_map(function ($headerLine) use (&$headers) {
                list($key, $value) = explode(':', $headerLine, 2);
                $headers[$key] = trim($value);
                unset($headerLine, $key, $value);
            }, $responseHeaders);

            if (isset($headers['Content-Encoding'])) {
                $response = zlib_decode($response);
            }
            unset($responseHeaders, $code);
        }

        return new Response($response, $statusCode, $headers);
    }
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'),
        ]);
    }
377080
public function mapResponse($success, $response)
    {
        $rawResponse = $response;

        if (array_key_exists('type', $response) && isset($response['data']['object'])) {
            $response = $response['data']['object'];
        }

        return (new Response())->setRaw($rawResponse)->map([
            'isRedirect'      => false,
            'success'         => $success,
            'reference'       => $success ? $response['id'] : Arr::get($response['error'], 'charge', 'error'),
            'message'         => $success ? 'Transaction approved' : $response['error']['message'],
            'test'            => array_key_exists('livemode', $response) ? !$response['livemode'] : false,
            'authorization'   => $success ? Arr::get($response, 'balance_transaction', '') : false,
            'status'          => $success ? $this->getStatus(Arr::get($response, 'paid', true)) : new Status('failed'),
            'errorCode'       => $success ? null : $this->getErrorCode($response['error']),
            'type'            => array_key_exists('type', $rawResponse) ? $rawResponse['type'] : Arr::get($rawResponse, 'object'),
        ]);
    }
528506
public function checkResponse(array $response)
    {
        $exception = $responses = null;

        if (isset($response['responseCode'])) {
            $responses = explode(',', $response['responseCode']);
        }

        if (isset($response['response_code'])) {
            $responses = explode(',', $response['response_code']);
        }

        if (isset($responses)) {
            foreach ($responses as $code) {
                if (!in_array($code, [100])) {
                    $exception = new LimeLightCRMTransactionException($code, $exception, $response);
                }
            }
        }

        if (isset($exception)) {
            throw $exception;
        }
    }
177417
protected function validateResponse($response)
    {
        if (isset($response->code) && isset($response->message)) {
            if ($response->code == $this->validResponseCode &&
                $response->message == $this->validResponseMessage
            ) {
                // serial keys are valid
                $valid = true;
            } else {
                // serial keys are not valid
                $this->setErrorMessage(\OxidEsales\Eshop\Core\Registry::getLang()->translateString('OLC_ERROR_SERIAL_NOT_VALID'));
                $valid = false;
            }
        } else {
            // validation result is unknown
            throw new \OxidEsales\Eshop\Core\Exception\StandardException('OLC_ERROR_RESPONSE_NOT_VALID');
        }

        return $valid;
    }
63602
protected function respond($response)
    {
        if (!isset($response[0])) {
            $success = !(array_key_exists('type', $response) && $response['type'] == 'error')
                && !(array_key_exists('status', $response) && $response['status'] == 'error');

            return $this->mapResponse($success, $response);
        }

        $responses = [];

        foreach ($response as $responds) {
            $success = !(array_key_exists('type', $response) && $response['type'] == 'error')
                && !(array_key_exists('status', $response) && $response['status'] == 'error');

            $responses[] = $this->mapResponse($success, $responds);
        }

        return $responses;
    }
1149691
public function mapResponse($success, $response)
    {
        $authorization = Arr::get($response['result']['recipe'], 'authorization_code');
        $type = $this->getType($response);
        $transaction = Arr::get($response['result'], 'transaction');

        if ($success) {
            $message = 'Transaction approved';
        } else {
            $message = Arr::get($response['error'], 'message');
        }

        return (new Response())->setRaw($response)->map([
            'isRedirect'    => false,
            'success'       => $success,
            'reference'     => $transaction,
            'message'       => $message,
            'test'          => $this->isTest,
            'authorization' => $authorization,
            'status'        => $success ? new Status('authorized') : new Status('failed'),
            'errorCode'     => $success ? null : $this->getErrorCode($response),
            'type'          => $type,
        ]);
    }
933681
protected function respond($success, $response)
    {
        if (Arr::get($response, 'object') !== 'list') {
            $success = (!array_key_exists('error', $response));

            return $this->mapResponse($success, $response);
        }

        $responses = [];

        foreach ($response['data'] as $responds) {
            $success = (!array_key_exists('error', $responds));

            $responses[] = $this->mapResponse($success, $responds);
        }

        return $responses;
    }
274022
public function response(array $errors)
    {
        if (($this->ajax() && ! $this->pjax()) || $this->wantsJson()) {
            return new JsonResponse($errors, ValidationException::VALIDATION_FAILED);
        }

        return $this->redirector->to($this->getRedirectUrl())
            ->withInput($this->except($this->dontFlash))
            // This makes errors display properly (original errors are placed under the key 'errors' instead of 'error')
            ->with('error', $this->getValidatorInstance()->getMessageBag());
    }
65577
protected function handleError($response) {
    $errorMsg = $response->getValue('errorMsg');
    self::$logger->error("Error in remote call to ".$this->serverCli.": ".$errorMsg."\n".$response->toString());
    throw new \RuntimeException("Error in remote call to ".$this->serverCli.": ".$errorMsg);
  }
329426
protected function fetchResponseError($response)
	{
		if (isset($response['error-code'])) {
			return [
				'code' => $response['error-code'],
				'message' => $response['message'],
			];
		} else if (isset($response['errorCode'])) {
			return [
				'code' => $response['errorCode'],
				'message' => $response['message'],
			];
		}
		return null;
	}
1139716
public function error(array $errors): Response
    {
        $this->response->setStatus(500);
        $bodyTemplate = '<html><title>Error 500</title><h1>Server Error</h1><pre>%s</pre></html>';
        $this->response->setBody(sprintf($bodyTemplate, print_r($errors, true)));
        return $this->response;
    }
808354
public function packetResponse(array $response = null)
    {

        // Act as setter
        if (!empty($response)) {
            $this->packets_response = $response;
        }

        return $this->packets_response;
    }