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)
        {
            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;
        }
Exemplo n.º 3
0
        // working with local dates and times
        public static void GenerateInvoiceForStore(Store s, DateTime invoiceDateLocal, MerchantTribeApplication app)
        {
            // Create an Order
            Orders.Order o = new Orders.Order();
            o.StoreId = WebAppSettings.BillingStoreId;
            app.OrderServices.Orders.Create(o);

            o.Notes.Add(new Orders.OrderNote() { IsPublic = false, Note = "Auto Generated By Invoicing System" });

            // Base Rate
            Orders.LineItem li = new Orders.LineItem();
            li.BasePricePerItem = s.CurrentPlanRate;
            li.ProductName = "BV Commerce Hosted: " + s.PlanName;
            li.ProductSku = "BVH" + s.PlanId;
            li.Quantity = 1;
            li.QuantityShipped = 1;
            li.ShippingSchedule = -1;
            o.Items.Add(li);

            // need to add Percent of sales
            decimal lastMonthSales = 0;
            // End date should be immediately before bill not, not on the bill date
            DateTime localEnd = Dates.MaxOutTime(invoiceDateLocal);
            localEnd = localEnd.AddDays(-1);
            DateTime localStart = Dates.ZeroOutTime(invoiceDateLocal).AddMonths(-1);
            lastMonthSales = app.OrderServices.Transactions.FindBillableTransactionTotal(localStart.ToUniversalTime(),
                                                                        localEnd.ToUniversalTime(),
                                                                        s.Id);
            Orders.LineItem li2 = new Orders.LineItem();
            Decimal multiplier = s.CurrentPlanPercent / 100;
            Decimal transFees = Math.Round(multiplier * lastMonthSales, 2, MidpointRounding.AwayFromZero);
            li2.BasePricePerItem = transFees;
            li2.ProductName = "Transaction Fees:";
            li2.ProductShortDescription = s.CurrentPlanPercent + "% of " + lastMonthSales.ToString("c");
            li2.ProductShortDescription += " " + localStart.ToShortDateString() + " to " + localEnd.ToShortDateString();
            li2.ProductSku = "BVHTF";
            li2.Quantity = 1;
            li2.QuantityShipped = 1;
            li2.ShippingSchedule = -1;
            o.Items.Add(li2);

            List<UserAccount> users = app.AccountServices.FindAdminUsersByStoreId(s.Id);
            if (users != null)
            {
                if (users.Count > 0)
                {
                    UserAccount u = users[0];
                    o.UserEmail = u.Email;

                    Service svc = new Service(WebAppSettings.ApplicationConnectionString);
                    BillingAccount act = svc.Accounts.FindOrCreate(u.Email);
                    if (act != null)
                    {
                        o.BillingAddress.RegionData.Abbreviation = string.Empty;
                        o.BillingAddress.RegionName = string.Empty;
                        o.BillingAddress.PostalCode = act.BillingZipCode;
                        o.BillingAddress.FirstName = act.CreditCard.CardHolderName;
                        o.BillingAddress.Company = s.StoreName;

                        app.CalculateOrder(o);

                        Orders.OrderPaymentManager payManager = new Orders.OrderPaymentManager(o, app);
                        payManager.CreditCardAddInfo(act.CreditCard, o.TotalGrand);

                        o.OrderNumber = app.OrderServices.GenerateNewOrderNumber(WebAppSettings.BillingStoreId).ToString();
                        o.StatusCode = Orders.OrderStatusCode.Received;
                        o.IsPlaced = true;
                        o.TimeOfOrderUtc = DateTime.UtcNow;
                        o.EvaluateCurrentShippingStatus();

                        app.OrderServices.Orders.Update(o);
                    }
                }
            }
        }
Exemplo n.º 4
0
        // working with local dates and times
        public static void GenerateInvoiceForStore(Store s, DateTime invoiceDateLocal, MerchantTribeApplication app)
        {
            // Create an Order
            Orders.Order o = new Orders.Order();
            o.StoreId = WebAppSettings.BillingStoreId;
            app.OrderServices.Orders.Create(o);

            o.Notes.Add(new Orders.OrderNote()
            {
                IsPublic = false, Note = "Auto Generated By Invoicing System"
            });

            // Base Rate
            Orders.LineItem li = new Orders.LineItem();
            li.BasePricePerItem = s.CurrentPlanRate;
            li.ProductName      = "BV Commerce Hosted: " + s.PlanName;
            li.ProductSku       = "BVH" + s.PlanId;
            li.Quantity         = 1;
            li.QuantityShipped  = 1;
            li.ShippingSchedule = -1;
            o.Items.Add(li);

            // need to add Percent of sales
            decimal lastMonthSales = 0;
            // End date should be immediately before bill not, not on the bill date
            DateTime localEnd = Dates.MaxOutTime(invoiceDateLocal);

            localEnd = localEnd.AddDays(-1);
            DateTime localStart = Dates.ZeroOutTime(invoiceDateLocal).AddMonths(-1);

            lastMonthSales = app.OrderServices.Transactions.FindBillableTransactionTotal(localStart.ToUniversalTime(),
                                                                                         localEnd.ToUniversalTime(),
                                                                                         s.Id);
            Orders.LineItem li2        = new Orders.LineItem();
            Decimal         multiplier = s.CurrentPlanPercent / 100;
            Decimal         transFees  = Math.Round(multiplier * lastMonthSales, 2);

            li2.BasePricePerItem         = transFees;
            li2.ProductName              = "Transaction Fees:";
            li2.ProductShortDescription  = s.CurrentPlanPercent + "% of " + lastMonthSales.ToString("c");
            li2.ProductShortDescription += " " + localStart.ToShortDateString() + " to " + localEnd.ToShortDateString();
            li2.ProductSku       = "BVHTF";
            li2.Quantity         = 1;
            li2.QuantityShipped  = 1;
            li2.ShippingSchedule = -1;
            o.Items.Add(li2);

            List <UserAccount> users = app.AccountServices.FindAdminUsersByStoreId(s.Id);

            if (users != null)
            {
                if (users.Count > 0)
                {
                    UserAccount u = users[0];
                    o.UserEmail = u.Email;

                    Service        svc = new Service(WebAppSettings.ApplicationConnectionString);
                    BillingAccount act = svc.Accounts.FindOrCreate(u.Email);
                    if (act != null)
                    {
                        o.BillingAddress.RegionData.Abbreviation = string.Empty;
                        o.BillingAddress.RegionName = string.Empty;
                        o.BillingAddress.PostalCode = act.BillingZipCode;
                        o.BillingAddress.FirstName  = act.CreditCard.CardHolderName;
                        o.BillingAddress.Company    = s.StoreName;

                        app.CalculateOrder(o);

                        Orders.OrderPaymentManager payManager = new Orders.OrderPaymentManager(o, app);
                        payManager.CreditCardAddInfo(act.CreditCard, o.TotalGrand);

                        o.OrderNumber    = app.OrderServices.GenerateNewOrderNumber(WebAppSettings.BillingStoreId).ToString();
                        o.StatusCode     = Orders.OrderStatusCode.Received;
                        o.IsPlaced       = true;
                        o.TimeOfOrderUtc = DateTime.UtcNow;
                        o.EvaluateCurrentShippingStatus();

                        app.OrderServices.Orders.Update(o);
                    }
                }
            }
        }