21 private static $successResponseCodes = [200, 201, 204];
26 private static $phpVersionId = PHP_VERSION_ID;
33 private static $failureResponses = [
34 400 =>
'Bad Request - The request could not be parsed. Response: %s',
35 401 =>
'Unauthorized - user is not logged in, could not be authenticated. Response: %s',
36 403 =>
'Forbidden - Cannot access resource. Response: %s',
37 404 =>
'Not Found - resource does not exist. Response: %s',
38 409 =>
'Conflict - with state of the resource on server. Can occur with (too rapid) PUT requests. Response: %s',
39 500 =>
'Server error. Response: %s' 47 private static $unexpectedResponse =
'Unexpected Signifyd API response code "%s" with content "%s".';
62 $this->dataDecoder = $dataDecoder;
76 if (!in_array($responseCode, self::$successResponseCodes)) {
77 $errorMessage = $this->buildApiCallFailureMessage(
$response);
81 $responseBody = (string)
$response->getBody();
83 if (self::$phpVersionId < 70000 && empty($responseBody)) {
88 throw new ApiCallException(
'Response is not valid JSON: Decoding failed: Syntax error');
92 $decodedResponseBody = $this->dataDecoder->decode($responseBody);
93 }
catch (\Exception $e) {
95 'Response is not valid JSON: ' . $e->getMessage(),
101 return $decodedResponseBody;
114 if (key_exists(
$response->getStatus(), self::$failureResponses)) {
115 return sprintf(self::$failureResponses[
$response->getStatus()], $responseBody);
119 self::$unexpectedResponse,
__construct(DecoderInterface $dataDecoder)
handle(\Zend_Http_Response $response)