/// <summary> /// This function needs to process and returned message from the bank. /// Thsi processing may vary widely between banks. /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { var modCtrl = new NBrightBuyController(); var info = ProviderUtils.GetProviderSettings("NBrightBuySipsApipayment"); try { var debugMode = info.GetXmlPropertyBool("genxml/checkbox/debugmode"); var rtnMsg = "version=2" + Environment.NewLine + "cdr=1"; // ------------------------------------------------------------------------ // In this case the payment provider passes back data via form POST. // Get the data we need. string returnmessage = ""; int NBrightBuySipsApiStoreOrderID = 0; string NBrightBuySipsApiCartID = ""; string NBrightBuySipsApiClientLang = ""; if ((context.Request.Form.Get("DATA") != null)) { returnmessage = "message=" + context.Request.Form.Get("DATA"); if (!string.IsNullOrEmpty(returnmessage)) { // ------------------------------------------------------------------------ var settings = ProviderUtils.GetProviderSettings("NBrightBuySipsApipayment"); var controlMapPath = HttpContext.Current.Server.MapPath("/DesktopModules/NBright/NBrightBuySipsApi"); var pathfile = "pathfile=" + PortalSettings.Current.HomeDirectoryMapPath.TrimEnd('\\') + "\\" + settings.GetXmlProperty("genxml/textbox/paramfolder") + "\\pathfile"; var exepath = controlMapPath.TrimEnd('\\') + "\\sipsbin\\response.exe"; var sipsdata = ProviderUtils.CallSipsExec(exepath, pathfile + " " + returnmessage); if (debugMode) { info.SetXmlProperty("genxml/debugmsg", sipsdata); modCtrl.Update(info); } var tableau = sipsdata.Split('!'); string code = tableau[1]; string error_msg = tableau[2]; if (string.IsNullOrEmpty(code) | code == "-1") { info.SetXmlProperty("genxml/debugmsg", error_msg); modCtrl.Update(info); } else { // L'execution s'est bien deroulee // recuperation des donnees de la reponse string merchant_id = tableau[3]; string merchant_country = tableau[4]; string amount = tableau[5]; string transaction_id = tableau[6]; string payment_means = tableau[7]; string transmission_date = tableau[8]; string payment_time = tableau[9]; string payment_date = tableau[10]; string response_code = tableau[11]; string payment_certificate = tableau[12]; string authorisation_id = tableau[13]; string currency_code = tableau[14]; string card_number = tableau[15]; string cvv_flag = tableau[16]; string cvv_response_code = tableau[17]; string bank_response_code = tableau[18]; string complementary_code = tableau[19]; string complementary_info = tableau[20]; string return_context = tableau[21]; string caddie = tableau[22]; string receipt_complement = tableau[23]; string merchant_language = tableau[24]; string language = tableau[25]; string customer_id = tableau[26]; string order_id = tableau[27]; string customer_email = tableau[28]; string customer_ip_address = tableau[29]; string capture_day = tableau[30]; string capture_mode = tableau[31]; string data = tableau[32]; // Sauvegarde des champs de la reponse string Lmsg = null; Lmsg = merchant_id + ","; Lmsg += merchant_country + ","; Lmsg += amount + ","; Lmsg += transaction_id + ","; Lmsg += transmission_date + ","; Lmsg += payment_means + ","; Lmsg += payment_time + ","; Lmsg += payment_date + ","; Lmsg += response_code + ","; Lmsg += payment_certificate + ","; Lmsg += authorisation_id + ","; Lmsg += currency_code + ","; Lmsg += card_number + ","; Lmsg += cvv_flag + ","; Lmsg += cvv_response_code + ","; Lmsg += bank_response_code + ","; Lmsg += complementary_code + ","; Lmsg += complementary_info + ","; Lmsg += return_context + ","; Lmsg += caddie + ","; Lmsg += receipt_complement + ","; Lmsg += merchant_language + ","; Lmsg += language + ","; Lmsg += customer_id + ","; Lmsg += order_id + ","; Lmsg += customer_email + ","; Lmsg += customer_ip_address + ","; Lmsg += capture_day + ","; Lmsg += capture_mode + ","; Lmsg += data + ","; //update database stuff if (Utils.IsNumeric(order_id)) { var orderData = new OrderData(Convert.ToInt32(order_id)); orderData.AddAuditMessage(Lmsg, "payment", "sipsapi", info.GetXmlProperty("genxml/checkbox/debugmode")); // Status return "00" is payment successful if (response_code == "00") { //set order status to Payed orderData.PaymentOk(); } else { orderData.PaymentFail(); } } } } } } catch (Exception ex) { if (!ex.ToString().StartsWith("System.Threading.ThreadAbortException")) // we expect a thread abort from the End response. { info.SetXmlProperty("genxml/debugmsg", "NBrightBuySipsApi ERROR: " + ex.ToString()); modCtrl.Update(info); } } }
public static String GetBankRemotePost(OrderData orderData) { var rPost = new RemotePost(); var settings = ProviderUtils.GetProviderSettings("NBrightBuySipsApipayment"); var appliedtotal = orderData.PurchaseInfo.GetXmlPropertyDouble("genxml/appliedtotal"); var alreadypaid = orderData.PurchaseInfo.GetXmlPropertyDouble("genxml/alreadypaid"); var orderTotal = Regex.Replace((appliedtotal - alreadypaid).ToString("0.00"), "[^0-9]", ""); var controlMapPath = HttpContext.Current.Server.MapPath("/DesktopModules/NBright/NBrightBuySipsApi"); var pathfile = PortalSettings.Current.HomeDirectoryMapPath.TrimEnd('\\') + "\\" + settings.GetXmlProperty("genxml/textbox/paramfolder") + "\\pathfile"; var transid = Convert.ToDateTime(orderData.PurchaseInfo.ModifiedDate).Ticks.ToString(); transid = transid.Substring(transid.Length - 6); var parms = ""; parms = "pathfile=\"" + pathfile + "\" "; parms += "merchant_id=" + settings.GetXmlProperty("genxml/textbox/merchant_id") + " "; parms += "merchant_country=" + settings.GetXmlProperty("genxml/textbox/merchant_country") + " "; parms += "amount=" + orderTotal + " "; parms += "currency_code=" + settings.GetXmlProperty("genxml/textbox/currency_code") + " "; parms += "transaction_id=" + transid + " "; parms += "payment_means=" + settings.GetXmlProperty("genxml/textbox/payment_means") + " "; parms += "order_id=" + orderData.PurchaseInfo.ItemID.ToString("") + " "; var param = new string[3]; param[0] = "orderid=" + orderData.PurchaseInfo.ItemID.ToString(""); param[1] = "status=1"; var storeSettings = new StoreSettings(orderData.PortalId); var sUrlOk = Globals.NavigateURL(storeSettings.PaymentTabId, "", param); param[1] = "status=0"; var sUrlKo = Globals.NavigateURL(storeSettings.PaymentTabId, "", param); parms += "normal_return_url=" + sUrlOk + " "; parms += "cancel_return_url=" + sUrlKo + " "; var baseUri = new Uri("http://" + PortalSettings.Current.PortalAlias.HTTPAlias); var absoluteUri = new Uri(baseUri, "/DesktopModules/NBright/NBrightBuySipsApi/notify.ashx"); parms += "automatic_response_url=" + absoluteUri + " "; parms += "language=" + orderData.Lang.Substring(0, 2) + " "; if (settings.GetXmlPropertyBool("genxml/checkbox/debugmode")) { File.WriteAllText(PortalSettings.Current.HomeDirectoryMapPath + "\\debug_NBrightBuySipsApiparams.html", parms); } var exepath = controlMapPath.TrimEnd('\\') + "\\sipsbin\\request.exe"; var sipsdata = CallSipsExec(exepath, parms); var tableau = sipsdata.Split('!'); string code = ""; code = tableau[1]; string errorMsg = tableau[2]; if (code.Equals("") | code.Equals("-1")) { return(errorMsg); } var htmlOutput = tableau[3]; var aryResult = htmlOutput.Split('"'); var sipsUrl = aryResult[1]; var sipsData = aryResult[5]; rPost.Url = sipsUrl; rPost.Add("DATA", sipsData); // must be uppercase. // just force CB payment. (CB must be in the list of payment_means) rPost.Add("CB.x", "5"); rPost.Add("CB.y", "5"); // save here (may chnage lang field) orderData.AddAuditMessage(transid, "sisptransid", "sipsapi", "True"); orderData.Save(); //Build the re-direct html var rtnStr = rPost.GetPostHtml("/DesktopModules/NBright/NBrightBuySipsApi/Themes/config/img/" + settings.GetXmlProperty("genxml/textbox/imagelogo")); if (settings.GetXmlPropertyBool("genxml/checkbox/debugmode")) { File.WriteAllText(PortalSettings.Current.HomeDirectoryMapPath + "\\debug_NBrightBuySipsApihtmlOutput.html", htmlOutput); File.WriteAllText(PortalSettings.Current.HomeDirectoryMapPath + "\\debug_NBrightBuySipsApipost.html", rtnStr); } return(rtnStr); }