raw_response_data = $raw_response_data; } /** * Gets the response data. * * @since 2.0.0 * * @return Object */ public function get_data() { return $this->raw_response_data ?: null; } /** * Gets errors returned by the Square API. * * @since 2.0.0 * * @return \stdClass[] */ public function get_errors() { if ( is_array( $this->raw_response_data ) && count( $this->raw_response_data ) > 0 ) { if ( $this->raw_response_data[0] instanceof \Square\Models\Error ) { return $this->raw_response_data; } } return array(); } /** * Determines if the API response contains errors. * * @since 2.0.0 * * @return bool */ public function has_errors() { return ! empty( $this->get_errors() ); } /** * Determines if the API response contains a particular error code. * * @since 2.1.6 * @param $error \Square\Models\Error * @return bool */ public function has_error_code( $error_code ) { foreach ( $this->get_errors() as $error ) { if ( $error_code === $error->getCode() ) { return true; } } return false; } /** * Gets the response data as a string. * * @since 2.0.0 * * @return string */ public function to_string() { $response_data = $this->get_data(); if ( is_callable( array( $response_data, '__toString' ) ) ) { return $this->get_data(); } else if ( is_callable( array( $response_data, 'jsonSerialize' ) ) ) { return wp_json_encode( $response_data, JSON_PRETTY_PRINT ); } return ''; } /** * Gets the response data a string with all sensitive information masked. * * @since 2.0.0 * * @return string */ public function to_string_safe() { return $this->to_string(); } }