public static dynamic AddPlace(NewPlace place) { try { string jsonPlace = new JavaScriptSerializer().Serialize(place); Settings settings = new Settings(); StringBuilder sb = new StringBuilder(settings.Get("PlacesAPIDomain")); sb.Append("add/json?sensor=false"); sb.Append("&key=" + settings.Get("GoogleAPIKey")); byte[] byteArr = Encoding.UTF8.GetBytes(jsonPlace); WebRequest req = WebRequest.Create(sb.ToString()); req.Method = "POST"; req.ContentType = "application/json"; req.ContentLength = byteArr.Length; Stream dataStream = req.GetRequestStream(); dataStream.Write(byteArr, 0, byteArr.Length); dataStream.Close(); WebResponse resp = req.GetResponse(); string resp_status = (((HttpWebResponse)resp).StatusDescription); dataStream = resp.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string returned_resp = reader.ReadToEnd(); AddPlaceResponse formatted_resp = new JavaScriptSerializer().Deserialize<AddPlaceResponse>(returned_resp); return formatted_resp; } catch (Exception) { return "[]"; } }
public string ECDoExpressCheckout(string token, string payerID, string amount, Cart cart) { Settings settings = new Settings(); NVPCallerServices caller = new NVPCallerServices(); IAPIProfile profile = getProfile(); caller.APIProfile = profile; NVPCodec encoder = new NVPCodec(); encoder.Add("VERSION","84.0"); encoder.Add("METHOD","DoExpressCheckoutPayment"); // Add request-specific fields to the request. encoder.Add("TOKEN",token); encoder.Add("PAYERID",payerID); encoder.Add("RETURNURL",getSiteURL() + "Payment/PayPalCheckout"); encoder.Add("CANCELURL",getSiteURL() + "Payment"); encoder.Add("PAYMENTREQUEST_0_AMT",amount); encoder.Add("PAYMENTREQUEST_0_PAYMENTACTION","Sale"); encoder.Add("PAYMENTREQUEST_0_CURRENCYCODE","USD"); encoder.Add("BRANDNAME",settings.Get("SiteName")); encoder.Add("LOGIN","Login"); encoder.Add("HDRIMG",settings.Get("EmailLogo")); encoder.Add("CUSTOMERSERVICENUMBER",settings.Get("PhoneNumber")); encoder.Add("PAYMENTREQUEST_0_SHIPPINGAMT",cart.shipping_price.ToString()); encoder.Add("PAYMENTREQUEST_0_DESC","Your " + settings.Get("SiteName") + " Order"); encoder.Add("ALLOWNOTE","0"); encoder.Add("NOSHIPPING","1"); int count = 0; decimal total = 0; foreach (CartItem item in cart.CartItems) { encoder.Add("L_PAYMENTREQUEST_0_NUMBER" + count, item.partID.ToString()); encoder.Add("L_PAYMENTREQUEST_0_NAME" + count, item.shortDesc); encoder.Add("L_PAYMENTREQUEST_0_AMT" + count, String.Format("{0:N2}", item.price)); encoder.Add("L_PAYMENTREQUEST_0_QTY" + count, item.quantity.ToString()); encoder.Add("L_PAYMENTREQUEST_0_ITEMCATEGORY" + count, "Physical"); encoder.Add("L_PAYMENTREQUEST_0_ITEMURL" + count, settings.Get("SiteURL") + "part/" + item.partID); total += item.price * item.quantity; count++; } encoder.Add("PAYMENTREQUEST_0_TAXAMT", String.Format("{0:N2}", cart.tax)); encoder.Add("PAYMENTREQUEST_0_ITEMAMT", String.Format("{0:N2}", total)); // Execute the API operation and obtain the response. string pStrrequestforNvp = encoder.Encode(); string pStresponsenvp = caller.Call(pStrrequestforNvp); NVPCodec decoder = new NVPCodec(); decoder.Decode(pStresponsenvp); return decoder["ACK"]; }
public static bool ValidateCaptcha(HttpContext ctx, string challenge = "", string apiresponse = "") { bool valid = false; Settings settings = new Settings(); string privatekey = settings.Get("ReCaptchaPrivateKey"); string postdata = "privatekey=" + privatekey + "&challenge=" + challenge + "&response=" + apiresponse + "&remoteip=" + UDF.GetIp(ctx).ToString(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.google.com/recaptcha/api/verify"); request.Method = "POST"; ASCIIEncoding encoding=new ASCIIEncoding(); byte[] postbytes = encoding.GetBytes(postdata); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postdata.Length; Stream postStream = request.GetRequestStream(); postStream.Write(postbytes, 0, postbytes.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); StreamReader reader = new StreamReader(responseStream); string responsestring = reader.ReadToEnd(); postStream.Close(); responseStream.Close(); string[] responselines = responsestring.Split('\n'); valid = Convert.ToBoolean(responselines[0]); return valid; }
public static string GenerateCaptcha(string theme = "clean") { string captcha = ""; Settings settings = new Settings(); string publickey = settings.Get("ReCaptchaPublicKey"); captcha += "<script type=\"text/javascript\">" + "var RecaptchaOptions = { theme : '" + theme + "' };</script>"; captcha += "<script type=\"text/javascript\"" + " src=\"//www.google.com/recaptcha/api/challenge?k=" + publickey + "\">" + "</script>" + "<noscript>" + "<iframe src=\"//www.google.com/recaptcha/api/noscript?k=" + publickey + "\"" + " height=\"300\" width=\"500\" frameborder=\"0\"></iframe><br>" + "<textarea name=\"recaptcha_challenge_field\" rows=\"3\" cols=\"40\">" + "</textarea>" + "<input type=\"hidden\" name=\"recaptcha_response_field\"" + " value=\"manual_challenge\">" + "</noscript>"; return captcha; }
internal void Save() { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); Settings settings = new Settings(); bool RequireCustomerActivation = true; if (settings.Get("RequireCustomerActivation") == "false") { RequireCustomerActivation = false; } // Make sure we don't have an account with this e-mail address Customer cust = this.GetCustomerByEmail(); if (cust != null && cust.ID > 0) { throw new Exception("An account using the E-Mail address you provided already exists."); } // We are going to make an attempt at saving the Customer record Customer new_customer = new Customer { email = this.email, fname = this.fname, lname = this.lname, phone = this.phone, dateAdded = this.dateAdded, isSuspended = this.isSuspended, isValidated = this.isValidated, validator = this.validator, password = this.password, receiveNewsletter = this.receiveNewsletter, receiveOffers = this.receiveOffers, }; if (!RequireCustomerActivation) { new_customer.isValidated = 1; } db.Customers.InsertOnSubmit(new_customer); db.SubmitChanges(); this.ID = new_customer.ID; if (RequireCustomerActivation) { SendValidation(); } }
internal static async Task<List<APIPart>> GetVehiclePartsAsync(string year, string make, string model, string style, int cust_id = 0) { try { Settings settings = new Settings(); WebClient wc = new WebClient(); wc.Proxy = null; string url = getAPIPath(); url += "getparts?dataType=JSON"; url += "&cust_id=" + cust_id; url += "&year=" + year; url += "&make=" + make; url += "&model=" + model; url += "&style=" + style; url += "&cust_id=" + settings.Get("CURTAccount"); Uri targeturi = new Uri(url); var parts_json = await wc.DownloadStringTaskAsync(targeturi); List<APIPart> parts = new List<APIPart>(); parts = JsonConvert.DeserializeObject<List<APIPart>>(parts_json); return parts.OrderByDescending(x => x.pClass).ToList<APIPart>(); } catch (Exception) { return new List<APIPart>(); } }
internal static List<APIPart> GetCategoryParts(int id, int page = 1, int per_page = 10) { try { Settings settings = new Settings(); StringBuilder sb = new StringBuilder(getAPIPath()); sb.Append("GetCategoryParts"); sb.Append("?catID=" + id); sb.Append("&page=" + page); sb.Append("&perpage=" + per_page); sb.Append("&cust_id=" + settings.Get("CURTAccount")); sb.Append("&dataType=JSON"); HttpWebRequest req = WebRequest.Create(sb.ToString()) as HttpWebRequest; req.Proxy = null; HttpWebResponse resp = req.GetResponse() as HttpWebResponse; string json = new StreamReader(resp.GetResponseStream()).ReadToEnd(); List<APIPart> parts = JsonConvert.DeserializeObject<List<APIPart>>(json); return parts; } catch (Exception) { return new List<APIPart>(); } }
internal static List<APIPart> GetConnector(string year, string make, string model, string style) { try { WebClient wc = new WebClient(); wc.Proxy = null; Settings settings = new Settings(); StringBuilder sb = new StringBuilder(); sb.Append(getAPIPath()); sb.Append("GetConnector?dataType=JSON"); sb.Append("&year=" + year); sb.Append("&make=" + make); sb.Append("&model=" + model); sb.Append("&style=" + style); sb.Append("&cust_id=" + settings.Get("CURTAccount")); return JsonConvert.DeserializeObject<List<APIPart>>(wc.DownloadString(sb.ToString())); } catch (Exception e) { return new List<APIPart>(); } }
internal static APIPart GetPart(int p, string year = "", string make = "", string model = "", string style = "") { try { Settings settings = new Settings(); WebClient wc = new WebClient(); wc.Proxy = null; string url = getAPIPath(); url += "GetPart?dataType=JSON"; url += "&partID=" + p; url += "&cust_id=" + settings.Get("CURTAccount"); if (year.Length > 0 && make.Length > 0 && model.Length > 0 && style.Length > 0) { url += "&year=" + year; url += "&make=" + make; url += "&model=" + model; url += "&style=" + style; } return JsonConvert.DeserializeObject<APIPart>(wc.DownloadString(url)); } catch (Exception) { return new APIPart(); } }
internal static void DeletePlaceEntry(string referenceCode = "") { DeletePlace place = new DeletePlace { reference = referenceCode }; string json_reference = new JavaScriptSerializer().Serialize(place); Settings settings = new Settings(); StringBuilder sb = new StringBuilder(settings.Get("PlacesAPIDomain")); sb.Append("delete/json?sensor=false"); sb.Append("&key=" + settings.Get("GoogleAPIKey")); byte[] byteArr = Encoding.UTF8.GetBytes(json_reference); WebRequest req = WebRequest.Create(sb.ToString()); req.Method = "POST"; req.ContentType = "application/json"; req.ContentLength = byteArr.Length; Stream dataStream = req.GetRequestStream(); dataStream.Write(byteArr, 0, byteArr.Length); dataStream.Close(); WebResponse resp = req.GetResponse(); string resp_status = (((HttpWebResponse)resp).StatusDescription); dataStream = resp.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string returned_resp = reader.ReadToEnd(); DeletePlaceResponse response = new JavaScriptSerializer().Deserialize<DeletePlaceResponse>(returned_resp); if (response.status != "OK") { throw new Exception("Failed to delete Google Place listing with error code: " + response.status); } }
public string GetImage() { try { string image = ""; WebClient wc = new WebClient(); wc.Proxy = null; Settings settings = new Settings(); StringBuilder sb = new StringBuilder(settings.Get("CURTAPIDOMAIN")); sb.AppendFormat("GetPart?partID={0}&dataType=JSON", this.partID); string resp = wc.DownloadString(sb.ToString()); APIPart part = Newtonsoft.Json.JsonConvert.DeserializeObject<APIPart>(resp); image = part.images.Where(x => x.size.Equals("Grande") && x.sort.ToString().Contains('a')).Select(x => x.path).FirstOrDefault<string>(); if (image == null) { foreach (APIImage img in part.images) { image = img.path; break; } } return image; } catch (Exception e) { return e.Message; } }
internal static List<APIPart> Search(string term, int page = 1, int per_page = 10) { try { WebClient wc = new WebClient(); wc.Proxy = null; Settings settings = new Settings(); StringBuilder sb = new StringBuilder(); sb.Append(getAPIPath()); sb.Append("PowerSearch?dataType=JSON"); sb.Append("&search_term=" + term); sb.Append("&integrated=false"); sb.Append("&customerID=" + settings.Get("CURTAccount")); return JsonConvert.DeserializeObject<List<APIPart>>(wc.DownloadString(sb.ToString())).Skip((page - 1) * per_page).Take(per_page).ToList<APIPart>(); } catch (Exception) { return new List<APIPart>(); } }
private static string getAPIPath() { Settings settings = new Settings(); string API = settings.Get("CURTAPIDOMAIN"); /*if (isSecure()) { return API.Replace("http:", "https:"); }*/ return API; }
internal void ReadAcknowledgement(string editext) { List<string> purchaseOrderIDs = new List<string>(); Cart order = new Cart(); Settings settings = new Settings(); string EDIPOPreface = settings.Get("EDIPOPreface"); List<string> edilines = editext.Split('~').ToList<string>(); foreach (string line in edilines) { List<string> lineelements = line.Split('*').ToList<string>(); switch (lineelements[0]) { case "AK1": // Original Shipment Number from Shipper string purchaseOrderID = lineelements[2]; if (EDIPOPreface != "") { purchaseOrderID = purchaseOrderID.Replace(EDIPOPreface, ""); } if(!String.IsNullOrWhiteSpace(purchaseOrderID)) { purchaseOrderIDs.Add(purchaseOrderID); } break; } } foreach(string purchaseOrderID in purchaseOrderIDs) { if (!String.IsNullOrWhiteSpace(purchaseOrderID)) { try { order = new Cart().GetByPaymentID(Convert.ToInt32(purchaseOrderID)); order.SetStatus((int)OrderStatuses.Processed); OrderEDI edi = new OrderEDI().GetByOrderID(order.ID); if (edi != null && edi.ID > 0) { edi.SetAcknowledged(); } } catch { } } } }
internal static ShippingResponse GetShipping(FedExAuthentication auth, ShippingAddress origin, ShippingAddress dest, List<int> parts) { ShippingResponse response = new ShippingResponse(); try { WebClient wc = new WebClient(); wc.Proxy = null; Settings settings = new Settings(); wc.Headers["Content-type"] = "application/x-www-form-urlencoded"; string URI = settings.Get("CURTAPISHIPPINGDOMAIN") + "GetShipping"; string parameters = "dataType=JSON"; parameters += "&auth=" + Newtonsoft.Json.JsonConvert.SerializeObject(auth); parameters += "&origin=" + Newtonsoft.Json.JsonConvert.SerializeObject(origin); parameters += "&destination=" + Newtonsoft.Json.JsonConvert.SerializeObject(dest); parameters += "&parts=" + Newtonsoft.Json.JsonConvert.SerializeObject(parts); if (settings.Get("FedExEnvironment") == "development") { parameters += "&environment=development"; } else { parameters += "&environment=production"; } string APIresponse = wc.UploadString(URI, parameters); response = JsonConvert.DeserializeObject<ShippingResponse>(APIresponse); if (response.Status == "ERROR") { throw new Exception("FedEx is having issues at the moment. Please try again."); } } catch (Exception) { } return response; }
internal void CreatePurchaseOrder(int id = 0) { try { Settings settings = new Settings(); Cart order = new Cart().Get(id); Payment payment = order.getPayment(); if (order.CartItems.Count > 0) { Customer cust = new Customer { ID = order.cust_id }; cust.Get(); order.BindAddresses(); string ponumber = settings.Get("EDIPOPreface") + order.payment_id.ToString(); CloudBlockBlob blob = null; string edicontent = ""; int linecount = 1; // linecount is just for the PO section and doesn't include the head or tail // next two lines are head edicontent += "ISA*00* *00* *12*" + settings.Get("EDIPhone") + " *01*809988975 *" + String.Format("{0:yyMMdd}*{0:hhmm}", payment.created) + "*U*00401*" + order.payment_id.ToString("000000000") + "*0*P*>~" + Environment.NewLine; edicontent += "GS*PO*" + settings.Get("EDIPhone") + "*809988975*" + String.Format("{0:yyyyMMdd}*{0:hhmm}", payment.created) + "*" + order.payment_id.ToString("000000000") + "*X*004010~" + Environment.NewLine; // begin PO section edicontent += "ST*850*000000001~" + Environment.NewLine; linecount++; edicontent += "BEG*00*DS*" + ponumber + "**" + String.Format("{0:yyyyMMdd}", payment.created) + "~" + Environment.NewLine; linecount++; edicontent += "CUR*BT*USD~" + Environment.NewLine; linecount++; edicontent += "REF*CO*" + ponumber + "~" + Environment.NewLine; linecount++; edicontent += "REF*IA*" + settings.Get("CURTAccount") + "~" + Environment.NewLine; linecount++; edicontent += "DTM*002*" + String.Format("{0:yyyyMMdd}", payment.created) + "~" + Environment.NewLine; linecount++; edicontent += "N1*ST*" + order.Shipping.first + " " + order.Shipping.last + "~" + Environment.NewLine; linecount++; edicontent += "N3*" + order.Shipping.street1 + ((order.Shipping.street2 != null && order.Shipping.street2 != "") ? "*" + order.Shipping.street2 : "") + "~" + Environment.NewLine; linecount++; edicontent += "N4*" + order.Shipping.city + "*" + order.Shipping.State1.abbr + "*" + order.Shipping.postal_code + "*" + order.Shipping.State1.Country.longAbbr + "~" + Environment.NewLine; if (!String.IsNullOrEmpty(cust.phone)) { linecount++; edicontent += "PER*BD*" + cust.fname + " " + cust.lname + "*TE*" + cust.phone + "~" + Environment.NewLine; } linecount++; edicontent += "PER*BD*" + cust.fname + " " + cust.lname + "*EM*" + cust.email + "~" + Environment.NewLine; linecount++; edicontent += "TD5**2*FDEG*P*" + order.shipping_type + "~" + Environment.NewLine; for (int i = 0; i < order.CartItems.Count; i++) { linecount++; edicontent += "PO1*" + (i + 1).ToString("000") + "*" + order.CartItems[i].quantity + "*EA***BP*" + order.CartItems[i].partID + "*VP*" + order.CartItems[i].partID + "*UP*" + order.CartItems[i].upc + "~" + Environment.NewLine; linecount++; edicontent += "CTP*PUR*" + String.Format("{0:0.00}", order.CartItems[i].price) + "~" + Environment.NewLine; linecount++; edicontent += "PID*F*08***" + order.CartItems[i].shortDesc + "~" + Environment.NewLine; } linecount++; edicontent += "CTT*" + order.CartItems.Count + "*" + order.getCount() + "~" + Environment.NewLine; linecount++; edicontent += "SE*" + linecount + "*000000001~" + Environment.NewLine; // end PO section // begin Tail section edicontent += "GE*1*" + order.payment_id.ToString("000000000") + "~" + Environment.NewLine; edicontent += "IEA*1*" + order.payment_id.ToString("000000000") + "~"; // write file DiscountBlobContainer blobcontainer = BlobManagement.GetContainer("edi"); BlobContainerPermissions perms = new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }; blobcontainer.Container.SetPermissions(perms); string filename = "PO" + String.Format("{0:yyyyMMdd}_{0:HHmmss}", payment.created) + ".txt"; blob = blobcontainer.Container.GetBlockBlobReference("out\\" + filename); byte[] edibytes = Encoding.ASCII.GetBytes(edicontent); MemoryStream edistream = new MemoryStream(edibytes); blob.UploadFromStream(edistream); OrderEDI orderedi = new OrderEDI { orderID = order.ID, editext = edicontent, filename = filename, dateAcknowledged = null, }; orderedi.Save(); } } catch { }; }
internal void ReadShippingNotification(string editext) { string trackingcode = ""; string purchaseOrderID = ""; string shipmentNumber = ""; string weight = ""; Cart order = new Cart(); List<Shipment> shipments = new List<Shipment>(); DateTime shipdate = DateTime.Now; Settings settings = new Settings(); string EDIPOPreface = settings.Get("EDIPOPreface"); List<string> edilines = editext.Split('~').ToList<string>(); foreach (string line in edilines) { List<string> lineelements = line.Split('*').ToList<string>(); switch (lineelements[0]) { case "ST": // Beginning of invoice order = new Cart(); shipments = new List<Shipment>(); weight = ""; break; case "BSN": // Original Shipment Number from Shipper shipmentNumber = lineelements[2]; break; case "PRF": // Purchase Order Reference purchaseOrderID = lineelements[1]; if (EDIPOPreface != "") { purchaseOrderID = purchaseOrderID.Replace(EDIPOPreface, ""); } break; case "REF": // Tracking Code reference trackingcode = lineelements[2]; Shipment shipment = new Shipment { tracking_number = trackingcode }; shipments.Add(shipment); break; case "DTM": shipdate = Convert.ToDateTime(lineelements[2].Substring(4, 2) + "/" + lineelements[2].Substring(6, 2) + "/20" + lineelements[2].Substring(2, 2)); break; case "TD1": weight = lineelements[7] + " " + lineelements[8]; break; case "SE": // End of Invoice try { order = new Cart().GetByPaymentID(Convert.ToInt32(purchaseOrderID)); order.SetStatus((int)OrderStatuses.Shipped); foreach (Shipment s in shipments) { s.order_id = order.ID; s.dateShipped = shipdate; s.shipment_number = shipmentNumber; s.weight = weight; } EcommercePlatformDataContext db = new EcommercePlatformDataContext(); db.Shipments.InsertAllOnSubmit(shipments); db.SubmitChanges(); order.SendShippingNotification(); } catch { } break; } } }
internal void Write() { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); List<int> statuses = new List<int> { (int)OrderStatuses.Void, (int)OrderStatuses.Cancelled, (int)OrderStatuses.AwaitingCancellation, (int)OrderStatuses.Fraudulent, (int)OrderStatuses.PaymentDeclined, (int)OrderStatuses.PaymentPending }; // get all orders with no edi history List<int> orders = (from c in db.Carts join e in db.OrderEDIs on c.ID equals e.orderID into edijoin from ej in edijoin.DefaultIfEmpty() join p in db.Payments on c.payment_id equals p.ID where !statuses.Contains(c.OrderHistories.OrderByDescending(x => x.dateAdded).Select(x => x.statusID).FirstOrDefault()) && ej.orderID == null select c.ID).ToList(); foreach (int order in orders) { Settings settings = new Settings(); if (settings.Get("EDIOrderProcessing") == "true") { CreatePurchaseOrder(order); } else { CreateEDIHistory(order); } } }
public static void getNotification(string serial) { // get Google Order number from serial string ordernum = serial.Split('-')[0]; // create web client WebClient wc = new WebClient(); wc.Proxy = null; // get merchant info from settings Settings settings = new Settings(); string MerchantID = settings.Get("GoogleMerchantId"); string MerchantKey = settings.Get("GoogleMerchantKey"); GCheckout.EnvironmentType env = GCheckout.EnvironmentType.Production; if (HttpContext.Current.Request.Url.Host.Contains("127.0.0") || HttpContext.Current.Request.Url.Host.Contains("localhost") || settings.Get("GoogleCheckoutEnv") == "override") { MerchantID = settings.Get("GoogleDevMerchantId"); MerchantKey = settings.Get("GoogleDevMerchantKey"); env = GCheckout.EnvironmentType.Sandbox; } NotificationHistoryRequest request = new NotificationHistoryRequest(new List<string> {ordernum}); request.MerchantID = MerchantID; request.MerchantKey = MerchantKey; request.Environment = env; request.RetrieveAllNotifications = true; NotificationHistoryResponse response = (NotificationHistoryResponse)request.Send(); // Iterate through the notification history for this order looking for the notification that exactly matches the given serial number foreach (object notification in response.NotificationResponses) { if (notification.GetType().Equals(typeof(GCheckout.AutoGen.NewOrderNotification))) { GCheckout.AutoGen.NewOrderNotification newOrderNotification = (GCheckout.AutoGen.NewOrderNotification)notification; if (newOrderNotification.serialnumber.Equals(serial)) { HandleNewOrderNotification(newOrderNotification); } } else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.OrderStateChangeNotification))) { GCheckout.AutoGen.OrderStateChangeNotification statechange = (GCheckout.AutoGen.OrderStateChangeNotification)notification; if (statechange.serialnumber.Equals(serial)) { HandleOrderStateChangeNotification(statechange); } } else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.RiskInformationNotification))) { GCheckout.AutoGen.RiskInformationNotification riskInformationNotification = (GCheckout.AutoGen.RiskInformationNotification)notification; if (riskInformationNotification.serialnumber.Equals(serial)) { //HandleRiskInformationNotification(riskInformationNotification); } } else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.AuthorizationAmountNotification))) { GCheckout.AutoGen.AuthorizationAmountNotification authorizationAmountNotification = (GCheckout.AutoGen.AuthorizationAmountNotification)notification; if (authorizationAmountNotification.serialnumber.Equals(serial)) { HandleAuthorizationAmountNotification(authorizationAmountNotification); } } else if (notification.GetType().Equals(typeof(GCheckout.AutoGen.ChargeAmountNotification))) { GCheckout.AutoGen.ChargeAmountNotification chargeAmountNotification = (GCheckout.AutoGen.ChargeAmountNotification)notification; if (chargeAmountNotification.serialnumber.Equals(serial)) { HandleChargeAmountNotification(chargeAmountNotification); } } else { //throw new ArgumentOutOfRangeException("Unhandled Type [" + notification.GetType().ToString() + "]!; serialNumber=[" + serial + "];"); } } }
internal void SendValidation() { if (this.isValidated == 1) { throw new Exception("Account is already validated."); } Settings settings = new Settings(); string[] tos = { this.email }; StringBuilder sb = new StringBuilder(); sb.Append("<p>A new account with this e-mail address was created from <a href='" + settings.Get("SiteURL") + "' title='" + settings.Get("SiteName") + "'>" + settings.Get("SiteName") + "</a>.</p>"); sb.Append("<hr />"); sb.AppendFormat("<p>To <a href='" + settings.Get("SiteURL") + "Authenticate/Validate?id={0}&validator={1}' title='Validate' target='_blank'>Validate</a> your account for <a href='" + settings.Get("SiteURL") + "' title='" + settings.Get("SiteName") + "'>" + settings.Get("SiteName") + "</a>, please use the link provided below.</p>", this.ID, this.validator); sb.AppendFormat("<a href='" + settings.Get("SiteURL") + "Authenticate/Validate?id={0}&validator={1}'>" + settings.Get("SiteURL") + "Authenticate/Validate?id={0}&validator={1}</a><hr />", this.ID, this.validator); sb.Append("<hr /><br />"); sb.Append("<p style='font-size:11px'>If you feel this was a mistake please disregard this e-mail.</p>"); UDF.SendEmail(tos, "New Account for " + settings.Get("SiteName"), true, sb.ToString()); }
internal static List<APIPart> GetPartsByList(string partlist = "", string year = "", string make = "", string model = "", string style = "") { Settings settings = new Settings(); WebClient wc = new WebClient(); wc.Proxy = null; string url = getAPIPath(); url += "GetPartsByList?dataType=JSON"; url += "&partlist=" + partlist; url += "&cust_id=" + settings.Get("CURTAccount"); if (year.Length > 0 && make.Length > 0 && model.Length > 0 && style.Length > 0) { url += "&year=" + year; url += "&make=" + make; url += "&model=" + model; url += "&style=" + style; } List<APIPart> parts = JsonConvert.DeserializeObject<List<APIPart>>(wc.DownloadString(url)); return parts; try { } catch (Exception) { return new List<APIPart>(); } }
internal void SendConfirmation() { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); Payment payment = this.getPayment(); string toemail = db.Customers.Where(x => x.ID == this.cust_id).Select(x => x.email).FirstOrDefault(); StringBuilder sb = new StringBuilder(); TextInfo myTI = new CultureInfo("en-US",false).TextInfo; Settings settings = new Settings(); string supportemail = settings.Get("SupportEmail"); List<string> tolist = new List<string>(); tolist.Add(toemail); if (settings.Get("SendConfirmationsToSupport") == "true" && supportemail.Trim() != "") { tolist.Add(supportemail); } string[] tos = tolist.ToArray(); decimal total = 0; sb.Append("<html><body style=\"font-family: arial, helvetica,sans-serif;\">"); sb.Append("<a href=\"" + settings.Get("SiteURL") + "\"><img src=\"" + settings.Get("EmailLogo") + "\" alt=\"" + settings.Get("SiteName") + "\" /></a>"); sb.Append("<h2>Thank you for your order!</h2>"); sb.Append("<hr />"); sb.AppendFormat("<p><strong>Order ID:</strong> {0}<br />", this.payment_id); sb.AppendFormat("<strong>Paid By:</strong> {0} on {1}</p>", payment.PaymentTypes.name, String.Format("{0:M/d/yyyy} at {0:h:mm tt}",payment.created)); sb.Append("<p style=\"font-size: 12px;\"><strong style=\"font-size: 14px;\">Billing Address:</strong><br />"); sb.AppendFormat("{0} {1}<br />", this.Billing.first, this.Billing.last); sb.AppendFormat("{0}{1}<br />{2}, {3} {4}<br />{5}</p>", this.Billing.street1, this.Billing.street2, this.Billing.city, this.Billing.State1.abbr, this.Billing.postal_code, this.Billing.State1.Country.name); sb.Append("<p style=\"font-size: 12px;\"><strong style=\"font-size: 14px;\">Shipping Address:</strong><br />"); sb.AppendFormat("{0} {1}<br />", this.Shipping.first, this.Shipping.last); sb.AppendFormat("{0}{1}<br />{2}, {3} {4}<br />{5}</p>", this.Shipping.street1, this.Shipping.street2, this.Shipping.city, this.Shipping.State1.abbr, this.Shipping.postal_code, this.Shipping.State1.Country.name); sb.Append("<table style=\"width: 100%;\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\"><thead><tr><th style=\"background-color: #343434; color: #fff;\">Item</th><th style=\"background-color: #343434; color: #fff;\">Quantity</th><th style=\"background-color: #343434; color: #fff;\">Price</th></tr></thead><tbody style=\"font-size: 12px;\">"); foreach(CartItem item in this.CartItems) { sb.AppendFormat("<tr><td><a href=\"" + settings.Get("SiteURL") + "part/{0}\">{1}</a></td><td style=\"text-align:center;\">{2}</td><td style=\"text-align:right;\">{3}</td></tr>", item.partID, item.shortDesc, item.quantity, String.Format("{0:C}", item.price)); total += (item.quantity * item.price); } sb.Append("</tbody><tfoot style=\"font-size: 12px;\">"); sb.Append("<tr><td colspan=\"2\" style=\"border-top: 1px solid #222; text-align: right;\"><strong>SubTotal:<strong></td>"); sb.AppendFormat("<td style=\"border-top: 1px solid #222; text-align:right;\"><strong>{0}</strong></td></tr>", String.Format("{0:C}", this.GetSubTotal())); sb.AppendFormat("<tr><td colspan=\"2\" style=\"text-align: right;\">({0}) Shipping:</td>", myTI.ToTitleCase(this.shipping_type.Replace("_", " "))); sb.AppendFormat("<td style=\"text-align:right;\">{0}</td></tr>", (this.shipping_price == 0) ? "Free" : String.Format("{0:C}", this.shipping_price)); sb.Append("<tr><td colspan=\"2\" style=\"text-align: right;\">Tax:</td>"); sb.AppendFormat("<td style=\"text-align:right;\">{0}</td></tr>", String.Format("{0:C}", this.tax)); sb.Append("<tr><td colspan=\"2\" style=\"text-align: right;\"><strong>Total:<strong></td>"); total += this.shipping_price; sb.AppendFormat("<td style=\"text-align:right;\"><strong>{0}</strong></td></tr>",String.Format("{0:C}", this.getTotal())); sb.Append("</tfoot></table>"); sb.Append("<hr /><br />"); sb.Append("<p style='font-size:11px'>If you have any questions, or if you did not place this order, please <a href='" + settings.Get("SiteURL") + "contact'>contact us</a>.</p>"); sb.Append("</body></html>"); UDF.SendEmail(tos, settings.Get("SiteName") + " Order Confirmation", true, sb.ToString()); }
internal static List<APIPart> GetRelatedParts(int p) { try { Settings settings = new Settings(); WebClient wc = new WebClient(); wc.Proxy = null; string url = getAPIPath(); url += "GetRelatedParts?dataType=JSON"; url += "&partID=" + p; url += "&cust_id=" + settings.Get("CURTAccount"); return JsonConvert.DeserializeObject<List<APIPart>>(wc.DownloadString(url)); } catch (Exception) { return new List<APIPart>(); } }
internal void SendInternalOrderEmail(HttpContext ctx) { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); TimeZoneInfo tz = UDF.GetTimeZone(ctx) ?? TimeZoneInfo.Utc; Payment payment = this.getPayment(); string phone = db.Customers.Where(x => x.ID == this.cust_id).Select(x => x.phone).FirstOrDefault(); StringBuilder sb = new StringBuilder(); TextInfo myTI = new CultureInfo("en-US", false).TextInfo; Settings settings = new Settings(); string supportemail = settings.Get("SupportEmail"); List<string> tolist = new List<string>(); if (settings.Get("EDIOrderProcessing") != "true") { string curtemail = settings.Get("CurtOrderEmail"); if (curtemail.Trim() != "") { tolist.Add(curtemail); } } tolist.Add(supportemail); string[] tos = tolist.ToArray(); decimal total = 0; sb.Append("<html><body style=\"font-family: arial, helvetica,sans-serif;\">"); sb.Append("<a href=\"" + settings.Get("SiteURL") + "\"><img src=\"" + settings.Get("EmailLogo") + "\" alt=\"" + settings.Get("SiteName") + "\" /></a>"); sb.Append("<h2>A New Order Has Been Placed</h2>"); sb.Append("<hr />"); sb.AppendFormat("<p><strong>Customer ID:</strong> {0}<br />", settings.Get("CURTAccount")); sb.AppendFormat("<p><strong>Order ID:</strong> {0}<br />", this.payment_id); sb.AppendFormat("<strong>Paid By:</strong> {0} on {1} {2}</p>", payment.PaymentTypes.name, String.Format("{0:M/d/yyyy} at {0:h:mm tt}", TimeZoneInfo.ConvertTimeFromUtc(payment.created, tz)), UDF.ShortTZ(tz, payment.created)); sb.AppendFormat("<strong>Phone:</strong> {0}</p>", phone); sb.Append("<p style=\"font-size: 12px;\"><strong style=\"font-size: 14px;\">Billing Address:</strong><br />"); sb.AppendFormat("{0} {1}<br />", this.Billing.first, this.Billing.last); sb.AppendFormat("{0}{1}<br />{2}, {3} {4}<br />{5}</p>", this.Billing.street1, this.Billing.street2, this.Billing.city, this.Billing.State1.abbr, this.Billing.postal_code, this.Billing.State1.Country.name); sb.Append("<p style=\"font-size: 12px;\"><strong style=\"font-size: 14px;\">Shipping Address:</strong><br />"); sb.AppendFormat("{0} {1}<br />", this.Shipping.first, this.Shipping.last); sb.AppendFormat("{0}{1}<br />{2}, {3} {4}<br />{5}</p>", this.Shipping.street1, this.Shipping.street2, this.Shipping.city, this.Shipping.State1.abbr, this.Shipping.postal_code, this.Shipping.State1.Country.name); sb.Append("<table style=\"width: 100%;\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\"><thead><tr><th style=\"background-color: #343434; color: #fff;\">Item</th><th style=\"background-color: #343434; color: #fff;\">Quantity</th><th style=\"background-color: #343434; color: #fff;\">Price</th></tr></thead><tbody style=\"font-size: 12px;\">"); foreach (CartItem item in this.CartItems) { sb.AppendFormat("<tr><td><a href=\"" + settings.Get("SiteURL") + "part/{0}\">{1}</a></td><td style=\"text-align:center;\">{2}</td><td style=\"text-align:right;\">{3}</td></tr>", item.partID, item.shortDesc, item.quantity, String.Format("{0:C}", item.price)); total += (item.quantity * item.price); } sb.Append("</tbody><tfoot style=\"font-size: 12px;\">"); sb.AppendFormat("<tr><td colspan=\"2\" style=\"border-top: 1px solid #222; text-align: right;\">({0}) Shipping:</td>", myTI.ToTitleCase(this.shipping_type.Replace("_", " "))); sb.AppendFormat("<td style=\"border-top: 1px solid #222; text-align:right;\">{0}</td></tr>", (this.shipping_price == 0) ? "Free" : String.Format("{0:C}", this.shipping_price)); if (this.handling_fee > 0) { sb.AppendFormat("<tr><td colspan=\"2\" style=\"text-align: right;\">Handling:</td><td style=\"text-align:right;\">{0}</td></tr>", String.Format("{0:C}", this.handling_fee)); } sb.Append("<tr><td colspan=\"2\" style=\"text-align: right;\"><strong>SubTotal:<strong></td>"); sb.AppendFormat("<td style=\"text-align:right;\"><strong>{0}</strong></td></tr>", String.Format("{0:C}", this.GetSubTotal())); sb.Append("<tr><td colspan=\"2\" style=\"text-align: right;\">Tax:</td>"); sb.AppendFormat("<td style=\"text-align:right;\">{0}</td></tr>", String.Format("{0:C}", this.tax)); sb.Append("<tr><td colspan=\"2\" style=\"text-align: right;\"><strong>Total:<strong></td>"); total += this.shipping_price; sb.AppendFormat("<td style=\"text-align:right;\"><strong>{0}</strong></td></tr>", String.Format("{0:C}", this.getTotal())); sb.Append("</tfoot></table>"); sb.Append("<hr /><br />"); sb.Append("</body></html>"); UDF.SendEmail(tos, settings.Get("CURTAccount") + " Order - PO " + this.payment_id, true, sb.ToString()); }
internal static List<string> GetShippingTypes() { try { Settings settings = new Settings(); StringBuilder sb = new StringBuilder(settings.Get("CURTAPISHIPPINGDOMAIN")); sb.Append("GenerateJSONServiceTypes"); WebClient wc = new WebClient(); wc.Proxy = null; string resp = wc.DownloadString(sb.ToString()); List<string> types = JsonConvert.DeserializeObject<List<string>>(resp); return types; } catch (Exception) { return new List<string>(); } }
internal void SendShippingNotification() { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); List<Shipment> shipments = db.Shipments.Where(x => x.order_id.Equals(this.ID)).ToList<Shipment>(); if (shipments.Count > 0) { DateTime shipdate = (DateTime)shipments[0].dateShipped; string toemail = db.Customers.Where(x => x.ID == this.cust_id).Select(x => x.email).FirstOrDefault(); StringBuilder sb = new StringBuilder(); TextInfo myTI = new CultureInfo("en-US", false).TextInfo; Settings settings = new Settings(); string[] tos = { toemail }; sb.Append("<html><body style=\"font-family: arial, helvetica,sans-serif;\">"); sb.Append("<a href=\"" + settings.Get("SiteURL") + "\"><img src=\"" + settings.Get("EmailLogo") + "\" alt=\"" + settings.Get("SiteName") + "\" /></a>"); sb.Append("<h2>Your Order Has Shipped!</h2>"); sb.Append("<hr />"); sb.AppendFormat("<p><strong>Order ID:</strong> {0}<br />", this.payment_id); sb.Append("<p>Your order shipped on " + String.Format("{0:dddd, MMMM d, yyyy}", shipdate) + ". Your Tracking Numbers are:<br />"); foreach(Shipment shipment in shipments) { sb.Append("<a href=\"http://www.fedex.com/Tracking?tracknumber_list=" + shipment.tracking_number + "\">" + shipment.tracking_number + "</a><br />"); } sb.Append("<hr /><br />"); sb.Append("<p style='font-size:11px'>If you have any questions, or if you did not place this order, please <a href='" + settings.Get("SiteURL") + "contact'>contact us</a>.</p>"); sb.Append("</body></html>"); UDF.SendEmail(tos, settings.Get("SiteName") + " Shipping Notification", true, sb.ToString()); } }
internal static void SubmitReview(int partID, int rating = 5, string subject = "", string review_text = "", string name = "", string email = "") { try { WebClient wc = new WebClient(); wc.Proxy = null; Settings settings = new Settings(); StringBuilder sb = new StringBuilder(); sb.Append(getAPIPath()); sb.Append("SubmitReview"); sb.Append("?partID=" + partID); sb.Append("&cust_id=" + settings.Get("CURTAccount")); sb.Append("&name=" + name); sb.Append("&email=" + email); sb.Append("&rating=" + rating); sb.Append("&subject=" + subject); sb.Append("&review_text=" + review_text); string resp = wc.DownloadString(sb.ToString()); if (resp != "success") { throw new Exception("Failed to submit review"); } } catch (Exception e) { throw new Exception(e.Message); } }
internal void SendCancelNotice() { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); Payment payment = this.getPayment(); string toemail = db.Customers.Where(x => x.ID == this.cust_id).Select(x => x.email).FirstOrDefault(); StringBuilder sb = new StringBuilder(); TextInfo myTI = new CultureInfo("en-US", false).TextInfo; Settings settings = new Settings(); string[] tos = { toemail }; decimal total = 0; sb.Append("<html><body style=\"font-family: arial, helvetica,sans-serif;\">"); sb.Append("<a href=\"" + settings.Get("SiteURL") + "\"><img src=\"" + settings.Get("EmailLogo") + "\" alt=\"" + settings.Get("SiteName") + "\" /></a>"); sb.Append("<h2>We're Sorry</h2>"); sb.Append("<hr />"); sb.AppendFormat("<p>Your recent order placed with {0} has been cancelled. Google Checkout was unable to process your payment. The order details are listed below.</p>", settings.Get("SiteName")); sb.AppendFormat("<p><strong>Order ID:</strong> {0}<br />", this.payment_id); sb.AppendFormat("<strong>Paid By:</strong> {0} on {1}</p>", payment.PaymentTypes.name, String.Format("{0:M/d/yyyy} at {0:h:mm tt}", payment.created)); sb.AppendFormat("<strong>Payment Status:</strong> {0}</p>", payment.status); sb.Append("<p style=\"font-size: 12px;\"><strong style=\"font-size: 14px;\">Billing Address:</strong><br />"); sb.AppendFormat("{0} {1}<br />", this.Billing.first, this.Billing.last); sb.AppendFormat("{0}{1}<br />{2}, {3} {4}<br />{5}</p>", this.Billing.street1, this.Billing.street2, this.Billing.city, this.Billing.State1.abbr, this.Billing.postal_code, this.Billing.State1.Country.name); sb.Append("<p style=\"font-size: 12px;\"><strong style=\"font-size: 14px;\">Shipping Address:</strong><br />"); sb.AppendFormat("{0} {1}<br />", this.Shipping.first, this.Shipping.last); sb.AppendFormat("{0}{1}<br />{2}, {3} {4}<br />{5}</p>", this.Shipping.street1, this.Shipping.street2, this.Shipping.city, this.Shipping.State1.abbr, this.Shipping.postal_code, this.Shipping.State1.Country.name); sb.Append("<table style=\"width: 100%;\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\"><thead><tr><th style=\"background-color: #343434; color: #fff;\">Item</th><th style=\"background-color: #343434; color: #fff;\">Quantity</th><th style=\"background-color: #343434; color: #fff;\">Price</th></tr></thead><tbody style=\"font-size: 12px;\">"); foreach (CartItem item in this.CartItems) { sb.AppendFormat("<tr><td><a href=\"" + settings.Get("SiteURL") + "part/{0}\">{1}</a></td><td style=\"text-align:center;\">{2}</td><td style=\"text-align:right;\">{3}</td></tr>", item.partID, item.shortDesc, item.quantity, String.Format("{0:C}", item.price)); total += (item.quantity * item.price); } sb.Append("</tbody><tfoot style=\"font-size: 12px;\">"); sb.AppendFormat("<tr><td colspan=\"2\" style=\"border-top: 1px solid #222;text-align: right;\">({0}) Shipping:</td>", myTI.ToTitleCase(this.shipping_type.Replace("_", " "))); sb.AppendFormat("<td style=\"border-top: 1px solid #222;text-align:right;\">{0}</td></tr>", (this.shipping_price == 0) ? "Free" : String.Format("{0:C}", this.shipping_price)); sb.Append("<tr><td colspan=\"2\" style=\"text-align: right;\"><strong>Total:<strong></td>"); total += this.shipping_price; sb.AppendFormat("<td style=\"text-align:right;\"><strong>{0}</strong></td></tr>", String.Format("{0:C}", total)); sb.Append("</tfoot></table>"); sb.Append("<hr /><br />"); sb.Append("<p style='font-size:11px'>We hope you come back and try your order again. If you have any questions, please <a href='" + settings.Get("SiteURL") + "contact'>contact us</a>.</p>"); sb.Append("</body></html>"); UDF.SendEmail(tos, settings.Get("SiteName") + " Order Cancellation Notice", true, sb.ToString()); }
public bool HasFreeShipping() { try { List<int> excludedStates = new State().GetExcludedStates().Select(x => x.stateID).ToList(); BindAddresses(); if (excludedStates.Contains(this.Shipping.state)) { return false; } Settings settings = new Settings(); decimal freeship = Convert.ToDecimal(settings.Get("FreeShippingAmount")); decimal total = 0; foreach (CartItem item in this.CartItems) { total += (item.price * item.quantity); } if (total >= freeship) { return true; } } catch (Exception) { } return false; }
internal void ResetPassword() { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); string orig_pass = this.password; try { PasswordGenerator pw = new PasswordGenerator(); string new_pass = pw.Generate(); Settings settings = new Settings(); string[] tos = { this.email }; StringBuilder sb = new StringBuilder(); sb.Append("<p>A new password has been generated for an account with this e-mail address from <a href='" + settings.Get("SiteURL") + "' title='" + settings.Get("SiteName") + "'>" + settings.Get("SiteName") + "</a>.</p>"); sb.Append("<hr />"); sb.Append("<p>To <a href='" + settings.Get("SiteURL") + "' title='Login' target='_blank'>login</a> to " + settings.Get("SiteName") + ", please use the information provided below.</p>"); sb.Append("<span>The new password is: <strong>" + new_pass + "</strong></span><br />"); sb.Append("<hr /><br />"); sb.Append("<p style='font-size:11px'>If you feel this was a mistake please disregard this e-mail.</p>"); UDF.SendEmail(tos, "New password for " + settings.Get("SiteName"), true, sb.ToString()); Customer c = db.Customers.Where(x => x.ID.Equals(this.ID)).First<Customer>(); c.password = UDF.EncryptString(new_pass); } catch {} db.SubmitChanges(); }