public bool RewardsPointsRefund(OrderTransaction previousTransaction, decimal amount)
        {
            if (previousTransaction == null) return false;

            Transaction t = o.GetEmptyTransaction();
            t.Action = ActionType.RewardPointsIncrease;
            t.Amount = EnsurePositiveAmount(amount);
            t.RewardPoints = pointsManager.PointsNeededForPurchaseAmount(EnsurePositiveAmount(amount));
            t.Customer.UserId = o.UserID;
            OrderTransaction ot = new OrderTransaction(t);

            if (previousTransaction.Action != ActionType.RewardPointsCapture
                && previousTransaction.Action != ActionType.RewardPointsDecrease
                && previousTransaction.Action != ActionType.RewardPointsInfo)
            {
                ot.Success = false;
                ot.Messages = "Transaction must be Rewards Points capture or charge type to refund.";
                return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
            }

            Payment.RewardPoints processor = new RewardPoints();
            processor.Settings = new RewardPointsSettings(this.MTApp.CurrentStore.Id)
            {
                PointsIssuedPerDollarSpent = pointsManager.PointsToIssueForSpend(1),
                PointsNeededForDollarCredit = pointsManager.PointsNeededForPurchaseAmount(1)
            };
            if (processor != null)
            {
                processor.ProcessTransaction(t);
                ot = new OrderTransaction(t);
                ot.LinkedToTransaction = previousTransaction.IdAsString;
            }
            return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
        }
        public bool RewardsPointsAcceptAll()
        {
            bool result = true;

            Payment.RewardPoints processor = new RewardPoints();
            processor.Settings = new RewardPointsSettings(this.MTApp.CurrentStore.Id)
            {
                PointsIssuedPerDollarSpent = pointsManager.PointsToIssueForSpend(1),
                PointsNeededForDollarCredit = pointsManager.PointsNeededForPurchaseAmount(1)
            };

            foreach (Orders.OrderTransaction p in svc.Transactions.FindForOrder(o.bvin))
            {

                List<Orders.OrderTransaction> transactions = svc.Transactions.FindForOrder(o.bvin);

                if (p.Action == MerchantTribe.Payment.ActionType.RewardPointsInfo ||
                    p.Action == MerchantTribe.Payment.ActionType.RewardPointsHold)
                {
                    // 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) ||
                        p.HasSuccessfulLinkedAction(MerchantTribe.Payment.ActionType.RewardPointsCapture, transactions)
                        )
                    {
                        continue;
                    }

                    try
                    {
                        MerchantTribe.Payment.Transaction t = o.GetEmptyTransaction();
                        t.Amount = p.Amount;
                        t.RewardPoints = pointsManager.PointsNeededForPurchaseAmount(p.Amount);
                        t.Customer.UserId = o.UserID;

                        if (p.Action == MerchantTribe.Payment.ActionType.RewardPointsHold)
                        {
                            t.Action = MerchantTribe.Payment.ActionType.RewardPointsCapture;
                        }
                        else
                        {
                            t.Action = MerchantTribe.Payment.ActionType.RewardPointsDecrease;
                        }

                        
                        processor.ProcessTransaction(t);

                        Orders.OrderTransaction ot = new Orders.OrderTransaction(t);
                        ot.LinkedToTransaction = p.IdAsString;
                        svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);

                        if (t.Result.Succeeded == false) result = false;

                    }
                    catch (Exception ex)
                    {
                        EventLog.LogEvent(ex);
                    }
                }

                Orders.OrderPaymentStatus previousPaymentStatus = o.PaymentStatus;
                svc.EvaluatePaymentStatus(o);
                BusinessRules.OrderTaskContext context = new BusinessRules.OrderTaskContext(this.MTApp);
                context.Order = o;
                context.UserId = o.UserID;
                context.Inputs.Add("bvsoftware", "PreviousPaymentStatus", previousPaymentStatus.ToString());
                BusinessRules.Workflow.RunByName(context, BusinessRules.WorkflowNames.PaymentChanged);
            }

            return result;
        }
        public bool RewardsPointsUnHold(OrderTransaction holdTransaction, decimal amount)
        {
            if (holdTransaction == null) return false;            

            Transaction t = o.GetEmptyTransaction();
            t.Action = ActionType.RewardPointsUnHold;
            int points = pointsManager.PointsNeededForPurchaseAmount(EnsurePositiveAmount(amount));
            t.RewardPoints = points;
            t.Customer.UserId = o.UserID;
            t.Amount = EnsurePositiveAmount(amount);
            OrderTransaction ot = new OrderTransaction(t);

            if (holdTransaction.Action != ActionType.RewardPointsHold)
            {
                ot.Success = false;
                ot.Messages = "Transaction must be Rewards Points Hold type to process.";
                return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
            }
            
            Payment.RewardPoints processor = new RewardPoints();
            processor.Settings = new RewardPointsSettings(this.MTApp.CurrentStore.Id)
            {
                PointsIssuedPerDollarSpent = pointsManager.PointsToIssueForSpend(1),
                PointsNeededForDollarCredit = pointsManager.PointsNeededForPurchaseAmount(1)
            };

            if (processor != null)
            {
                processor.ProcessTransaction(t);
                ot = new OrderTransaction(t);
                ot.LinkedToTransaction = holdTransaction.IdAsString;

                if (ot.Success)
                {
                    holdTransaction.Voided = true;
                    svc.Transactions.Update(holdTransaction);
                }
            }

            return svc.AddPaymentTransactionToOrder(o, ot, this.MTApp);
        }