private void ValidateResultFunction(IOwinContext con, IEnumerable <KeyValuePair <string, string[]> > formData, ref string ret, ref GVPSClient VPClient, Uri successUri, Uri failUri) { //string ret = ""; //var formData = con.Request.ReadFormAsync() as IEnumerable<KeyValuePair<string, string[]>>; var formDataDic = formData.ToDictionary(k => k.Key, e => e.Value); ret += string.Format("\n</br><strong>Method</strong>\n</br>{0}", con.Request.Method); Debug.WriteLine("INCOMING HEADERS"); foreach (var item in con.Request.Headers) { Debug.WriteLine(string.Format("{0}={1}", item.Key, item.Value.FirstOrDefault())); ret += string.Format("\n</br><strong>Header {0}</strong> : {1}", item.Key, System.Net.WebUtility.HtmlEncode(string.Format("{0}", item.Value))); } if (con.Request.Method == "POST") { ret += SelfHost.CreateWebContent(formDataDic); var Result = VPClient.Sales3DEvaluatesResponseAndGetProvision(formDataDic, SecureKey, successUri, failUri); ValidateResult(Result); } }
public void Sale3DTest() { var IsFail = true; string FailMessage = null; var VPClient = new GVPSClient(); Uri successUri = new Uri(HostUri, HostUriSuccessPath); Uri failUri = new Uri(HostUri, HostUriFailPath); var Request = VPClient .Test(true) .Company(TerminalID_For_3D_FULL, MerchandID, ProvUserID_3DS, ProvUserPassword, SubMerchandID) .Customer(customer_email, customer_ipAddress) .CreditCard(credit_card_number_for_3D, credit_card_cvv2_for_3D, credit_card_month_for_3D, credit_card_year_for_3D) .Order("OID" + DateTime.Now.Ticks.ToString()) //.AddOrderAddress(GVPSAddressTypeEnum.Billing, order_address_city, order_address_district, order_address_text, order_address_phone, null, null, order_address_name, order_address_postalCode) //.AddOrderAddress(GVPSAddressTypeEnum.Shipping, order_address_city, order_address_district, order_address_text, order_address_phone, null, null, order_address_name, order_address_postalCode) //.AddOrderItem(1, "0001", "ProductA ğüşiöçĞÜŞİÖÇ", 1.456, 3.456, "product A ğüşiöçĞÜŞİÖÇ description") //.AddOrderItem(2, "0002", "ProductB", 1.4, 1.1, "product B description") //.AddOrderComment(1, "COM1 ğüşiöçĞÜŞİÖÇ") .Amount(95, GVPSCurrencyCodeEnum.TRL) .Sale3DRequest(SecureKey, successUri, failUri); Request.AddInput("", "Gönder", "submit"); var HTML = Request.OuterXml; Debug.WriteLine("Secure 3D Form: " + HTML); var i = SelfHost.Run(HostUri.ToString()) .Listen("/Sales3DTest", (IOwinContext con) => { Debug.WriteLine("REQUEST Sales3DTest"); con.Response.Expires = DateTimeOffset.Now.AddDays(-1); string strRegex = @"<input type=""hidden"" name=""(\w*)"" value=""([\w|\.|\:|\/|\@]*)"" />"; string strReplace = "\n" + @"<div class=""row"">" + "\n" + @"<div class=""col-md-2"">$1</div>" + "\n" + @"<div class=""col-md-2"">$2</div>" + "\n" + @"</div>" + "\n"; Regex myRegex = new Regex(strRegex, RegexOptions.None); HTML = myRegex.Replace(HTML, strReplace).Replace(@"<input type=""submit"" name="""" value=""Gönder"" />", "").Replace("<form", "<div").Replace("</form>", "</div>") + HTML; con.Response.Write(SelfHost.CreateWebContent(HTML, "Sales 3D test page")); }) .Listen(HostUriSuccessPath, async(IOwinContext con) => { Debug.WriteLine("REQUEST " + HostUriSuccessPath); con.Response.Expires = DateTimeOffset.Now.AddDays(-1); var ResponseHTML = ""; try { var formData = await con.Request.ReadFormAsync() as IEnumerable <KeyValuePair <string, string[]> >; ValidateResultFunction(con, formData, ref ResponseHTML, ref VPClient, successUri, failUri); con.Response.Write(SelfHost.CreateWebContent(ResponseHTML, "Sales 3D SUCCESS page")); IsFail = false; } catch (Exception exSuccess) { IsFail = true; FailMessage = exSuccess.ToString(); con.Response.Write(SelfHost.CreateWebContent("<pre>" + exSuccess.ToString() + "</pre>" + ResponseHTML, "Sales 3D INTERNAL ERROR SUCCESS page")); throw; } }) .Listen(HostUriFailPath, async(IOwinContext con) => { Debug.WriteLine("REQUEST " + HostUriFailPath); IsFail = true; var ResponseHTML = ""; try { var formData = (await con.Request.ReadFormAsync() as IEnumerable <KeyValuePair <string, string[]> >); ValidateResultFunction(con, formData, ref ResponseHTML, ref VPClient, successUri, failUri); con.Response.Write(SelfHost.CreateWebContent(ResponseHTML, "Sales 3D FAIL page")); } catch (Exception exFail) { FailMessage = exFail.ToString(); con.Response.Write(SelfHost.CreateWebContent("<pre>" + exFail.ToString() + "</pre>" + ResponseHTML, "Sales 3D INTERNAL ERROR FAIL page")); throw; } }) //.OpenWebClient("/", false) .OpenWebClient("/Sales3DTest") ; Assert.IsFalse(IsFail, FailMessage); //OpenWebUI(HTML, "Sales3DTest"); //var _pay = new GarantiVPClient() // .Test(true) // .Sales3DComplete(Request, Response); //ValidateResult(_pay); //OrderIdForCancel = _pay.Order.OrderID; //OrderRefNumberForCancel = _pay.Transaction.RetrefNum; }
public static SelfHost Run(string url) { instance = new SelfHost(url); instance.Start(); return(instance); }