Exemplo n.º 1
0
        private static void VoidPayment_Federated(string orderId = "")
        {
            Console.WriteLine("Begin DeleteFederatedPaymentUX");

            if (string.IsNullOrEmpty(orderId))
            {
                orderId = _orderId;
            }

            var container = new AnonymousCustomerBob().Context.ShopsContainer();
            var order     = Orders.GetOrder(container, orderId);
            var paymentId = order.Components.OfType <Sitecore.Commerce.Plugin.Payments.FederatedPaymentComponent>().FirstOrDefault()?.Id;

            var view = Proxy.GetValue(ShopsContainer.GetEntityView(orderId, "OrderPayments", "VoidPayment", paymentId));

            view.Should().NotBeNull();
            view.Properties.Should().NotBeEmpty();
            var result = Proxy.DoCommand(ShopsContainer.DoAction(view));

            result.Should().NotBeNull();
            result.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse();

            // Get the OrderPayments View and validate that the payment is now gone
            var paymentsView = Proxy.GetValue(ShopsContainer.GetEntityView(orderId, "OrderPayments", string.Empty, string.Empty));

            paymentsView.ChildViews.Count().Should().Be(0);
        }
Exemplo n.º 2
0
        private static void RefundPayment_Federated()
        {
            Console.WriteLine("Begin RefundFederatedPaymentUX");

            var context   = new AnonymousCustomerBob().Context;
            var container = context.ShopsContainer();
            var orderid   = Scenarios.SimplePhysical2Items.Run(new AnonymousCustomerBob().Context).Result;
            var order     = Orders.GetOrder(container, orderid);
            var paymentId = order.Components.OfType <Sitecore.Commerce.Plugin.Payments.FederatedPaymentComponent>().FirstOrDefault()?.Id;

            Orders.RunPendingOrdersMinion(context);
            Orders.RunReleasedOrdersMinion(context);
            Orders.RunSettleSalesActivitiesMinion(context);
            var view = Proxy.GetValue(ShopsContainer.GetEntityView(orderid, "RefundPayment", "RefundPayment", paymentId));

            var result = Proxy.DoCommand(ShopsContainer.DoAction(view));

            result.Should().NotBeNull();
            result.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse();

            var updatedOrderView = Proxy.GetValue(ShopsContainer.GetEntityView(orderid, "Master", string.Empty, string.Empty));

            var salesActivities = updatedOrderView.ChildViews.FirstOrDefault(p => p.Name.Equals("SalesActivities")) as EntityView;

            salesActivities.Should().NotBeNull();
            //There should be 2 Sales Activities now. The original one and the one for the refund.
            salesActivities?.ChildViews.Count.Should().Be(2);

            // Get the OrderPayments View and validate that the payment is now gone
            var paymentsView = Proxy.GetValue(ShopsContainer.GetEntityView(orderid, "OrderPayments", string.Empty, string.Empty));

            paymentsView.ChildViews.Count().Should().Be(0);
        }
Exemplo n.º 3
0
        private static Order CreateCompletedOrder()
        {
            var orderId = Buy1ItemMultipleQuantity.Run(_context);

            orderId.Should().NotBeNullOrEmpty();

            var order = Orders.GetOrder(_context.ShopsContainer(), orderId);

            order.Should().NotBeNull();
            order.Lines.Should().NotBeEmpty();
            order.Lines.FirstOrDefault().Should().NotBeNull();

            var lineId = order.Lines.FirstOrDefault()?.Id;

            lineId.Should().NotBeNullOrEmpty();

            var paymentId = order.Components.OfType <PaymentComponent>().FirstOrDefault()?.Id;

            paymentId.Should().NotBeNullOrEmpty();

            Orders.RunPendingOrdersMinion(_context);
            Orders.RunReleasedOrdersMinion(_context);

            return(order);
        }
Exemplo n.º 4
0
        private static void VoidPayment_Federated(string orderId = "")
        {
            using (new SampleMethodScope())
            {
                if (string.IsNullOrEmpty(orderId))
                {
                    orderId = _orderId;
                }

                var container = new AnonymousCustomerBob().Context.ShopsContainer();
                var order     = Orders.GetOrder(container, orderId);
                var paymentId = order.Components.OfType <FederatedPaymentComponent>()
                                .FirstOrDefault()
                                ?.Id;

                var view = Proxy.GetValue(
                    ShopsContainer.GetEntityView(orderId, "OrderPayments", "VoidPayment", paymentId));
                view.Should().NotBeNull();
                view.Properties.Should().NotBeEmpty();
                var result = Proxy.DoCommand(ShopsContainer.DoAction(view));
                result.Should().NotBeNull();
                result.Messages.Should().NotContainErrors();

                // Get the OrderPayments View and validate that the payment is now gone
                var paymentsView = Proxy.GetValue(
                    ShopsContainer.GetEntityView(orderId, "OrderPayments", string.Empty, string.Empty));
                paymentsView.ChildViews.Count().Should().Be(0);
            }
        }
Exemplo n.º 5
0
        private static string RequestRma(string orderId, string lineId, decimal quantity)
        {
            using (new SampleMethodScope())
            {
                var result =
                    Proxy.DoCommand(
                        _context.ShopsContainer()
                        .RequestRma(
                            orderId,
                            "ConsoleWrongItem",
                            lines: new List <RmaLineComponent>
                {
                    new RmaLineComponent
                    {
                        LineId   = lineId,
                        Quantity = quantity
                    }
                }));
                result.Should().NotBeNull();
                result.Messages.Should().NotContainErrors();
                var rmaId = result.Models.OfType <PersistedEntityModel>().FirstOrDefault(m => m.Name.Equals(typeof(ReturnMerchandiseAuthorization).FullName))?.EntityId;
                rmaId.Should().NotBeNullOrEmpty();
                var rmaFriendlyId = result.Models.OfType <PersistedEntityModel>().FirstOrDefault(m => m.Name.Equals(typeof(ReturnMerchandiseAuthorization).FullName))?.EntityFriendlyId;
                rmaFriendlyId.Should().NotBeNullOrEmpty();

                var rma = GetRma(_context.ShopsContainer(), rmaId);
                rma.Status.Should().Be("Pending");
                rma.Lines.Should().Contain(l => l.LineId.Equals(lineId));
                rma.Order.EntityTarget.Should().Be(orderId);
                rma.ItemsReturnedDate.Should().Be(DateTimeOffset.MinValue);
                rma.RefundPaymentId.Should().NotBeEmpty();

                var order = Orders.GetOrder(_context.ShopsContainer(), orderId);
                order.Should().NotBeNull();
                order.Components.OfType <OrderRmasComponent>().FirstOrDefault().Should().NotBeNull();
                order.Components.OfType <OrderRmasComponent>().FirstOrDefault()?.Returns.Should().NotBeEmpty();
                order.Components.OfType <OrderRmasComponent>()
                .FirstOrDefault()
                ?.Returns.FirstOrDefault(r => r.Rma.EntityTarget.Equals(rma.Id))
                .Should()
                .NotBeNull();
                order.Components.OfType <OrderRmasComponent>()
                .FirstOrDefault()
                ?.Returns.FirstOrDefault(r => r.Rma.EntityTarget.Equals(rma.Id))
                ?.Lines.Should()
                .NotBeEmpty();
                order.Components.OfType <OrderRmasComponent>()
                .FirstOrDefault()
                ?.Returns.FirstOrDefault(r => r.Rma.EntityTarget.Equals(rma.Id))
                ?.Lines.Count.Should()
                .Be(rma.Lines.Count);
                order.Components.OfType <OrderRmasComponent>()
                .FirstOrDefault()
                ?.Returns.FirstOrDefault(r => r.Rma.EntityTarget.Equals(rma.Id))
                ?.Lines.Should()
                .Contain(rma.Lines.Select(l => l.LineId));

                return(rmaFriendlyId);
            }
        }
Exemplo n.º 6
0
        private static Order CreateCompletedOrder()
        {
            var orderId = Scenarios.Buy1ItemMultipleQuantity.Run(_context).Result;

            orderId.Should().NotBeNullOrEmpty();

            var order = Orders.GetOrder(_context.ShopsContainer(), orderId);

            order.Should().NotBeNull();
            order.Lines.Should().NotBeEmpty();
            order.Lines.FirstOrDefault().Should().NotBeNull();

            var lineId = order.Lines.FirstOrDefault()?.Id;

            lineId.Should().NotBeNullOrEmpty();

            var paymentId = order.Components.OfType <Sitecore.Commerce.Plugin.Payments.PaymentComponent>().FirstOrDefault()?.Id;

            paymentId.Should().NotBeNullOrEmpty();

            Orders.RunPendingOrdersMinion(_context);
            Orders.RunSettleSalesActivitiesMinion(_context);
            Orders.RunReleasedOrdersMinion(_context);
            WriteListCounts(_context.ShopsContainer());

            return(order);
        }
Exemplo n.º 7
0
        public static void ReturnedItemReceived(Engine.Container container, string rmaFriendlyId, string orderId, string lineId)
        {
            var result = Proxy.DoCommand(container.ReturnedItemReceived(rmaFriendlyId));

            result.Should().NotBeNull();
            result.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse();

            var rma = GetRma(container, rmaFriendlyId);

            rma.Status.Should().Be("RefundPending");
            rma.ItemsReturnedDate.Should().BeCloseTo(DateTimeOffset.UtcNow, 2000);

            var order = Orders.GetOrder(container, orderId);

            order.Should().NotBeNull();
            order.Components.OfType <OrderRmasComponent>().FirstOrDefault().Should().NotBeNull();
            order.Components.OfType <OrderRmasComponent>().FirstOrDefault()?.Returns.Should().NotBeEmpty();
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId)).Should().NotBeNull();
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))?.CartLineComponents.OfType <ItemReturnedComponent>().Any().Should().BeTrue();
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))?.CartLineComponents.OfType <ItemReturnedComponent>().FirstOrDefault()?.Returns.Should().NotBeEmpty();
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))?.CartLineComponents.OfType <ItemReturnedComponent>().FirstOrDefault()?.Returns.Count.Should().Be(order.Components.OfType <OrderRmasComponent>().FirstOrDefault()?.Returns.Count);
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))?.CartLineComponents.OfType <ItemReturnedComponent>().FirstOrDefault()?.Returns.OrderByDescending(r => r.ReturnedDate).FirstOrDefault().Should().NotBeNull();
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))?.CartLineComponents.OfType <ItemReturnedComponent>().FirstOrDefault()?.Returns.OrderByDescending(r => r.ReturnedDate).FirstOrDefault()?.Quantity.Should().Be(rma.Lines.FirstOrDefault()?.Quantity);
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))?.CartLineComponents.OfType <ItemReturnedComponent>().FirstOrDefault()?.Returns.OrderByDescending(r => r.ReturnedDate).FirstOrDefault()?.ReturnedDate.Should().BeCloseTo(DateTimeOffset.UtcNow, 2000);

            WriteListCounts(container);
        }
Exemplo n.º 8
0
        private static Order CreateDigitalCompletedOrder()
        {
            var orderId = BuyWarranty.Run(_context, 2);

            orderId.Should().NotBeNullOrEmpty();

            var order = Orders.GetOrder(_context.ShopsContainer(), orderId);

            order.Should().NotBeNull();

            Orders.RunPendingOrdersMinion(_context);
            Orders.RunReleasedOrdersMinion(_context);

            return(order);
        }
Exemplo n.º 9
0
        private static string RequestRma(string orderId, string lineId, decimal quantity)
        {
            Console.WriteLine("Begin RequestRma");

            var result =
                Proxy.DoCommand(
                    _context.ShopsContainer().RequestRma(
                        orderId,
                        "ConsoleWrongItem",
                        lines: new List <RmaLineComponent>
            {
                new RmaLineComponent
                {
                    LineId   = lineId,
                    Quantity = quantity
                }
            }));

            result.Should().NotBeNull();
            result.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse();
            result.Models.Should().NotBeEmpty();
            result.Models.OfType <RmaAdded>().FirstOrDefault().Should().NotBeNull();
            var rmaFriendlyId = result.Models.OfType <RmaAdded>().FirstOrDefault()?.RmaId;

            rmaFriendlyId.Should().NotBeNullOrEmpty();

            var rma = GetRma(_context.ShopsContainer(), rmaFriendlyId);

            rma.Status.Should().Be("Pending");
            rma.Lines.Should().Contain(l => l.LineId.Equals(lineId));
            rma.Order.EntityTarget.Should().Be(orderId);
            rma.ItemsReturnedDate.Should().Be(DateTimeOffset.MinValue);
            rma.RefundPaymentId.Should().NotBeEmpty();

            var order = Orders.GetOrder(_context.ShopsContainer(), orderId);

            order.Should().NotBeNull();
            order.Components.OfType <OrderRmasComponent>().FirstOrDefault().Should().NotBeNull();
            order.Components.OfType <OrderRmasComponent>().FirstOrDefault()?.Returns.Should().NotBeEmpty();
            order.Components.OfType <OrderRmasComponent>().FirstOrDefault()?.Returns.FirstOrDefault(r => r.Rma.EntityTarget.Equals(rma.Id)).Should().NotBeNull();
            order.Components.OfType <OrderRmasComponent>().FirstOrDefault()?.Returns.FirstOrDefault(r => r.Rma.EntityTarget.Equals(rma.Id))?.Lines.Should().NotBeEmpty();
            order.Components.OfType <OrderRmasComponent>().FirstOrDefault()?.Returns.FirstOrDefault(r => r.Rma.EntityTarget.Equals(rma.Id))?.Lines.Count.Should().Be(rma.Lines.Count);
            order.Components.OfType <OrderRmasComponent>().FirstOrDefault()?.Returns.FirstOrDefault(r => r.Rma.EntityTarget.Equals(rma.Id))?.Lines.Should().Contain(rma.Lines.Select(l => l.LineId));

            WriteListCounts(_context.ShopsContainer());

            return(rmaFriendlyId);
        }
        private static Order ValidateOrder(ShopperContext context, string orderId)
        {
            var order = Orders.GetOrder(context.ShopsContainer(), orderId);

            order.Should().NotBeNull();
            order.Status.Should().Be("Completed");

            order.Components.OfType <EntitlementsComponent>().Any().Should().BeTrue();
            var entitlementsComponent = order.Components.OfType <EntitlementsComponent>().FirstOrDefault();

            entitlementsComponent.Should().NotBeNull();
            entitlementsComponent?.Entitlements.Should().NotBeEmpty();
            entitlementsComponent?.Entitlements.All(e => !string.IsNullOrEmpty(e.EntityTarget)).Should().BeTrue();

            return(order);
        }
Exemplo n.º 11
0
        private static Order CreateDigitalCompletedOrder()
        {
            var orderId = Scenarios.BuyWarranty.Run(_context, 2).Result;

            orderId.Should().NotBeNullOrEmpty();

            var order = Orders.GetOrder(_context.ShopsContainer(), orderId);

            order.Should().NotBeNull();

            Orders.RunPendingOrdersMinion(_context);
            Orders.RunSettleSalesActivitiesMinion(_context);
            Orders.RunReleasedOrdersMinion(_context);

            return(order);
        }
Exemplo n.º 12
0
        private static void RefundPayment_Federated()
        {
            using (new SampleMethodScope())
            {
                var context   = new AnonymousCustomerBob().Context;
                var container = context.ShopsContainer();
                var orderid   = SimplePhysical2Items.Run(new AnonymousCustomerBob().Context);
                var order     = Orders.GetOrder(container, orderid);
                var paymentId = order.Components.OfType <FederatedPaymentComponent>()
                                .FirstOrDefault()
                                ?.Id;

                Orders.RunPendingOrdersMinion(context);
                Orders.RunReleasedOrdersMinion(context);
                var view = Proxy.GetValue(
                    ShopsContainer.GetEntityView(orderid, "RefundPayment", "RefundPayment", paymentId));

                var result = Proxy.DoCommand(ShopsContainer.DoAction(view));

                result.Should().NotBeNull();
                result.Messages.Should().NotContainErrors();

                var updatedOrderView = Proxy.GetValue(
                    ShopsContainer.GetEntityView(orderid, "Master", string.Empty, string.Empty));

                var salesActivities =
                    updatedOrderView.ChildViews.FirstOrDefault(p => p.Name.Equals("SalesActivities")) as EntityView;
                salesActivities.Should().NotBeNull();

                //There should be 2 Sales Activities now. The original one and the one for the refund.
                salesActivities?.ChildViews.Count.Should().Be(2);

                // Get the OrderPayments View and validate that the payment is now gone
                var paymentsView = Proxy.GetValue(
                    ShopsContainer.GetEntityView(orderid, "OrderPayments", string.Empty, string.Empty));
                paymentsView.ChildViews.Count().Should().Be(0);
            }
        }
Exemplo n.º 13
0
        private static void OnHoldScenarios()
        {
            var jeff      = new AnonymousCustomerJeff();
            var container = jeff.Context.ShopsContainer();

            var orderId = Scenarios.SimplePhysical2Items.Run(jeff.Context).Result;

            orderId.Should().NotBeNull();

            // hold order
            HoldOrder(orderId);

            // Get an Order Master view
            var orderMaster = Proxy.GetEntityView(container, orderId, "Master", string.Empty, string.Empty);

            // Adjustments
            var adjustments = orderMaster.ChildViews.FirstOrDefault(p => p.Name == "Adjustments") as EntityView;

            adjustments.Should().NotBeNull();
            adjustments.ChildViews.Count.Should().NotBe(0);
            var adjustment = adjustments.ChildViews[0] as EntityView;

            adjustment.DisplayName.Should().Be("Adjustment");
            adjustment.Properties.FirstOrDefault(p => p.Name == "Adjustment")?.Value.Should().NotBeEmpty();
            adjustment.Properties.FirstOrDefault(p => p.Name == "Type")?.Value.Should().NotBeEmpty();

            // Messages
            var messages = orderMaster.ChildViews.FirstOrDefault(p => p.Name == "Messages") as EntityView;

            messages.Should().NotBeNull();
            messages.ChildViews.Count.Should().NotBe(0);
            var message = messages.ChildViews[0] as EntityView;

            message.DisplayName.Should().Be("Message");
            message.Properties.FirstOrDefault(p => p.Name == "Code")?.Value.Should().NotBeEmpty();
            message.Properties.FirstOrDefault(p => p.Name == "Text")?.Value.Should().NotBeEmpty();

            // Edit line
            var lines = orderMaster.ChildViews.FirstOrDefault(p => p.Name == "Lines") as EntityView;

            lines?.Policies.OfType <ActionsPolicy>().First().Actions.First(p => p.Name == "AddLineItem").IsEnabled.Should().Be(true);
            var line   = lines?.ChildViews.First() as EntityView;
            var itemId = line?.Properties.FirstOrDefault(p => p.Name == "ItemId")?.Value;
            var editLineItemRequest = Proxy.GetEntityView(container, orderId, "EditLineItem", "EditLineItem", itemId);

            editLineItemRequest.Properties.First(p => p.Name == "Quantity").Value = "2";
            var actionResult = Proxy.GetValue(container.DoAction(editLineItemRequest));

            actionResult.ResponseCode.Should().Be("Ok");
            var totals = actionResult.Models.OfType <Sitecore.Commerce.Plugin.Carts.Totals>().FirstOrDefault();

            totals.Should().NotBeNull();

            // add payment
            AddPayment_Federated(totals.GrandTotal.Amount, orderId);

            // Commit the OnHold Order
            CommitOnHoldOrder(orderId);

            var order = Orders.GetOrder(container, orderId);

            order.Status.Should().Be("Pending");

            orderId = Scenarios.SimplePhysical2Items.Run(jeff.Context).Result;
            orderId.Should().NotBeNull();

            // hold order
            HoldOrder(orderId);

            order  = Proxy.GetValue(container.Orders.ByKey(orderId).Expand("Components"));
            totals = order.Totals;

            // Void payment
            VoidPayment_Federated(orderId);

            // add payment
            AddPayment_Federated(totals.GrandTotal.Amount, orderId);

            // Commit the OnHold Order
            CommitOnHoldOrder(orderId);

            order = Orders.GetOrder(container, orderId);
            order.Status.Should().Be("Pending");
        }
Exemplo n.º 14
0
        public static void ReturnedItemReceived(
            Container container,
            string rmaFriendlyId,
            string orderId,
            string lineId)
        {
            var result = Proxy.DoCommand(container.ReturnedItemReceived(rmaFriendlyId));

            result.Should().NotBeNull();
            result.Messages.Should().NotContainErrors();
            var rmaId = result.Models.OfType <PersistedEntityModel>().FirstOrDefault(m => m.Name.Equals(typeof(ReturnMerchandiseAuthorization).FullName))?.EntityId;

            rmaId.Should().NotBeNullOrEmpty();

            var rma = GetRma(container, rmaId);

            rma.Status.Should().Be("RefundPending");
            rma.ItemsReturnedDate.Should().BeCloseTo(DateTimeOffset.UtcNow, 5000);

            var order = Orders.GetOrder(container, orderId);

            order.Should().NotBeNull();
            order.Components.OfType <OrderRmasComponent>().FirstOrDefault().Should().NotBeNull();
            order.Components.OfType <OrderRmasComponent>().FirstOrDefault()?.Returns.Should().NotBeEmpty();
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId)).Should().NotBeNull();
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))
            ?.CartLineComponents.OfType <ItemReturnedComponent>()
            .Any()
            .Should()
            .BeTrue();
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))
            ?.CartLineComponents.OfType <ItemReturnedComponent>()
            .FirstOrDefault()
            ?.Returns.Should()
            .NotBeEmpty();
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))
            ?.CartLineComponents.OfType <ItemReturnedComponent>()
            .FirstOrDefault()
            ?.Returns.Count.Should()
            .Be(order.Components.OfType <OrderRmasComponent>().FirstOrDefault()?.Returns.Count);
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))
            ?.CartLineComponents.OfType <ItemReturnedComponent>()
            .FirstOrDefault()
            ?.Returns.OrderByDescending(r => r.ReturnedDate)
            .FirstOrDefault()
            .Should()
            .NotBeNull();
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))
            ?.CartLineComponents.OfType <ItemReturnedComponent>()
            .FirstOrDefault()
            ?.Returns.OrderByDescending(r => r.ReturnedDate)
            .FirstOrDefault()
            ?.Quantity.Should()
            .Be(rma.Lines.FirstOrDefault()?.Quantity);
            order.Lines.FirstOrDefault(l => l.Id.Equals(lineId))
            ?.CartLineComponents.OfType <ItemReturnedComponent>()
            .FirstOrDefault()
            ?.Returns.OrderByDescending(r => r.ReturnedDate)
            .FirstOrDefault()
            ?.ReturnedDate.Should()
            .BeCloseTo(DateTimeOffset.UtcNow, 5000);
        }