private Dictionary <string, string> PearToPear(string sessionXML, bool bEncrypt, string Action) { Dictionary <string, string> PeerReturns = new Dictionary <string, string>(); string UserAgent = "Mozilla/4.0"; var hashedData = Cryptographer.ConvertToSHA256(sessionXML); encodedData = "VERSION=" + Version + "&PWD=" + WebUtility.UrlDecode(Password) + "&MERCHANTID=" + MerchantId + "&KEY=" + Key + "&HASH=" + hashedData; if (bEncrypt) { encodedData = encodedData + "&ENINVOICE=" + Cryptographer.EncryptInvoice(sessionXML); } else { encodedData = encodedData + "&PTINVOICE=" + sessionXML; } dataToPost = Encoding.UTF8.GetBytes(encodedData); // Create a new HttpWebRequest object. HttpWebRequest request2 = (HttpWebRequest)WebRequest.Create(API_URL); request2.UserAgent = UserAgent; request2.ContentType = "application/x-www-form-urlencoded"; request2.ContentLength = dataToPost.Length; // Set the Method property to 'POST' to post data to the URI. request2.Method = "POST"; // start the asynchronous operation request2.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request2); // Keep the main thread from continuing while the asynchronous // operation completes. A real world application // could do something useful such as updating its user interface. allDone.WaitOne(); //Break the return values by char '&' var dicVariables = GenaralHelpers.BreakResponseString(responseString); var errorCode = dicVariables.ToList().Find(a => a.Key == "ERROR_CODE").Value; if (errorCode == "000") { //Extract UUID from the Data budnle. these lines can be writen in same line. but for demostration purpose we keep it separated PeerReturns = GenaralHelpers.ReadFromXmlString(dicVariables.ToList().Find(a => a.Key == "PTRECEIPT").Value, Action); } else { PeerReturns.Add("ERROR_CODE", errorCode); } //PeerReturns.Add("ipay_out__txn_uuid", UUID); //PeerReturns.Add("ipay_out__ipg_txn_id", UUID); return(PeerReturns); }
public Dictionary <string, string> saleTxnVerify() { string Action = ""; string MerRefID = ""; string TxnUUID = ""; Action = (Session["ipay_in__action"] != null) ? Session["ipay_in__action"].ToString() : "saleTxnVerify"; MerRefID = (Session["ipay_in__mer_ref_id"] != null) ? Session["ipay_in__mer_ref_id"].ToString() : ""; TxnUUID = (Session["ipay_out__txn_uuid"] != null) ? Session["ipay_out__txn_uuid"].ToString() : ""; string PTInvoice = "<req>" + "<mer_id>" + MerchantId + "</mer_id>" + "<mer_txn_id>" + MerRefID + "</mer_txn_id>" + "<txn_uuid>" + TxnUUID + "</txn_uuid>" + "<action>" + Action + "</action>"; PTInvoice = PTInvoice + "</req>"; var byteArray = Encoding.UTF8.GetBytes(PTInvoice); var finalHex = Cryptographer.ByteArrayToString(byteArray); return(PearToPear(finalHex, false, "saleTxnVerify")); }
public Dictionary <string, string> saleTxn() { Dictionary <string, string> SalesData = new Dictionary <string, string>(); string Action = ""; string CurrencyCode = ""; string MerRefID = ""; string TxnAmount = ""; string LanguageCode = ""; string ReturnURL = ""; string MerVar1 = ""; string MerVar2 = ""; string MerVar3 = ""; string MerVar4 = ""; Action = (Session["ipay_in__action"] != null) ? Session["ipay_in__action"].ToString() : ""; CurrencyCode = (Session["ipay_in__cur"] != null) ? Session["ipay_in__cur"].ToString() : ""; MerRefID = (Session["ipay_in__mer_ref_id"] != null) ? Session["ipay_in__mer_ref_id"].ToString() : ""; TxnAmount = (Session["ipay_in__txn_amt"] != null) ? Session["ipay_in__txn_amt"].ToString() : ""; LanguageCode = (Session["ipay_in__lang"] != null) ? Session["ipay_in__lang"].ToString() : ""; ReturnURL = (Session["ipay_in__ret_url"] != null) ? Session["ipay_in__ret_url"].ToString() : ""; MerVar1 = (Session["ipay_in__mer_var1"] != null) ? Session["ipay_in__mer_var1"].ToString() : ""; MerVar2 = (Session["ipay_in__mer_var2"] != null) ? Session["ipay_in__mer_var2"].ToString() : ""; MerVar3 = (Session["ipay_in__mer_var3"] != null) ? Session["ipay_in__mer_var3"].ToString() : ""; MerVar4 = (Session["ipay_in__mer_var4"] != null) ? Session["ipay_in__mer_var4"].ToString() : ""; string PTInvoice = "<req>" + "<mer_id>" + MerchantId + "</mer_id>" + "<mer_txn_id>" + MerRefID + "</mer_txn_id>" + "<action>" + Action + "</action>" + "<txn_amt>" + TxnAmount + "</txn_amt>" + "<cur>" + CurrencyCode + "</cur>" + "<lang>" + LanguageCode + "</lang>"; if ((ReturnURL != null) && (ReturnURL.Length > 0)) { PTInvoice = PTInvoice + "<ret_url>" + ReturnURL + "</ret_url>"; } if ((MerVar1 != null) && (MerVar1.Length > 0)) { PTInvoice = PTInvoice + "<mer_var1>" + MerVar1 + "</mer_var1>"; } if ((MerVar2 != null) && (MerVar2.Length > 0)) { PTInvoice = PTInvoice + "<mer_var2>" + MerVar2 + "</mer_var2>"; } if ((MerVar3 != null) && (MerVar3.Length > 0)) { PTInvoice = PTInvoice + "<mer_var3>" + MerVar3 + "</mer_var3>"; } if ((MerVar4 != null) && (MerVar4.Length > 0)) { PTInvoice = PTInvoice + "<mer_var4>" + MerVar4 + "</mer_var4>"; } PTInvoice = PTInvoice + "</req>"; var byteArray = Encoding.UTF8.GetBytes(PTInvoice); var finalHex = Cryptographer.ByteArrayToString(byteArray); return(PearToPear(finalHex, false, "SaleTxn")); }