public override bool Execute(OrderTaskContext context) { var order = context.Order; if (order != null) { var hccApp = context.HccApp; var store = hccApp.CurrentStore; if (order.CustomProperties.HccRewardsPointsIssued || !store.Settings.RewardsPointsEnabled || string.IsNullOrEmpty(context.UserId)) // skip if there is no user account { return(true); } var pointsAmount = GetPointsAmount(order, hccApp); var orderTotal = GetOrderTotal(order, store); if (orderTotal > pointsAmount) { var pointsManager = new CustomerPointsManager(hccApp.CurrentRequestContext); var pointsToIssue = pointsManager.PointsToIssueForSpend(orderTotal - pointsAmount); pointsManager.IssuePoints(order.UserID, pointsToIssue); order.CustomProperties.HccRewardsPointsIssued = true; hccApp.OrderServices.Orders.Update(order); } } return(true); }
public override bool Execute(OrderTaskContext context) { bool result = true; if (context.HccApp.OrderServices.PaymentSummary(context.Order).AmountDueWithAuth > 0) { CustomerPointsManager pointsManager = new CustomerPointsManager(context.HccApp.CurrentRequestContext); OrderPaymentManager payManager = new OrderPaymentManager(context.Order, context.HccApp); List <OrderTransaction> transactions = context.HccApp.OrderServices.Transactions .FindForOrder(context.Order.bvin) .OrderByDescending(x => x.TimeStampUtc) .ToList(); decimal dueAmount = context.HccApp.OrderServices.PaymentSummary(context.Order).AmountDueWithAuth; foreach (OrderTransaction p in transactions) { if (p.Action == ActionType.RewardPointsInfo) { // if we already have an auth or charge on the card, skip if (p.HasSuccessfulLinkedAction(ActionType.RewardPointsDecrease, transactions) || p.HasSuccessfulLinkedAction(ActionType.RewardPointsHold, transactions)) { continue; } try { int points = pointsManager.PointsNeededForPurchaseAmount(p.Amount); if (context.HccApp.CurrentRequestContext.CurrentStore.Settings.PaymentCreditCardAuthorizeOnly) { payManager.RewardsPointsHold(p, points); } else { payManager.RewardsPointsCharge(p, points); } } catch (Exception ex) { context.Errors.Add(new WorkflowMessage("Exception During Receive Rewards Points", ex.Message + ex.StackTrace, false)); } dueAmount = context.HccApp.OrderServices.PaymentSummary(context.Order).AmountDueWithAuth; //Amount required in order is already charged. No need to charge on other transactions if (dueAmount <= 0) { break; } } } } return(result); }
public void CanIssuePointsForSpendUneven() { string connectionString = string.Empty; int pointsIssuedPerDollar = 1; int pointsNeededForDollarCredit = 100; long storeId = -1; CustomerPointsManager target = CustomerPointsManager.InstantiateForMemory(pointsIssuedPerDollar, pointsNeededForDollarCredit, storeId); Decimal spend = 43.51m; int expected = 43; int actual; actual = target.PointsToIssueForSpend(spend); Assert.AreEqual(expected, actual); }
public void CanCalculatePointsNeededForSpend() { string connectionString = string.Empty; int pointsIssuedPerDollar = 1; int pointsNeededForDollarCredit = 100; long storeId = -1; CustomerPointsManager target = CustomerPointsManager.InstantiateForMemory(pointsIssuedPerDollar, pointsNeededForDollarCredit, storeId); Decimal purchaseAmount = 57.83m; int expected = 5783; int actual; actual = target.PointsNeededForPurchaseAmount(purchaseAmount); Assert.AreEqual(expected, actual); }
public void CanCalculateDollarValueOfPoints() { string connectionString = string.Empty; int pointsIssuedPerDollar = 1; int pointsNeededForDollarCredit = 100; long storeId = -1; CustomerPointsManager target = CustomerPointsManager.InstantiateForMemory(pointsIssuedPerDollar, pointsNeededForDollarCredit, storeId); int points = 487; Decimal expected = 4.87m; Decimal actual; actual = target.DollarCreditForPoints(points); Assert.AreEqual(expected, actual); }
public override bool Execute(OrderTaskContext context) { bool result = true; if (context.MTApp.OrderServices.PaymentSummary(context.Order).AmountDue > 0) { CustomerPointsManager pointsManager = CustomerPointsManager.InstantiateForDatabase(context.MTApp.CurrentRequestContext.CurrentStore.Settings.RewardsPointsIssuedPerDollarSpent, context.MTApp.CurrentRequestContext.CurrentStore.Settings.RewardsPointsNeededPerDollarCredit, context.MTApp.CurrentRequestContext.CurrentStore.Id); Orders.OrderPaymentManager payManager = new Orders.OrderPaymentManager(context.Order, context.MTApp); foreach (Orders.OrderTransaction p in context.MTApp.OrderServices.Transactions.FindForOrder(context.Order.bvin)) { List <Orders.OrderTransaction> transactions = context.MTApp.OrderServices.Transactions.FindForOrder(context.Order.bvin); if (p.Action == MerchantTribe.Payment.ActionType.RewardPointsInfo) { // if we already have an auth or charge on the card, skip if (p.HasSuccessfulLinkedAction(MerchantTribe.Payment.ActionType.RewardPointsDecrease, transactions) || p.HasSuccessfulLinkedAction(MerchantTribe.Payment.ActionType.RewardPointsHold, transactions)) { continue; } try { payManager.RewardsPointsHold(p, p.Amount); } catch (Exception ex) { context.Errors.Add(new WorkflowMessage("Exception During Receive Credit Card", ex.Message + ex.StackTrace, false)); } } } // Evaluate Payment Status After Receiving Payments Orders.OrderPaymentStatus previousPaymentStatus = context.Order.PaymentStatus; context.MTApp.OrderServices.EvaluatePaymentStatus(context.Order); context.Inputs.Add("bvsoftware", "PreviousPaymentStatus", previousPaymentStatus.ToString()); BusinessRules.Workflow.RunByName(context, WorkflowNames.PaymentChanged); } return(result); }
public override bool Execute(OrderTaskContext context) { if (context.Order != null) { string issued = context.Order.CustomProperties.GetProperty("bvsoftware", "rewardspointsissued"); if (issued == "1") { return(true); } // skip if there is no user account if (context.UserId == string.Empty) { return(true); } bool hasPointsPayment = false; foreach (OrderTransaction t in context.MTApp.OrderServices.Transactions.FindForOrder(context.Order.bvin)) { if (t.Action == MerchantTribe.Payment.ActionType.RewardPointsInfo) { hasPointsPayment = true; break; } } // Don't issue points when paying with points if (hasPointsPayment) { return(true); } CustomerPointsManager pointsManager = CustomerPointsManager.InstantiateForDatabase(context.MTApp.CurrentRequestContext.CurrentStore.Settings.RewardsPointsIssuedPerDollarSpent, context.MTApp.CurrentRequestContext.CurrentStore.Settings.RewardsPointsNeededPerDollarCredit, context.MTApp.CurrentRequestContext.CurrentStore.Id); int pointsToIssue = pointsManager.PointsToIssueForSpend(context.Order.TotalOrderAfterDiscounts); pointsManager.IssuePoints(context.Order.UserID, pointsToIssue); context.Order.CustomProperties.SetProperty("bvsoftware", "rewardspointsissued", "1"); context.MTApp.OrderServices.Orders.Update(context.Order); } return(true); }
private void LoadInfo() { var manager = new CustomerPointsManager(HccApp.CurrentRequestContext); var pointsIssued = manager.TotalPointsIssuedForStore(HccApp.CurrentStore.Id); lblPointsIssued.Text = pointsIssued.ToString(); lblPointsIssuedValue.Text = manager.DollarCreditForPoints(pointsIssued).ToString("c"); var pointsReserverd = manager.TotalPointsReservedForStore(HccApp.CurrentStore.Id); lblPointsReserved.Text = pointsReserverd.ToString(); lblPointsReservedValue.Text = manager.DollarCreditForPoints(pointsReserverd).ToString("c"); RewardsNameField.Text = HccApp.CurrentStore.Settings.RewardsPointsName; chkEnableRewardsPoints.Checked = HccApp.CurrentStore.Settings.RewardsPointsEnabled; chkUseForUserPrice.Checked = HccApp.CurrentStore.Settings.UseRewardsPointsForUserPrice; chkIssuePointsForUserPrice.Checked = HccApp.CurrentStore.Settings.IssuePointsForUserPrice; PointsCreditField.Text = HccApp.CurrentStore.Settings.RewardsPointsNeededPerDollarCredit.ToString(); PointsPerDollarField.Text = HccApp.CurrentStore.Settings.RewardsPointsIssuedPerDollarSpent.ToString(); }
private void LoadInfo() { CustomerPointsManager manager = CustomerPointsManager.InstantiateForDatabase(MTApp.CurrentStore.Settings.RewardsPointsIssuedPerDollarSpent, MTApp.CurrentStore.Settings.RewardsPointsNeededPerDollarCredit, MTApp.CurrentStore.Id); int pointsIssued = manager.TotalPointsIssuedForStore(MTApp.CurrentStore.Id); this.lblPointsIssued.Text = pointsIssued.ToString(); this.lblPointsIssuedValue.Text = manager.DollarCreditForPoints(pointsIssued).ToString("c"); int pointsReserverd = manager.TotalPointsReservedForStore(MTApp.CurrentStore.Id); this.lblPointsReserved.Text = pointsReserverd.ToString(); this.lblPointsReservedValue.Text = manager.DollarCreditForPoints(pointsReserverd).ToString("c"); this.RewardsNameField.Text = MTApp.CurrentStore.Settings.RewardsPointsName; this.chkPointForDollars.Checked = MTApp.CurrentStore.Settings.RewardsPointsOnPurchasesActive; this.chkPointsForProducts.Checked = MTApp.CurrentStore.Settings.RewardsPointsOnProductsActive; this.PointsCreditField.Text = MTApp.CurrentStore.Settings.RewardsPointsNeededPerDollarCredit.ToString(); this.PointsPerDollarField.Text = MTApp.CurrentStore.Settings.RewardsPointsIssuedPerDollarSpent.ToString(); }
// Multi-Store Destroy public bool DestroyStore(long storeId) { EventLog.LogEvent("System", "Destroying Store " + storeId, EventLogSeverity.Debug); var result = true; var s = AccountServices.Stores.FindById(storeId); if (s == null) { return(false); } if (s.Id != storeId) { return(false); } DiskStorage.DestroyAllFilesForStore(storeId); //this.AccountServices.RemoveAllUsersFromStore(storeId); // Store Address var storeAddress = ContactServices.Addresses.FindStoreContactAddress(); if (storeAddress != null) { ContactServices.Addresses.Delete(storeAddress.Bvin); } // Get rid of URLs so they won't stop category/product deletes ContentServices.CustomUrls.DestoryAllForStore(storeId); // Catalog Services DestroyAllProductsForStore(storeId); DestroyAllCategoriesForStore(storeId); CatalogServices.ProductProperties.DestroyAllForStore(storeId); CatalogServices.ProductTypeDestoryAllForStore(storeId); CatalogServices.WishListItems.DestroyAllForStore(storeId); // Contact Services ContactServices.Affiliates.DestoryForStore(storeId); ContactServices.MailingLists.DestoryForStore(storeId); ContactServices.Manufacturers.DestoryAllForStore(storeId); ContactServices.PriceGroups.DestoryAllForStore(storeId); ContactServices.Vendors.DestoryAllForStore(storeId); // Content Services ContentServices.Columns.DestroyForStore(storeId); ContentServices.HtmlTemplates.DestroyAllForStore(storeId); // Customer Points CustomerPointsManager.DestroyAllForStore(storeId); // Membership MembershipServices.UserQuestions.DestroyAllForStore(storeId); MembershipServices.Customers.DestroyAllForStore(storeId); // Marketing MarketingServices.Promotions.DestroyAllForStore(storeId); // Metrics MetricsSerices.SearchQueries.DestoryAllForStore(storeId); // Orders OrderServices.Orders.DestoryAllForStore(storeId); OrderServices.ShippingMethods.DestoryAllForStore(storeId); OrderServices.ShippingZones.DestoryAllForStore(storeId); OrderServices.Taxes.DestoryAllForStore(storeId); OrderServices.TaxSchedules.DestoryAllForStore(storeId); OrderServices.Transactions.DestoryAllForStore(storeId); // Tasks ScheduleServices.QueuedTasks.DestoryAllForStore(storeId); // Account Services AccountServices.ApiKeys.DestoryAllForStore(storeId); AccountServices.Stores.Delete(storeId); if (result) { EventLog.LogEvent("System", "Finished Destroying Store " + storeId, EventLogSeverity.Debug); } else { EventLog.LogEvent("System", "Error Destroying Store " + storeId, EventLogSeverity.Warning); } return(result); }