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);
        }
Esempio n. 3
0
        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();
        }