public void Apply(ApiRequest request) { request.Plain.MerchantId = Credentials.MerchantId; request.Plain.Salt = SaltProvider.Generate(); string scriptPath = request.Endpoint.GetScriptPath(); List<string> values = _valueProvider.GetValuesToSign(request.Plain); request.Plain.Signature = Sign(scriptPath, values); }
private string GetQueryString(ApiRequest request) { string xml = _xmlPipeline.Serialize(request); List<KeyValuePair<string, string>> values = GetQueryStringValues(xml); string query; using (var content = new FormUrlEncodedContent(values)) { query = content.ReadAsStringAsync().Result; } return query; }
public HttpRequestMessage Encode(ApiRequest request) { var message = new HttpRequestMessage(); switch (EncodingType) { case HttpRequestEncodingType.Get: message.Method = HttpMethod.Get; message.RequestUri = new Uri($"{request.Endpoint}?{GetQueryString(request)}", UriKind.Relative); return message; case HttpRequestEncodingType.PostWithQueryString: message.Method = HttpMethod.Post; message.RequestUri = new Uri($"{request.Endpoint}?{GetQueryString(request)}", UriKind.Relative); return message; case HttpRequestEncodingType.PostWithXml: message.Method = HttpMethod.Post; message.RequestUri = request.Endpoint; message.Content = new FormUrlEncodedContent( new[] {new KeyValuePair<string, string>("pg_xml", _xmlPipeline.Serialize(request))}); return message; default: throw new ArgumentOutOfRangeException(nameof(EncodingType), EncodingType, "Encoding not implemented"); } }