private static void AddRequiredHeaders(HttpClient client, string commerceCode, string apiKey, RequestServiceHeaders headers)
        {
            var header = new MediaTypeWithQualityHeaderValue(CONTENT_TYPE);

            client.DefaultRequestHeaders.Accept.Add(header);
            client.DefaultRequestHeaders.Add(headers.CommerceCodeHeaderName, commerceCode);
            client.DefaultRequestHeaders.Add(headers.ApiKeyHeaderName, apiKey);
        }
        private static HttpRequestMessage CreateHttpRequestMessage(BaseRequest request, String jsonRequest, Options options, RequestServiceHeaders requestServiceHeaders)
        {
            var message = new HttpRequestMessage(request.Method, new Uri(options.IntegrationType.ApiBase + request.Endpoint));

            if (request.Method != HttpMethod.Get)
            {
                message.Content = new StringContent(jsonRequest, Encoding.UTF8, CONTENT_TYPE);
            }
            AddRequiredHeaders(message, options.CommerceCode, options.ApiKey, requestServiceHeaders);
            return(message);
        }
        public ReturnType Perform <ReturnType, ExceptionType>(BaseRequest request, Options options, RequestServiceHeaders requestServiceHeaders)
            where ExceptionType : TransbankException
            where ReturnType : BaseResponse
        {
            var jsonRequest = JsonConvert.SerializeObject(request);
            var resp        = Perform <ExceptionType>(CreateHttpRequestMessage(request, jsonRequest, options, requestServiceHeaders));
            var result      = JsonConvert.DeserializeObject <ReturnType>(String.IsNullOrWhiteSpace(resp) ? "{}" : resp);

            result.OriginalRequest  = jsonRequest;
            result.OriginalResponse = resp;
            return(result);
        }
 private static void AddRequiredHeaders(HttpRequestMessage request, string commerceCode, string apiKey, RequestServiceHeaders headers)
 {
     request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(CONTENT_TYPE));
     request.Headers.Add(headers.CommerceCodeHeader, commerceCode);
     request.Headers.Add(headers.ApiKeyHeader, apiKey);
 }