protected function encodeParameters($parameters, $keyPrefix = null)
    {
        if (!is_array($parameters) && !is_object($parameters)) {
            return rawurlencode($parameters);
        }

        $encodedData = [];

        foreach ($parameters as $key => $value) {
            $encodedKey = is_null($keyPrefix) ? rawurlencode($key) : $keyPrefix.'['.rawurlencode($key).']';

            if (is_array($value) || is_object($value)) {
                $encodedData[] = $this->encodeParameters($value, $encodedKey);
            } else {
                $encodedData[] = $encodedKey.'='.rawurlencode($value);
            }
        }

        return implode('&', $encodedData);
    }