public PaymentResponse PreAuthorize(Transaction authTrans) { string signature = GetSignature(TransactionViewModel.New(authTrans), Settings.MerchantCode, Settings.MerchantKey); Dictionary <string, object> postData = new Dictionary <string, object>(); postData.Add("Ds_Merchant_TransactionType", GetType(ETransactionType.Preauthorization)); postData.Add("Ds_Merchant_MatchingData", authTrans.TransactionIDExt); postData.Add("Ds_Merchant_MerchantCode", Settings.MerchantCode); postData.Add("Ds_Merchant_Amount", authTrans.Amount.ToString("N2").Replace(".", string.Empty)); postData.Add("Ds_Date", authTrans.Resolved.ToString(GATEWAY_DATE_FORMAT)); postData.Add("Ds_Merchant_PanMask", authTrans.PanMask); postData.Add("Ds_Merchant_MerchantSignature", signature); postData.Add("Ds_Merchant_InitialAmount", authTrans.Amount.ToString("N2").Replace(".", string.Empty)); postData.Add("Ds_Merchant_Currency", GetCurrency(authTrans.ECurrency)); string url = Settings.ApiOperationHost; PaymentResponse response = Remote(url, postData); return(response); }
protected PaymentResponse Remote(string url, Dictionary <string, object> postParameters) { HttpWebResponse response = null; try { HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckCertification); StringBuilder postParams = WebFace.Helpers.PostCaller.GetPostDataString(postParameters); request.Method = "POST"; request.ContentLength = postParams.Length; request.ContentType = "application/x-www-form-urlencoded"; request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; request.Headers.Add("CURLOPT_POST", "1"); request.Headers.Add("CURLOPT_HEADER", "false"); request.Headers.Add("CURLOPT_USERAGENT", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"); request.Headers.Add("CURLOPT_RETURNTRANSFER", "true"); request.Headers.Add("CURLOPT_TIMEOUT", "45"); request.Headers.Add("CURLOPT_FOLLOWLOCATION", "false"); request.Headers.Add("CURLOPT_SSL_VERIFYPEER", "true"); request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; request.Headers.Add("Accept-Encoding", "gzip,deflate,sdch"); request.Headers.Add("Accept-Language", "es-ES,es;q=0.8"); request.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3"); // send the request StreamWriter oStreamWriter = new StreamWriter(request.GetRequestStream()); oStreamWriter.Write(postParams.ToString()); oStreamWriter.Close(); // get the response response = (HttpWebResponse)request.GetResponse(); } catch (WebException ex) { StreamReader str = new StreamReader(ex.Response.GetResponseStream()); PaymentResponse presponse = new PaymentResponse() { Status = EStatus.Error, ServerResponse = str.ReadToEnd() }; str.Close(); string message = String.Format("URL: {0}", url) + System.Environment.NewLine + String.Format("RESPONSE: {0}", presponse.ServerResponse) + System.Environment.NewLine + String.Format("PARAMETERS: {0}", postParameters.ToString()); presponse.Message = message; molLogger.LogError(ex, message); return(presponse); } return(ParseXMLResponse(response)); }