public PaymentServiceProvider DelegatePaymentServiceProvider(PaymentProviders paymentProvider) { if (paymentProvider.Equals(PaymentProviders.CheapPaymentService)) { return(new CheapPaymentService()); } else if (paymentProvider.Equals(PaymentProviders.ExpensivePaymentService)) { return(new ExpensivePaymentService()); } else if (paymentProvider.Equals(PaymentProviders.PremiumPaymentService)) { return(new PremiumPaymentService()); } else { throw new ArgumentException("The PaymentProvider received is not valid"); } }
string GetPaymentURL(PaymentProviders paymentProviders, string strFullName, string strEmail) { using (var client = new HttpClient()) { string strCartID = $"PL{(new Random()).Next()}{DateTime.Now.ToFileTime()}"; if (paymentProviders == PaymentProviders.PayTabs) { var tmp = new PayTabPageResponse(); client.BaseAddress = new Uri("https://www.paytabs.com/apiv2/"); client.DefaultRequestHeaders.ExpectContinue = false; var result = client.PostAsync("create_pay_page", new FormUrlEncodedContent(new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("merchant_email", "*****@*****.**"), new KeyValuePair <string, string>("secret_key", "qfGUoC0uMa7Lstz7rlz5n2jwxMI0cffDuWxTyxnlIv7aYGip1SvpUOWrBFsNUIrpEYidwGzebGpanIzpA5OuTLWvqpjl7KLMJ40f"), new KeyValuePair <string, string>("site_url", "https://localhost:44314"), new KeyValuePair <string, string>("return_url", "https://localhost:44314"), new KeyValuePair <string, string>("title", "Bill To Blatinum Package"), new KeyValuePair <string, string>("cc_first_name", strFullName), new KeyValuePair <string, string>("cc_last_name", strFullName), new KeyValuePair <string, string>("cc_phone_number", "00966"), new KeyValuePair <string, string>("phone_number", "123569854"), new KeyValuePair <string, string>("email", strEmail), new KeyValuePair <string, string>("products_per_title", "Product"), new KeyValuePair <string, string>("unit_price", "100"), new KeyValuePair <string, string>("quantity", "1"), new KeyValuePair <string, string>("other_charges", "0"), new KeyValuePair <string, string>("amount", "100"), new KeyValuePair <string, string>("discount", "0"), new KeyValuePair <string, string>("currency", "SAR"), new KeyValuePair <string, string>("reference_no", strCartID), new KeyValuePair <string, string>("ip_customer", System.Net.Dns.GetHostName()), new KeyValuePair <string, string>("ip_merchant", "100.100.100.100"), new KeyValuePair <string, string>("billing_address", "billing address"), new KeyValuePair <string, string>("state", "state here"), new KeyValuePair <string, string>("city", "Cite here"), new KeyValuePair <string, string>("postal_code", "25698"), new KeyValuePair <string, string>("country", "SAU"), new KeyValuePair <string, string>("shipping_first_name", "Shipping First Name"), new KeyValuePair <string, string>("shipping_last_name", "Shipping Last Name"), new KeyValuePair <string, string>("address_shipping", "address shipping"), new KeyValuePair <string, string>("city_shipping", "city shipping"), new KeyValuePair <string, string>("state_shipping", "state shipping"), new KeyValuePair <string, string>("postal_code_shipping", "postal code shipping"), new KeyValuePair <string, string>("country_shipping", "SAU"), new KeyValuePair <string, string>("msg_lang", "Arabic"), new KeyValuePair <string, string>("cms_with_version", "API") })).Result; if (result.IsSuccessStatusCode) { dynamic data = (result.Content.ReadAsStringAsync().Result); tmp = JsonConvert.DeserializeObject <PayTabPageResponse>(data); if (tmp.payment_url != "") { return(tmp.payment_url); //Set Payment Active URL to session // var activeClient = (Models.Settings)Session["ActiveClient"]; var CurrentActivePaymentID = tmp.payment_url; var LastPaymentReferenceNumber = tmp.p_id; //Helper.PayTabsSession.PageRequestList = new List<Models.PayPageRequest>(); //objrequest.PaymentReference = tmp.p_id; //var paymentList = new Models.PaymentsList(); //paymentList.PayPageRequests = new List<Models.PayPageRequest>(); //if (HttpRuntime.Cache["PAYTABS_PAYMENTS"] != null) //{ // paymentList = HttpRuntime.Cache["PAYTABS_PAYMENTS"] as Models.PaymentsList; // //Remove the Old // HttpRuntime.Cache.Remove("PAYTABS_PAYMENTS"); //} //paymentList.PayPageRequests.Add(objrequest); //HttpRuntime.Cache.Insert("PAYTABS_PAYMENTS", paymentList, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(60)); //Helper.PayTabsSession.PageRequestList.Add(objrequest); ////Redirect to Hosted Page //Response.Redirect("~/ClientHost.aspx"); } } else { var x = result; } } if (paymentProviders == PaymentProviders.TelrPay) { client.BaseAddress = new Uri("https://secure.telr.com/"); client.DefaultRequestHeaders.ExpectContinue = false; var result = client.PostAsync("gateway/order.json", new FormUrlEncodedContent(new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("ivp_method", "create"), new KeyValuePair <string, string>("ivp_store", "23236"), new KeyValuePair <string, string>("ivp_authkey", "St3GP^Bjx4q~GvtM"), new KeyValuePair <string, string>("ivp_cart", strCartID), new KeyValuePair <string, string>("ivp_desc", "Test Desc"), new KeyValuePair <string, string>("ivp_test", "1"), new KeyValuePair <string, string>("ivp_amount", "5"), new KeyValuePair <string, string>("ivp_currency", "SAR"), new KeyValuePair <string, string>("return_auth", "https://localhost:44314"), new KeyValuePair <string, string>("return_can", "https://localhost:44314"), new KeyValuePair <string, string>("return_decl", "https://localhost:44314"), new KeyValuePair <string, string>("bill_title", "MR"), new KeyValuePair <string, string>("bill_fname", strFullName), new KeyValuePair <string, string>("bill_sname", strFullName), new KeyValuePair <string, string>("bill_addr1", "Test"), new KeyValuePair <string, string>("bill_city", "Cairo"), //new KeyValuePair<string, string>("bill_region","Maharashtra"), new KeyValuePair <string, string>("bill_country", "SA"), //new KeyValuePair<string, string>("bill_zip", "400002"), new KeyValuePair <string, string>("bill_email", strEmail), //new KeyValuePair<string,string>("ivp_update_url","www.urdomain.com"), new KeyValuePair <string, string>("ivp_framed", "2") })).Result; if (result.IsSuccessStatusCode) { dynamic data = (result.Content.ReadAsStringAsync().Result); data = JsonConvert.DeserializeObject(data).ToString(); string[] arrayResponse = data.Split(':'); string[] arr = arrayResponse[4].Split('\"'); string val = arr[1]; // Access variables from the returned JSON object //var appHref = data.links.applications.href; //Session["RefNO"] = val; string IFrameURL = "https://secure.telr.com/gateway/process_framed_full.html?o={val}"; string URL = $"https://secure.telr.com/gateway/process.html?o={val}"; return(val); //Response.Redirect(URL); } else { var x = result; } } return(""); } }