public PasargadPayResponse CheckPayment(long invoiceNumber, string transactionReferenceID, string invoiceDate) { string strXML = ReadPaymentResult(transactionReferenceID); var res = new PasargadPayResponse(); //در صورتی که تراکنشی انجام نشده باشد فایلی از بانک برگشت داده نمی شود //دستور شزطی زیر جهت اعلام نتیجه به کاربر است if (strXML == "") { res.Result = false; res.TraceNumber = "تراکنش انجام نشد "; } else { XmlDocument oXml = new XmlDocument(); oXml.LoadXml(strXML); //xmlResult.Document = oXml; XmlElement oElResult = (XmlElement)oXml.SelectSingleNode("//result"); //نتیجه تراکنش XmlElement _oElTraceNumber = (XmlElement)oXml.SelectSingleNode("//traceNumber"); //شماره پیگیری XmlElement _TXNreferenceNumber = (XmlElement)oXml.SelectSingleNode("//referenceNumber"); //شماره ارجاع res.Result = Boolean.Parse(oElResult.InnerText); if (res.Result) { res.TraceNumber = _oElTraceNumber.InnerText; res.ReferenceNumber = _TXNreferenceNumber.InnerText; } } return(res); }
public PasargadPayResponse VerifyPasargadPayment(long payreqPayReqId, double payreqPayReqValue, string invoicetime) { var res = new PasargadPayResponse(); var amount = payreqPayReqValue * 10; //convert to rial string timeStamp = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); string invoiceDate = invoicetime; string invoiceNumber = payreqPayReqId.ToString(); RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); rsa.FromXmlString(PrivateKey); string data = "#" + MerchantCode + "#" + TerminalCode + "#" + invoiceNumber + "#" + invoiceDate + "#" + amount + "#" + timeStamp + "#"; byte[] signedData = rsa.SignData(Encoding.UTF8.GetBytes(data), new SHA1CryptoServiceProvider()); string signedString = Convert.ToBase64String(signedData); HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://pep.shaparak.ir/VerifyPayment.aspx"); string text = "InvoiceNumber=" + invoiceNumber + "&InvoiceDate=" + invoiceDate + "&MerchantCode=" + MerchantCode + "&TerminalCode=" + TerminalCode + "&Amount=" + amount + "&TimeStamp=" + timeStamp + "&Sign=" + signedString; byte[] textArray = Encoding.UTF8.GetBytes(text); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = textArray.Length; request.GetRequestStream().Write(textArray, 0, textArray.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream()); string result = reader.ReadToEnd(); if (result == "") { res.Result = false; res.ResultMessage = "تراکنش انجام نشد "; } else { XmlDocument oXml = new XmlDocument(); oXml.LoadXml(result); //xmlResult.DocumentContent = result; XmlElement oElResult = (XmlElement)oXml.SelectSingleNode("//result"); //نتیجه تراکنش XmlElement msg = (XmlElement)oXml.SelectSingleNode("//resultMessage"); //شماره پیگیری res.ResultMessage = msg.InnerText; res.Result = Boolean.Parse(oElResult.InnerText); } return(res); }