Verifies if a given MAC in a response object is valid

@param Response $response
@throws \opus\payment\Exception
166986
public function verifyResponseMac(Response $response)
    {
        $mac = $this->generateMacKey($response, 'payment_response');

        /** @noinspection SpellCheckingInspection */
        if ($mac !== $response->getParam('SOLOPMT_RETURN_MAC')) {
            /** @noinspection SpellCheckingInspection */
            $params = [
                'SOLOPMT_RETURN_VERSION' => $response->getParam('SOLOPMT_RETURN_VERSION'),
                'SOLOPMT_RETURN_STAMP' => $response->getParam('SOLOPMT_RETURN_STAMP'),
                'SOLOPMT_RETURN_REF' => $response->getParam('SOLOPMT_RETURN_REF'),
                'SOLOPMT_RETURN_PAID' => $response->getParam('SOLOPMT_RETURN_PAID'),
                'SOLOPMT_RETURN_MAC' => $response->getParam('SOLOPMT_RETURN_MAC'),
                'generated_mac' => $mac,
            ];
            throw new Exception('BankNet-> Incorrect signature. (' . implode(',', $params) . ')');
        }
    }
22086
private function enforcePreconditions(Response $response) : void
    {
        $result = $this->preconditionValidator->validate($response);

        if (!$result->isValid()) {
            throw PreconditionNotMetException::createFromValidationResult($result);
        }
    }
69693
protected function assertResponseCode($response, $wanted)
    {
        if (!$response) {
            $this->throwException(new Swift_TransportException('Expected response code '.implode('/', $wanted).' but got an empty response'));
        }

        list($code) = sscanf($response, '%3d');
        $valid = (empty($wanted) || in_array($code, $wanted));

        if ($evt = $this->eventDispatcher->createResponseEvent($this, $response,
            $valid)) {
            $this->eventDispatcher->dispatchEvent($evt, 'responseReceived');
        }

        if (!$valid) {
            $this->throwException(new Swift_TransportException('Expected response code '.implode('/', $wanted).' but got code "'.$code.'", with message "'.$response.'"', $code));
        }
    }
1183736
protected function processResponse(Response $response)
    {
        if ($response->hasErrors()) {
            throw new \Exception($this->getErrorMessage($response));
        }

        return is_array($response->body) ? $response->body['data'] : $response->body->data;
    }
1073633
public static function mapResponseCodeToException(Response $response)
	{
		switch ($response->getCode()) {
			case Response::CODE_03: {
				return new DeclinedSystemErrorException($response);
			}

			case Response::CODE_05: {
				return new CustomerContactBankException($response);
			}

			case Response::CODE_31: {
				return new CardInvalidException($response);
			}

			case Response::CODE_33:
			case Response::CODE_AC: {
				return new CardExpiredException($response);
			}

			case Response::CODE_51: {
				return new InsufficientFundsException($response);
			}

			case Response::CODE_91: {
				return new BankNotAvailableException($response);
			}

			case Response::CODE_0C: {
				return new InvalidDecimalPlacementException($response);
			}

			case Response::CODE_0M: {
				return new InvalidClientIdException($response);
			}

			case Response::CODE_A6: {
				return new ServerBusyException($response);
			}

			case Response::CODE_A8: {
				return new InvalidRefundException($response);
			}

			case Response::CODE_AE: {
				return new TimeoutException($response);
			}

			case Response::CODE_IN: {
				return new InitializedException($response);
			}

			case Response::CODE_IP: {
				return new InProgressException($response);
			}

			case Response::CODE_VA: {
				return new ValidationFailureException($response);
			}

			case Response::CODE_Y3: {
				return new UnableToProcessException($response);
			}

			/**
			 * A blank string is included here as the Webpay library doesn't seem to return the -1 code
			 * to this library, regardless of what is output in the log file.
			 */
			case '':
			case Response::CODE_LOCAL_ERROR: {
				switch ($response->getError()) {
					case 'Unable to initialise SSL': {
						return new InitializeSSLException($response);
					}

					case 'Unable to negotiate SSL': {
						return new NegotiateSSLException($response);
					}

					case 'Unable to connect to server': {
						return new ConnectionException($response);
					}

					case 'Unable to process': {
						return new ProcessException($response);
					}

					default: {
						return new Exceptions\ResponseCodes\LocalErrors\Exception($response);
					}
				}
			}

			default: {
				return new Exception($response);
			}
		}
	}
1153798
public function validateResponse(Response $response)
	{
		$xml = simplexml_load_string($response->body);

		if (isset($xml->warnings))
		{
			throw new \DomainException($xml->warnings->info);
		}

		if (isset($xml->error))
		{
			throw new \DomainException($xml->error['info']);
		}

		return $xml;
	}
62456
protected function isValidResponse($response)
    {
        if (empty($this->acceptable)) {
            return true;
        }

        if ($this->acceptableIsClosure()) {
            return call_user_func($this->acceptable, $response);
        }

        return $this->isAcceptableResponse($response);
    }
621593
private function checkException($response)
    {
        if ((true === $this->getThrowExceptions()) and ($this->isErroneousResponse($response))) {
            throw new ClientException($response->detail, $response->status);
        }
        return $response;
    }
877283
private function decodeResponse(string $response)
    {
        if (strpos($response, '!') !== false) {
            throw new \Exception($response);
        }

        return new BotScoutResponse($response);
    }
710190
protected function isJsonEncodable($response) : bool
    {
        if ($response instanceof ResponseInterface) {
            return false;
        }

        return (is_array($response) || is_object($response));
    }
512901
public function validateLogoutResponse(LogoutResponse $response)
    {
        $this->validateIssuer($response);

        if ($this->hasSignature($response)) {
            $this->validateSignature(
                $response,
                KeyHelper::createPublicKey(
                    $this->getMetadata()->getFirstIdpSsoDescriptor()
                        ->getFirstKeyDescriptor(KeyDescriptor::USE_SIGNING)
                        ->getCertificate()
                )
            );
        }
    }
13852
public static function parseResponse(Response $response)
    {
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
        if (
            (isset($jsonData['errCode']) && 0 === $jsonData['errCode'])
            || (isset($jsonData['retcode']) && 0 === $jsonData['retcode'])
        ) {
            return true;
        }
        if (isset($jsonData['retcode']) && 103 === $jsonData['retcode']) {
            throw new Code103ResponseException($response);
        }

        return false;
    }
1311666
public function isAuthorise($response){
        $result = false;
        $hasError = $this->isError($response);
        $isApprove = $this->isApprove($response);

        if(!$hasError && $isApprove){
            $result = true;
        }

        return $result;
    }
468853
protected function checkResponse(Response $response)
    {
        $status = $response->getStatusCode();
        $reason = $response->getReasonPhrase();
        switch ($status) {
            case '403':
                throw new Exceptions\GeocodioAuthError($reason);
                break;

            case '422':
                throw new Exceptions\GeocodioDataError($reason);
                break;

            case '500':
                throw new Exceptions\GeocodioServerError($reason);
                break;

            case '200':
                return $response;
                break;

            default:
                throw new Exceptions\GeocodioException("There was a problem with your request - $reason");
                break;
        }
    }
684467
private function validateResponse( $response ) {

		// Make sure WordPress errors are handled.
		if ( is_wp_error( $response ) ) {
			$this->error = $response->get_error_message();
			return false;
		}

		// Check for 200 response code from server.
		$responseCode = wp_remote_retrieve_response_code( $response );
		if ( false === strstr( $responseCode, '200' ) ) {
			$responseMessage = wp_remote_retrieve_response_message( $response );
			$this->error = "{$responseCode} {$responseMessage}";
			return false;
		}

		// Check for nested status code not being successful.
		if ( isset( $this->response->status ) && 200 !== $this->response->status ) {
			$this->error = $this->response->result->data;
			return false;
		}

		return true;
	}
634183
protected function validateResponse($response)
    {
        if ('Failure' == $response['ACK']) {
            /**
             * @var \OxidEsales\PayPalModule\Core\Exception\PayPalResponseException $exception
             */
            $exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalResponseException::class, $response['L_LONGMESSAGE0'], $response['L_ERRORCODE0']);
            throw $exception;
        }
    }
1246170
protected function evaluateResponse(array $response) {
        if (array_key_exists('error', $response) &&
            $response['error'] !== null) {
            // Validate error object:
            if (!is_array($response['error'])) {
                throw new RuntimeException('Invalid error object');
            }

            if (!array_key_exists('code', $response['error']) ||
                !is_int($response['error']['code']) ||
                $response['error']['code'] >= 0) {
                throw new RuntimeException('Invalid error code');
            }

            if (!array_key_exists('message', $response['error']) ||
                !is_string($response['error']['message']) ||
                strlen($response['error']['message']) === 0) {
                throw new RuntimeException('Invalid error message');
            }

            $details = [];

            if (array_key_exists('data', $response['error']) &&
                is_array($response['error']['data'])) {
                foreach ($response['error']['data'] as $topic => $description) {
                    $text = 'unknown';

                    switch (gettype($description)) {
                        case 'array':
                            $text = implode('; ', $description);
                            break;
                        case 'string':
                            $text = $description;
                            break;
                    }

                    $details[] = sprintf(
                        '%s: %s',
                        $topic,
                        $text
                    );
                }
            }

            if (count($details) > 0) {
                $message = sprintf(
                    'i-doit responded with an error: %s [%s]',
                    $response['error']['message'],
                    implode('; ', $details)
                );
            } else {
                $message = sprintf(
                    'i-doit responded with an error: %s',
                    $response['error']['message']
                );
            }

            throw new RuntimeException(
                $message,
                $response['error']['code']
            );
        }

        if (!array_key_exists('result', $response)) {
            throw new RuntimeException('i-doit forgot to add a result to its response.');
        }

        return $this;
    }