string certificatePath = @"f:\ctqc_certificate\qcct.p12"; var certBytes = File.ReadAllBytes(certificatePath); X509Certificate2 cert = new X509Certificate2(certBytes, "password"); var url = "https://payments.com"; var req = (HttpWebRequest)WebRequest.Create(url); req.ContentType = "text/xml; charset=utf-8"; req.Method = "POST"; req.Headers.Add("SOAPAction", "\"http://soapaction.com\""); var body = new StringBuilder(); body.AppendLine("<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:pay='http://ctfs.com/paymentSvcsIo/'>"); body.AppendLine("<soapenv:Header/>"); body.AppendLine("<soapenv:Body>"); body.AppendLine("<pay:initializePaymentRequest>"); body.AppendLine("<pay:requestId>" + uniqueRequestId + "</pay:requestId>"); body.AppendLine("<pay:merchantId>MerchantId</pay:merchantId>"); body.AppendLine("<pay:merchantKey>Merchant Key</pay:merchantKey>"); body.AppendLine("<pay:browserIPAddress>127.0.0.1</pay:browserIPAddress>"); body.AppendLine("<pay:paymentType>CREDIT</pay:paymentType>"); body.AppendLine("<pay:transactionType>PURCHASE</pay:transactionType>"); body.AppendLine("<pay:orderNumber>" + string.Format("{0}", id) + "</pay:orderNumber>"); body.AppendLine("<pay:transactionAmount>" + (amount * 100) + "</pay:transactionAmount>"); body.AppendLine("</pay:initializePaymentRequest>"); body.AppendLine("</soapenv:Body>"); body.AppendLine("</soapenv:Envelope>"); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(body.ToString()); req.ClientCertificates.Add(cert); var data = Encoding.ASCII.GetBytes(xmlDoc.InnerXml.ToString()); req.ContentLength = data.Length; Stream newStream = req.GetRequestStream(); newStream.Write(data, 0, data.Length); var response = (HttpWebResponse)req.GetResponse(); var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); token = Regex.Match(responseString, "(.*?)").Groups[1].Value; code-box

Post a Comment

Previous Post Next Post