/// <summary> /// Called to send the emails whenever a new order is processed. /// </summary> /// <param name="settingGroupList"></param> /// <param name="paypalPurchaseOrder"></param> public static void SendNewEcommerceOrderEmails(List <SettingGroup> settingGroupList, PurchaseOrderDetails paypalPurchaseOrder) { try { SettingGroup EmailSettings = settingGroupList.Where(e => e.GroupKey.Equals(SettingGroupKeys.EMAIL_SETTINGS)).FirstOrDefault(); SettingGroup TemplateSettings = settingGroupList.Where(e => e.GroupKey.Equals(SettingGroupKeys.TEMPLATE_CUSTOM_SETTINGS)).FirstOrDefault(); List <AdminUser> AdminUserList = new List <AdminUser>(); try { if (!string.IsNullOrWhiteSpace(EmailSettings.GetSettingVal(EmailSettingKeys.NewOrderEmailAdminUsers))) { AdminUserList = AdminUserDAO.LoadByMultipleIds(EmailSettings.GetSettingVal(EmailSettingKeys.NewOrderEmailAdminUsers).Split(',').ToList()); } } catch (Exception e) { //do nothing, just in case the setting got jacked up somehow we still want to send the customer's email. } Chimera.Emails.Ecommerce.SendNewEcommerceOrderEmails(AdminUserList, paypalPurchaseOrder, EmailSettings.GetSettingVal(EmailSettingKeys.CustomerOrderFinishedEmail), EmailSettings.GetSettingVal(EmailSettingKeys.SenderEmailAddress), TemplateSettings.GetSettingVal("WebsiteTitle")); } catch (Exception e) { CompanyCommons.Logging.WriteLog("Chimera.Core.PurchaseOrders.Email.SendNewEcommerceOrderEmails()" + e.Message); } }
/// <summary> /// Get the necessary paypal API auth header from our setting group. /// </summary> /// <param name="paypalSettingGroup"></param> /// <returns></returns> public static AuthHeader GetAuthHeaderFromSetting(SettingGroup paypalSettingGroup) { AuthHeader PayPalAuthHeader = new AuthHeader(); PayPalAuthHeader.BaseApiURL = paypalSettingGroup.GetSettingVal(PayPalSettingKeys.PayPal_API); PayPalAuthHeader.Username = paypalSettingGroup.GetSettingVal(PayPalSettingKeys.PayPal_Username); PayPalAuthHeader.Password = paypalSettingGroup.GetSettingVal(PayPalSettingKeys.PayPal_Password); PayPalAuthHeader.Signature = paypalSettingGroup.GetSettingVal(PayPalSettingKeys.PayPal_Signature); return(PayPalAuthHeader); }
/// <summary> /// View the product /// </summary> /// <returns></returns> public ActionResult Details(string id) { try { Product Prod = ProductDAO.LoadByBsonId(id); try { if (Prod != null && !string.IsNullOrWhiteSpace(Prod.Name)) { ChimeraWebsite.Helpers.SiteContext.RecordPageView("Ecommerce_ViewProduct=" + Prod.Name); } } catch (Exception e) { CompanyCommons.Logging.WriteLog("ChimeraWebsite.Controllers.ViewProduct.Details.RecordPageVisit()", e); } SettingGroup EcommerceSettings = SettingGroupDAO.LoadSettingGroupByName(SettingGroupKeys.ECOMMERCE_SETTINGS); ViewBag.ProductModel = new ProductModel(EcommerceSettings.GetSettingVal(ECommerceSettingKeys.ViewProductDetailPage), Prod); return(View("Details", String.Format("~/Templates/{0}/Views/Shared/Template.Master", Models.ChimeraTemplate.TemplateName))); } catch (Exception e) { CompanyCommons.Logging.WriteLog("ChimeraWebsite.Controllers.ViewProductController.Details() " + e.Message); } //TODO: return 404 page instead? return(RedirectToAction("Index", "Home")); }
/// <summary> /// Get the model for the view cart view /// </summary> /// <returns></returns> private ShoppingCartModel GetModel() { List <SettingGroup> SettingGroupList = SettingGroupDAO.LoadByMultipleGroupNames(new List <string> { SettingGroupKeys.ECOMMERCE_SETTINGS, SettingGroupKeys.PAYPAL_PURCHASE_SETTINGS }); SettingGroup EcommerceSettings = SettingGroupList.Where(e => e.GroupKey.Equals(SettingGroupKeys.ECOMMERCE_SETTINGS)).FirstOrDefault(); SettingGroup PaypalPurchaseSettings = SettingGroupList.Where(e => e.GroupKey.Equals(SettingGroupKeys.PAYPAL_PURCHASE_SETTINGS)).FirstOrDefault(); StaticProperty ShippingMethods = StaticPropertyDAO.LoadByKeyName(StaticProperty.SHIPPING_METHOD_PROPERTY_KEY); return(new ShoppingCartModel(PaypalPurchaseSettings, EcommerceSettings.GetSettingVal(ECommerceSettingKeys.ViewShoppingCartPage), ShippingMethods)); }
public ActionResult InitCheckout(string shippingMethod) { try { List <ShoppingCartProduct> ShoppingCartList = SiteContext.ShoppingCartProductList; SettingGroup PayPalSettings = SettingGroupDAO.LoadSettingGroupByName(SettingGroupKeys.PAYPAL_PURCHASE_SETTINGS); //create auth header obj AuthHeader PayPalAuthHeader = Chimera.Core.PurchaseOrders.PayPalAuthHeader.GetAuthHeaderFromSetting(PayPalSettings); //create authorization obj Authorization PayPalAuthorization = new Authorization(); string BaseWebsiteURL = CM.AppSettings["BaseWebsiteURL"]; PayPalAuthorization.StoreImageURL = PayPalSettings.GetSettingVal(PayPalSettingKeys.PayPal_HDRIMG); PayPalAuthorization.SuccessOrderURL = BaseWebsiteURL + "Order/PayPalSuccess"; PayPalAuthorization.CancelOrderURL = BaseWebsiteURL + "Order/PayPalCancel"; //create purchase order details obj PurchaseOrderDetails PurchaseOrder = new PurchaseOrderDetails(shippingMethod, ShoppingCartList, Helpers.ShippingMethod.GetGlobalShippingMethodDictionary(null, PayPalSettings)[shippingMethod], PayPalSettings.GetSettingVal(PayPalSettingKeys.GlobalTaxAmount)); //call paypal API to get new order details OrderDetails AuthOrderDetails = CompanyCommons.Ecommerce.PayPal.Functions.Execute.Authorization(PayPalAuthHeader, PayPalAuthorization, PurchaseOrder.PayPalOrderDetails, PurchaseOrder.CreatePayPalItemDescriptions()); if (AuthOrderDetails != null) { //store purchase order object into session PurchaseOrder.PayPalOrderDetails = AuthOrderDetails; //add updated info to session SiteContext.PayPalPurchaseOrder = PurchaseOrder; //redirect to paypal return(Redirect(CompanyCommons.Ecommerce.PayPal.Functions.Execute.GetAuthorizationRedirectURL(PayPalSettings.GetSettingVal(PayPalSettingKeys.PayPal_REDIRECT), AuthOrderDetails))); } //if we got this far the call the paypal's API failed } catch (Exception e) { CompanyCommons.Logging.WriteLog("ChimeraWebsite.Controllers.OrderController.InitCheckout() " + e.Message); } //TODO: return 404 page instead? return(RedirectToAction("Index", "Home")); }
/// <summary> /// User redirected back here from paypal after successfully filling out all the necessary form data from paypal /// </summary> /// <returns></returns> public ActionResult PayPalSuccess() { try { if (!string.IsNullOrWhiteSpace(SiteContext.PayPalPurchaseOrder.PayPalOrderDetails.PaypalInfo.Token)) { SiteContext.RecordPageView("Ecommerce_PayPalSuccess"); List <SettingGroup> SettingGroupList = SettingGroupDAO.LoadByMultipleGroupNames(new List <string> { SettingGroupKeys.ECOMMERCE_SETTINGS, SettingGroupKeys.PAYPAL_PURCHASE_SETTINGS }); SettingGroup PayPalSettings = SettingGroupList.Where(e => e.GroupKey.Equals(SettingGroupKeys.PAYPAL_PURCHASE_SETTINGS)).FirstOrDefault(); //create auth header obj AuthHeader PayPalAuthHeader = Chimera.Core.PurchaseOrders.PayPalAuthHeader.GetAuthHeaderFromSetting(PayPalSettings); PurchaseOrderDetails PayPalPurchaseOrder = SiteContext.PayPalPurchaseOrder; OrderDetails CheckoutOrderDetails = CompanyCommons.Ecommerce.PayPal.Functions.Execute.ExpressCheckout(PayPalAuthHeader, PayPalPurchaseOrder.PayPalOrderDetails); if (CheckoutOrderDetails != null) { PayPalPurchaseOrder.PayPalOrderDetails = CheckoutOrderDetails; SiteContext.PayPalPurchaseOrder = PayPalPurchaseOrder; SettingGroup EcommerceSettings = SettingGroupList.Where(e => e.GroupKey.Equals(SettingGroupKeys.ECOMMERCE_SETTINGS)).FirstOrDefault(); ViewBag.PayPalSuccessModel = new PayPalSuccessModel(EcommerceSettings.GetSettingVal(ECommerceSettingKeys.FinalizeCheckoutPage), PayPalPurchaseOrder); return(View("PayPalSuccess", String.Format("~/Templates/{0}/Views/Shared/Template.Master", Models.ChimeraTemplate.TemplateName))); } } } catch (Exception e) { CompanyCommons.Logging.WriteLog("ChimeraWebsite.Controllers.OrderController.PayPalSuccess() " + e.Message); } //TODO: return 404 page instead? return(RedirectToAction("Index", "Home")); }
/// <summary> /// Process a purchased product after the stock level has been altered from the purchase order /// </summary> /// <param name="product"></param> /// <returns></returns> public static bool ProcessPurchasedProduct(SettingGroup paypalSettings, Product product) { try { string StockLevelWarningString = paypalSettings.GetSettingVal(PayPalSettingKeys.StockLevelWarning); int StockLevelWarning = Int32.Parse(!string.IsNullOrWhiteSpace(StockLevelWarningString) ? StockLevelWarningString : "0"); if (product.PurchaseSettings.StockLevel <= StockLevelWarning) { Notification NewNotification = GenerateNewNotification(product.Name, product.Id, product.PurchaseSettings.StockLevel); DashboardNotificationDAO.Save(NewNotification); } if (product.CheckoutPropertySettingsList != null && product.CheckoutPropertySettingsList.Count > 0) { foreach (var CheckPropSetting in product.CheckoutPropertySettingsList) { if (CheckPropSetting.PurchaseSettings.StockLevel <= StockLevelWarning) { Notification NewNotification = GenerateNewNotification(product.Name, product.Id, product.PurchaseSettings.StockLevel, CheckPropSetting.CheckoutPropertySettingKeys); DashboardNotificationDAO.Save(NewNotification); } } } return(true); } catch (Exception e) { CompanyCommons.Logging.WriteLog("Chimera.Core.Notifications.ProductStock.ProcessPurchasedProduct()" + e.Message); } return(false); }
public ActionResult Index(string friendlyURL, string previewPageData) { friendlyURL = string.IsNullOrWhiteSpace(friendlyURL) ? "Index" : friendlyURL; if (friendlyURL.ToUpper().Equals("ADMIN")) { return(RedirectToRoute("Admin_Default")); } Models.PageModel PageModel = new Models.PageModel(); if (!string.IsNullOrWhiteSpace(previewPageData)) { ViewBag.PreviewPageData = previewPageData; PageModel.InEditMode = true; } else { PageModel = new Models.PageModel(friendlyURL, Request); } if (!string.IsNullOrWhiteSpace(PageModel.Page.Id) || PageModel.InEditMode) { ViewBag.PageModel = PageModel; return(View("Index", String.Format("~/Templates/{0}/Views/Shared/Template.Master", Models.ChimeraTemplate.TemplateName))); } //if we got this far this is a 404 SettingGroup SettingGroup = SettingGroupDAO.LoadSettingGroupByName(SettingGroupKeys.TEMPLATE_CUSTOM_SETTINGS); ViewBag.ViewType = SettingGroup.GetSettingVal("PageNotFoundPage"); return(View("PageNotFound", String.Format("~/Templates/{0}/Views/Shared/Template.Master", Models.ChimeraTemplate.TemplateName))); }
/// <summary> /// Called after the user reviews their order on our side right and wishes to finalize the purchase /// </summary> /// <returns></returns> public ActionResult FinalCheckout() { SiteContext.RecordPageView("Ecommerce_FinalCheckout"); try { PurchaseOrderDetails PayPalPurchaseOrder = SiteContext.PayPalPurchaseOrder; if (PayPalPurchaseOrder != null && !string.IsNullOrWhiteSpace(PayPalPurchaseOrder.PayPalOrderDetails.PaypalInfo.Token)) { List <SettingGroup> SettingGroupList = SettingGroupDAO.LoadByMultipleGroupNames(new List <string> { SettingGroupKeys.TEMPLATE_CUSTOM_SETTINGS, SettingGroupKeys.EMAIL_SETTINGS, SettingGroupKeys.ECOMMERCE_SETTINGS, SettingGroupKeys.PAYPAL_PURCHASE_SETTINGS }); SettingGroup PayPalSettings = SettingGroupList.Where(e => e.GroupKey.Equals(SettingGroupKeys.PAYPAL_PURCHASE_SETTINGS)).FirstOrDefault(); //create auth header obj AuthHeader PayPalAuthHeader = Chimera.Core.PurchaseOrders.PayPalAuthHeader.GetAuthHeaderFromSetting(PayPalSettings); OrderDetails FinalOrderDetails = CompanyCommons.Ecommerce.PayPal.Functions.Execute.FinalConfirmedAuthorization(PayPalAuthHeader, PayPalPurchaseOrder.PayPalOrderDetails); if (FinalOrderDetails != null) { PayPalPurchaseOrder.PayPalOrderDetails = FinalOrderDetails; //generate a new id so we can give the user a confirmation # PayPalPurchaseOrder.Id = ObjectId.GenerateNewId().ToString(); //save to the database as an order PurchaseOrderDetailsDAO.Save(PayPalPurchaseOrder); //clear session cart SiteContext.ClearShoppingCart(); //subtract stock from current products Chimera.Core.PurchaseOrders.ProductStock.ProcessNewOrderStockLevels(PayPalSettings, PayPalPurchaseOrder); //send emails Chimera.Core.PurchaseOrders.Email.SendNewEcommerceOrderEmails(SettingGroupList, PayPalPurchaseOrder); //add admin notification Chimera.Core.Notifications.PurchaseOrder.ProcessNewPurchaseOrder(PayPalPurchaseOrder); //return view SettingGroup EcommerceSettings = SettingGroupList.Where(e => e.GroupKey.Equals(SettingGroupKeys.ECOMMERCE_SETTINGS)).FirstOrDefault(); ViewBag.ConfirmationNumber = PayPalPurchaseOrder.Id.ToString(); ViewBag.ViewType = EcommerceSettings.GetSettingVal(ECommerceSettingKeys.CheckoutFinishedPage); return(View("FinalCheckout", String.Format("~/Templates/{0}/Views/Shared/Template.Master", Models.ChimeraTemplate.TemplateName))); } } } catch (Exception e) { CompanyCommons.Logging.WriteLog("ChimeraWebsite.Controllers.OrderController.FinalCheckout() " + e.Message); } //TODO: return 404 page instead? return(RedirectToAction("Index", "Home")); }
public ActionResult ShipOrder(string id, string trackingNumber) { try { PurchaseOrderDetails PurchaseOrderDetail = PurchaseOrderDetailsDAO.LoadByBsonId(id); PurchaseOrderDetail.PayPalOrderDetails.ShippingTrackingNumber = trackingNumber; PurchaseOrderDetail.PayPalOrderDetails.OrderShippedDateUtc = DateTime.UtcNow; if (PurchaseOrderDetailsDAO.Save(PurchaseOrderDetail)) { Chimera.Core.Notifications.PurchaseOrder.ProcessPurchaseOrderShipped(PurchaseOrderDetail); try { List <SettingGroup> SettingGroupList = SettingGroupDAO.LoadByMultipleGroupNames(new List <string> { SettingGroupKeys.TEMPLATE_CUSTOM_SETTINGS, SettingGroupKeys.EMAIL_SETTINGS }); SettingGroup EmailSettings = SettingGroupList.Where(e => e.GroupKey.Equals(SettingGroupKeys.EMAIL_SETTINGS)).FirstOrDefault(); SettingGroup TemplateSettings = SettingGroupList.Where(e => e.GroupKey.Equals(SettingGroupKeys.TEMPLATE_CUSTOM_SETTINGS)).FirstOrDefault(); Chimera.Emails.Ecommerce.SendOrderShippedEmail(PurchaseOrderDetail, EmailSettings.GetSettingVal(EmailSettingKeys.CustomerOrderShippedEmail), EmailSettings.GetSettingVal(EmailSettingKeys.SenderEmailAddress), TemplateSettings.GetSettingVal("WebsiteTitle")); } catch (Exception e) { CompanyCommons.Logging.WriteLog("ChimeraWebsite.Areas.Admin.Controllers.PurchaseOrdersController.ShipOrder.SendEmail()" + e.Message); } AddWebUserMessageToSession(Request, String.Format("Tracking # added and user notified order shipped!"), SUCCESS_MESSAGE_TYPE); } else { AddWebUserMessageToSession(Request, String.Format("Unable to add tracking # and email user of shipped order."), FAILED_MESSAGE_TYPE); } } catch (Exception e) { CompanyCommons.Logging.WriteLog("ChimeraWebsite.Areas.Admin.Controllers.PurchaseOrdersController.ShipOrder()" + e.Message); } return(RedirectToAction("Search", "PurchaseOrders")); }