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 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); }