public override OrderReference GetOrderReference(HttpRequestBase request, StripeCheckoutOneTimeSettings settings)
        {
            try
            {
                var secretKey            = settings.TestMode ? settings.TestSecretKey : settings.LiveSecretKey;
                var webhookSigningSecret = settings.TestMode ? settings.TestWebhookSigningSecret : settings.LiveWebhookSigningSecret;

                ConfigureStripe(secretKey);

                var stripeEvent = GetWebhookStripeEvent(request, webhookSigningSecret);
                if (stripeEvent != null && stripeEvent.Type == Events.CheckoutSessionCompleted)
                {
                    if (stripeEvent.Data?.Object?.Instance is Session stripeSession && !string.IsNullOrWhiteSpace(stripeSession.ClientReferenceId))
                    {
                        return(OrderReference.Parse(stripeSession.ClientReferenceId));
                    }
                }
            }
            catch (Exception ex)
            {
                Vendr.Log.Error <StripeCheckoutOneTimePaymentProvider>(ex, "Stripe - GetOrderReference");
            }

            return(base.GetOrderReference(request, settings));
        }
Esempio n. 2
0
        public int PlaceCartForQuoteById(int orderId, Guid userId)
        {
            PurchaseOrder purchaseOrder = null;

            try
            {
                var referedOrder = _orderRepository.Load <IPurchaseOrder>(orderId);
                var cart         = _orderRepository.LoadOrCreateCart <ICart>(userId, "RequstQuoteFromOrder");
                foreach (var lineItem in referedOrder.GetFirstForm().GetAllLineItems())
                {
                    var newLineItem = lineItem;
                    newLineItem.Properties[Constants.Quote.PreQuotePrice] = lineItem.PlacedPrice;
                    cart.AddLineItem(newLineItem);
                }
                cart.Currency = referedOrder.Currency;
                cart.Market   = referedOrder.Market;

                OrderReference orderReference = _orderRepository.SaveAsPurchaseOrder(cart);
                purchaseOrder = _orderRepository.Load <PurchaseOrder>(orderReference.OrderGroupId);
                if (purchaseOrder != null)
                {
                    int quoteExpireDays;
                    int.TryParse(ConfigurationManager.AppSettings[Constants.Quote.QuoteExpireDate], out quoteExpireDays);
                    purchaseOrder[Constants.Quote.QuoteExpireDate] =
                        string.IsNullOrEmpty(ConfigurationManager.AppSettings[Constants.Quote.QuoteExpireDate])
                            ? DateTime.Now.AddDays(30)
                            : DateTime.Now.AddDays(quoteExpireDays);

                    purchaseOrder[Constants.Quote.PreQuoteTotal] = purchaseOrder.Total;
                    purchaseOrder[Constants.Quote.QuoteStatus]   = Constants.Quote.RequestQuotation;
                    purchaseOrder.Status = OrderStatus.OnHold.ToString();
                    if (string.IsNullOrEmpty(purchaseOrder[Constants.Customer.CustomerFullName]?.ToString()))
                    {
                        if (CustomerContext.Current != null && CustomerContext.Current.CurrentContact != null)
                        {
                            var contact = CustomerContext.Current.CurrentContact;
                            purchaseOrder[Constants.Customer.CustomerFullName]     = contact.FullName;
                            purchaseOrder[Constants.Customer.CustomerEmailAddress] = contact.Email;
                            if (_organizationService.GetCurrentUserOrganization() != null)
                            {
                                var organization = _organizationService.GetCurrentUserOrganization();
                                purchaseOrder[Constants.Customer.CurrentCustomerOrganization] = organization.Name;
                            }
                        }
                    }
                }
                purchaseOrder.AcceptChanges();
                _orderRepository.Delete(cart.OrderLink);
            }
            catch (Exception ex)
            {
                LogManager.GetLogger(GetType()).Error("Failed to process request quote request.", ex);
            }

            return(purchaseOrder?.Id ?? 0);
        }
 public OrderUpdate(
     OrderReference orderReference,
     DateTime dueDate,
     EmailAddress reminderTo,
     EmailAddress copyReminderTo
     )
 {
     OrderReference = orderReference;
     DueDate = dueDate;
     ReminderTo = reminderTo;
     CopyReminderTo = copyReminderTo;
 }
Esempio n. 4
0
        public FakeOrderGroup()
        {
            Forms = new List <IOrderForm>();
            var market = new MarketImpl(MarketId.Default);

            MarketId         = market.MarketId;
            MarketName       = market.MarketName;
            PricesIncludeTax = market.PricesIncludeTax;
            Currency         = new Currency(Currency.USD);
            OrderLink        = new OrderReference(++_counter, "Default", _customerId, typeof(Cart));
            Properties       = new Hashtable();
            Notes            = new List <IOrderNote>();
        }
Esempio n. 5
0
        public bool PlaceCartForQuote(ICart cart)
        {
            var quoteResult = true;

            try
            {
                foreach (var lineItem in cart.GetFirstForm().GetAllLineItems())
                {
                    lineItem.Properties[Constants.Quote.PreQuotePrice] = lineItem.PlacedPrice;
                }

                OrderReference orderReference = _orderRepository.SaveAsPurchaseOrder(cart);
                PurchaseOrder  purchaseOrder  = _orderRepository.Load <PurchaseOrder>(orderReference.OrderGroupId);
                if (purchaseOrder != null)
                {
                    int quoteExpireDays;
                    int.TryParse(ConfigurationManager.AppSettings[Constants.Quote.QuoteExpireDate], out quoteExpireDays);
                    purchaseOrder[Constants.Quote.QuoteExpireDate] =
                        string.IsNullOrEmpty(ConfigurationManager.AppSettings[Constants.Quote.QuoteExpireDate])
                            ? DateTime.Now.AddDays(30)
                            : DateTime.Now.AddDays(quoteExpireDays);

                    purchaseOrder[Constants.Quote.PreQuoteTotal] = purchaseOrder.Total;
                    purchaseOrder[Constants.Quote.QuoteStatus]   = Constants.Quote.RequestQuotation;
                    purchaseOrder.Status = OrderStatus.OnHold.ToString();
                    if (string.IsNullOrEmpty(purchaseOrder[Constants.Customer.CustomerFullName]?.ToString()))
                    {
                        if (CustomerContext.Current != null && CustomerContext.Current.CurrentContact != null)
                        {
                            var contact = CustomerContext.Current.CurrentContact;
                            purchaseOrder[Constants.Customer.CustomerFullName]     = contact.FullName;
                            purchaseOrder[Constants.Customer.CustomerEmailAddress] = contact.Email;
                            if (_organizationService.GetCurrentUserOrganization() != null)
                            {
                                var organization = _organizationService.GetCurrentUserOrganization();
                                purchaseOrder[Constants.Customer.CurrentCustomerOrganization] = organization.Name;
                            }
                        }
                    }
                }
                _orderRepository.Save(purchaseOrder);
            }
            catch (Exception ex)
            {
                quoteResult = false;
                LogManager.GetLogger(GetType()).Error("Failed to process request quote request.", ex);
            }

            return(quoteResult);
        }
Esempio n. 6
0
 public DespatchAdvice()
 {
     UblExtensions  = new UblExtensions();
     OrderReference = new OrderReference();
     AdditionalDocumentReference = new InvoiceDocumentReference();
     Signature             = new SignatureCac();
     DespatchSupplierParty = new AccountingSupplierParty();
     DeliveryCustomerParty = new AccountingSupplierParty();
     SellerSupplierParty   = new AccountingSupplierParty();
     Shipment        = new Shipment();
     DespatchLines   = new List <DespatchLine>();
     UblVersionId    = "2.0";
     CustomizationId = "1.0";
     Formato         = new System.Globalization.CultureInfo(Formatos.Cultura);
 }
Esempio n. 7
0
        public void CreateOrderOnMultipleThreads_OnlyTwoShouldBeCreated()
        {
            var cart1 = new FakeCart(new Mock <IMarket>().Object, Currency.NOK);
            var cart2 = new FakeCart(new Mock <IMarket>().Object, Currency.NOK);

            var purchaseOrder1 = new FakePurchaseOrder(new Mock <IMarket>().Object, Currency.NOK);
            var purchaseOrder2 = new FakePurchaseOrder(new Mock <IMarket>().Object, Currency.NOK);

            var orderReference1 = new OrderReference(1, "", Guid.Empty, null);
            var orderReference2 = new OrderReference(2, "", Guid.Empty, null);

            _orderRepositoryMock.Setup(x => x.SaveAsPurchaseOrder(cart1))
            .Returns(() => orderReference1);

            _orderRepositoryMock.Setup(x => x.SaveAsPurchaseOrder(cart2))
            .Returns(() => orderReference2);

            _vippsServiceMock.SetupSequence(x => x.GetPurchaseOrderByOrderId("1"))
            .Returns(null)
            .Returns(purchaseOrder1)
            .Returns(purchaseOrder1)
            .Returns(purchaseOrder1)
            .Returns(purchaseOrder1)
            .Returns(purchaseOrder1)
            .Returns(purchaseOrder1);

            _vippsServiceMock.SetupSequence(x => x.GetPurchaseOrderByOrderId("2"))
            .Returns(null)
            .Returns(purchaseOrder2);

            var responseList = new List <LoadOrCreatePurchaseOrderResponse>();

            Parallel.Invoke(async() => responseList.Add(await _subject.LoadOrCreatePurchaseOrder(cart1, "1")),
                            async() => responseList.Add(await _subject.LoadOrCreatePurchaseOrder(cart1, "1")),
                            async() => responseList.Add(await _subject.LoadOrCreatePurchaseOrder(cart1, "1")),
                            async() => responseList.Add(await _subject.LoadOrCreatePurchaseOrder(cart1, "1")),
                            async() => responseList.Add(await _subject.LoadOrCreatePurchaseOrder(cart2, "2")),
                            async() => responseList.Add(await _subject.LoadOrCreatePurchaseOrder(cart1, "1")),
                            async() => responseList.Add(await _subject.LoadOrCreatePurchaseOrder(cart2, "2")),
                            async() => responseList.Add(await _subject.LoadOrCreatePurchaseOrder(cart1, "1")),
                            async() => responseList.Add(await _subject.LoadOrCreatePurchaseOrder(cart1, "1"))
                            );

            var createdOrders = responseList.Where(x => x.PurchaseOrderCreated);

            Assert.Equal(2, createdOrders.Count());
        }
Esempio n. 8
0
        public void PlaceOrder_WhenPaymentProcessingFails_ShouldReturnNullAndAddModelError()
        {
            var cartTotal = new Money(1, Currency.USD);

            _orderGroupCalculatorMock.Setup(x => x.GetTotal(It.IsAny <IOrderGroup>())).Returns(() => cartTotal);

            _orderRepositoryMock.Setup(x => x.Load <IPurchaseOrder>(It.IsAny <int>())).Returns(new Mock <IPurchaseOrder>().Object);

            var orderReference = new OrderReference(0, "", Guid.Empty, null);

            _orderRepositoryMock.Setup(x => x.SaveAsPurchaseOrder(It.IsAny <ICart>())).Returns(() => orderReference);

            var cart = new FakeCart(new MarketImpl(MarketId.Empty), Currency.SEK);

            cart.GetFirstForm().Payments.Add(new FakePayment {
                Status = PaymentStatus.Processed.ToString(), Amount = 1
            });

            var modelState = new ModelStateDictionary();

            var paymentMethodMock = new Mock <CashOnDeliveryPaymentMethod>(null, null);

            paymentMethodMock.Setup(x => x.PostProcess(It.IsAny <IPayment>())).Throws(new PaymentException("", "", ""));

            var viewModel = new CheckoutViewModel
            {
                BillingAddress = new AddressModel {
                    AddressId = "billingAddress"
                },
                Payment = new PaymentMethodViewModel <PaymentMethodBase>
                {
                    PaymentMethod = paymentMethodMock.Object
                }
            };

            var result = _subject.PlaceOrder(cart, modelState, viewModel);

            Assert.Null(result);
            Assert.Equal(1, modelState.Count(x => x.Value.Errors.Count > 0));
        }
Esempio n. 9
0
        public override async Task <OrderReference> GetOrderReferenceAsync(PaymentProviderContext <TSettings> ctx)
        {
            try
            {
                var secretKey            = ctx.Settings.TestMode ? ctx.Settings.TestSecretKey : ctx.Settings.LiveSecretKey;
                var webhookSigningSecret = ctx.Settings.TestMode ? ctx.Settings.TestWebhookSigningSecret : ctx.Settings.LiveWebhookSigningSecret;

                ConfigureStripe(secretKey);

                var stripeEvent = await GetWebhookStripeEventAsync(ctx, webhookSigningSecret);

                if (stripeEvent != null && stripeEvent.Type == Events.CheckoutSessionCompleted)
                {
                    if (stripeEvent.Data?.Object?.Instance is Session stripeSession && !string.IsNullOrWhiteSpace(stripeSession.ClientReferenceId))
                    {
                        return(OrderReference.Parse(stripeSession.ClientReferenceId));
                    }
                }
                else if (stripeEvent != null && stripeEvent.Type == Events.ReviewClosed)
                {
                    if (stripeEvent.Data?.Object?.Instance is Review stripeReview && !string.IsNullOrWhiteSpace(stripeReview.PaymentIntentId))
                    {
                        var paymentIntentService = new PaymentIntentService();
                        var paymentIntent        = paymentIntentService.Get(stripeReview.PaymentIntentId);

                        if (paymentIntent != null && paymentIntent.Metadata.ContainsKey("orderReference"))
                        {
                            return(OrderReference.Parse(paymentIntent.Metadata["orderReference"]));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Stripe - GetOrderReference");
            }

            return(await base.GetOrderReferenceAsync(ctx));
        }
Esempio n. 10
0
        public override OrderReference GetOrderReference(HttpRequestBase request, PayPalCheckoutOneTimeSettings settings)
        {
            try
            {
                var clientConfig       = GetPayPalClientConfig(settings);
                var client             = new PayPalClient(clientConfig);
                var payPalWebhookEvent = GetPayPalWebhookEvent(client, request);

                if (payPalWebhookEvent != null && payPalWebhookEvent.EventType.StartsWith("CHECKOUT.ORDER."))
                {
                    var payPalOrder = payPalWebhookEvent.Resource.ToObject <PayPalOrder>();
                    if (payPalOrder?.PurchaseUnits != null && payPalOrder.PurchaseUnits.Length == 1)
                    {
                        return(OrderReference.Parse(payPalOrder.PurchaseUnits[0].CustomId));
                    }
                }
            }
            catch (Exception ex)
            {
                Vendr.Log.Error <PayPalCheckoutOneTimePaymentProvider>(ex, "PayPal - GetOrderReference");
            }

            return(base.GetOrderReference(request, settings));
        }
Esempio n. 11
0
        public virtual IHttpActionResult DeleteOrder(int orderGroupId)
        {
            Logger.LogDelete("DeleteOrder", Request, new[] { orderGroupId.ToString() });

            var existingOrder = _orderRepository.Load <PurchaseOrder>(orderGroupId);

            if (existingOrder == null)
            {
                return(NotFound());
            }

            try
            {
                var orderReference = new OrderReference(orderGroupId, existingOrder.Name, existingOrder.CustomerId, typeof(PurchaseOrder));

                _orderRepository.Delete(orderReference);
                return(Ok());
            }
            catch (Exception exception)
            {
                Logger.Error(exception.Message, exception);
                return(InternalServerError(exception));
            }
        }
Esempio n. 12
0
 public void OnDeleted(OrderReference orderReference)
 {
     //throw new NotImplementedException();
 }
 public void OnDeleted(OrderReference orderReference)
 {
     _logger.Information(string.Format("Deleted order {0}: orderid [{1}], customer [{2}], name[{3}].", orderReference.OrderType, orderReference.OrderGroupId, orderReference.CustomerId, orderReference.Name));
 }
Esempio n. 14
0
 public void OnUpdated(OrderReference orderReference)
 {
     //throw new NotImplementedException();
     EventReciever.RecordNewOrderEvents(orderReference);
 }
Esempio n. 15
0
 public void OnUpdating(OrderReference orderReference)
 {
     //throw new NotImplementedException();
 }
Esempio n. 16
0
 public static void RecordNewOrderEvents(OrderReference orderReference)
 {
     BfEventManager.SendToBF("FrontEnd", orderReference.OrderGroupId.ToString() + " was changed", "NewOrderEvents");
 }
        public CheckoutControllerTests()
        {
            _controllerExceptionHandlerMock = new Mock <ControllerExceptionHandler>();
            _requestContextMock             = new Mock <RequestContext>();
            _httpRequestBaseMock            = new Mock <HttpRequestBase>();
            _httpContextBaseMock            = new Mock <HttpContextBase>();
            _contentRepositoryMock          = new Mock <IContentRepository>();
            _mailServiceMock                  = new Mock <IMailService>();
            _localizationService              = new MemoryLocalizationService();
            _currencyServiceMock              = new Mock <ICurrencyService>();
            _customerContextFacadeMock        = new Mock <CustomerContextFacade>();
            _orderRepositoryMock              = new Mock <IOrderRepository>();
            _orderGroupCalculatorMock         = new Mock <IOrderGroupCalculator>();
            _paymentProcessorMock             = new Mock <IPaymentProcessor>();
            _promotionEngineMock              = new Mock <IPromotionEngine>();
            _cartServiceMock                  = new Mock <ICartService>();
            _addressBookServiceMock           = new Mock <IAddressBookService>();
            _orderSummaryViewModelFactoryMock = new Mock <OrderSummaryViewModelFactory>(null, null, null, null);
            _checkoutViewModelFactoryMock     = new Mock <CheckoutViewModelFactory>(null, null, null, null, null, null, null, null);
            _orderFactoryMock                 = new Mock <IOrderFactory>();
            _cart             = new FakeCart(null, new Currency("USD"));
            _exceptionContext = new ExceptionContext
            {
                HttpContext    = _httpContextBaseMock.Object,
                RequestContext = _requestContextMock.Object
            };
            var customerId     = Guid.NewGuid();
            var orderReference = new OrderReference(1, "PurchaseOrder", customerId, typeof(InMemoryPurchaseOrder));
            var purchaseOrder  = new InMemoryPurchaseOrder {
                Name = orderReference.Name, Currency = _cart.Currency, CustomerId = customerId, OrderLink = orderReference
            };

            var paymentMock = new Mock <ICreditCardPayment>();

            paymentMock.SetupGet(x => x.CreditCardNumber).Returns("423465654");
            paymentMock.SetupGet(x => x.Status).Returns(PaymentStatus.Pending.ToString());

            _httpContextBaseMock.Setup(x => x.Request).Returns(_httpRequestBaseMock.Object);

            _subject = new CheckoutControllerForTest(_contentRepositoryMock.Object, _mailServiceMock.Object, _localizationService,
                                                     _currencyServiceMock.Object, _controllerExceptionHandlerMock.Object, _customerContextFacadeMock.Object, _orderRepositoryMock.Object,
                                                     _checkoutViewModelFactoryMock.Object, _orderGroupCalculatorMock.Object, _paymentProcessorMock.Object, _promotionEngineMock.Object,
                                                     _cartServiceMock.Object, _addressBookServiceMock.Object, _orderSummaryViewModelFactoryMock.Object, _orderFactoryMock.Object);

            _checkoutViewModelFactoryMock
            .Setup(x => x.CreateCheckoutViewModel(It.IsAny <ICart>(), It.IsAny <CheckoutPage>(), It.IsAny <PaymentMethodViewModel <PaymentMethodBase> >()))
            .Returns((ICart cart, CheckoutPage currentPage, PaymentMethodViewModel <PaymentMethodBase> paymentMethodViewModel) => CreateCheckoutViewModel(currentPage, paymentMethodViewModel));

            _orderFactoryMock.Setup(x => x.CreateCardPayment()).Returns(paymentMock.Object);
            _orderRepositoryMock.Setup(x => x.SaveAsPurchaseOrder(_cart)).Returns(orderReference);
            _orderRepositoryMock.Setup(x => x.Load <IPurchaseOrder>(orderReference.OrderGroupId)).Returns(purchaseOrder);

            _contentRepositoryMock.Setup(x => x.Get <StartPage>(It.IsAny <ContentReference>())).Returns(new StartPage());
            _contentRepositoryMock.Setup(x => x.GetChildren <OrderConfirmationPage>(It.IsAny <ContentReference>())).Returns(new[] { new OrderConfirmationPageForTest()
                                                                                                                                    {
                                                                                                                                        Language = new CultureInfo("en-US")
                                                                                                                                    } });

            _cartServiceMock.Setup(x => x.LoadCart(It.IsAny <string>())).Returns(_cart);
            _cartServiceMock.Setup(x => x.ValidateCart(It.IsAny <ICart>())).Returns(new Dictionary <ILineItem, List <ValidationIssue> >());
            _cartServiceMock.Setup(x => x.RequestInventory(It.IsAny <ICart>())).Returns(new Dictionary <ILineItem, List <ValidationIssue> >());

            _cart.AddLineItem(new InMemoryLineItem(), _orderFactoryMock.Object);
        }
Esempio n. 18
0
 public override int GetHashCode()
 {
     return(CombineHashCodes(OrderReference.GetHashCode(), Marketplace.GetHashCode()));
 }
        public ActionResult Buy(StartPage currentPage)
        {
            var cart   = LoadOrCreateCart();
            var market = _currentMarket.GetCurrentMarket();
            // Add shipping
            var shippingMethod = ShippingManager.GetShippingMethodsByMarket
                                     (market.MarketId.Value, false).ShippingMethod.FirstOrDefault();

            cart.OrderAddresses.Clear();
            cart.OrderForms.First().Shipments.Clear();
            cart.OrderForms.First().Payments.Clear();

            var shippingAddress = cart.OrderAddresses.AddNew();

            FillInAddress(shippingAddress);

            var shipment   = new Shipment();
            var shipmentId = cart.OrderForms.First().Shipments.Add(shipment);

            shipment.ShippingMethodId   = shippingMethod.ShippingMethodId;
            shipment.ShippingMethodName = shippingMethod.Name;
            shipment.SubTotal           = shippingMethod.BasePrice;

            // LineItem

            ContentReference theRef     = _refConv.GetContentLink("Long-Sleeve-Shirt-White-Small_1");
            VariationContent theContent = _contentLoader.Get <VariationContent>(theRef);
            LineItem         li         = CreateLineItem(theContent, 2, 22);

            var orderForm = cart.OrderForms.First();

            orderForm.LineItems.Add(li);
            var index = orderForm.LineItems.IndexOf(li);

            cart.OrderForms.First().Shipments.First().AddLineItemIndex(index, li.Quantity);


            //var liId = cart.OrderForms.First().LineItems.Add(li);
            //PurchaseOrderManager.AddLineItemToShipment(cart, 1, shipment, 2);

            // Add a pay method
            var paymentMethod = PaymentManager.GetPaymentMethodsByMarket(market.MarketId.Value)
                                .PaymentMethod.First();
            // Add Payment
            var payment = cart.OrderForms.First().Payments.AddNew(typeof(OtherPayment));

            payment.Amount            = 42; // ((IOrderGroup)cart).GetTotal(_totti).Amount;// .SubTotal.Amount;
            payment.PaymentMethodName = paymentMethod.Name;
            payment.PaymentMethodId   = paymentMethod.PaymentMethodId;
            payment.Status            = PaymentStatus.Pending.ToString();
            payment.TransactionID     = "transactionId";

            // No activations of Ship&Pay&Tax-providers in this example

            // Do the purchase
            using (var scope = new Mediachase.Data.Provider.TransactionScope())
            {
                OrderReference oRef = _orderRepository.SaveAsPurchaseOrder(cart);
                // I want to do this _orderRepository.Delete(cart);
                //_orderRepository.Delete(((IOrderGroup)cart).OrderLink);
                scope.Complete();
            }

            return(Content("Done"));
        }
        public CheckoutControllerTests()
        {
            _controllerExceptionHandlerMock = new Mock<ControllerExceptionHandler>();
            _requestContextMock = new Mock<RequestContext>();
            _httpRequestBaseMock = new Mock<HttpRequestBase>();
            _httpContextBaseMock = new Mock<HttpContextBase>();
            _contentRepositoryMock = new Mock<IContentRepository>();
            _mailServiceMock = new Mock<IMailService>();
            _localizationService = new MemoryLocalizationService();
            _currencyServiceMock = new Mock<ICurrencyService>();
            _customerContextFacadeMock = new Mock<CustomerContextFacade>();
            _orderRepositoryMock = new Mock<IOrderRepository>();
            _orderGroupCalculatorMock = new Mock<IOrderGroupCalculator>();
            _paymentProcessorMock = new Mock<IPaymentProcessor>();
            _promotionEngineMock = new Mock<IPromotionEngine>();
            _cartServiceMock = new Mock<ICartService>();
            _addressBookServiceMock = new Mock<IAddressBookService>();
            _orderSummaryViewModelFactoryMock = new Mock<OrderSummaryViewModelFactory>(null, null, null, null);
            _checkoutViewModelFactoryMock = new Mock<CheckoutViewModelFactory>(null, null, null, null, null, null, null, null);
            _orderFactoryMock = new Mock<IOrderFactory>();
            _cart = new FakeCart(null, new Currency("USD"));
            _exceptionContext = new ExceptionContext
            {
                HttpContext = _httpContextBaseMock.Object,
                RequestContext = _requestContextMock.Object
            };
            var customerId = Guid.NewGuid();
            var orderReference = new OrderReference(1, "PurchaseOrder", customerId, typeof(InMemoryPurchaseOrder));
            var purchaseOrder = new InMemoryPurchaseOrder { Name = orderReference.Name, Currency = _cart.Currency, CustomerId = customerId, OrderLink = orderReference };

            var paymentMock = new Mock<ICreditCardPayment>();
            paymentMock.SetupGet(x => x.CreditCardNumber).Returns("423465654");
            paymentMock.SetupGet(x => x.Status).Returns(PaymentStatus.Pending.ToString());

            _httpContextBaseMock.Setup(x => x.Request).Returns(_httpRequestBaseMock.Object);

            _subject = new CheckoutControllerForTest(_contentRepositoryMock.Object, _mailServiceMock.Object, _localizationService,
                _currencyServiceMock.Object, _controllerExceptionHandlerMock.Object, _customerContextFacadeMock.Object, _orderRepositoryMock.Object,
                _checkoutViewModelFactoryMock.Object, _orderGroupCalculatorMock.Object, _paymentProcessorMock.Object, _promotionEngineMock.Object,
                _cartServiceMock.Object, _addressBookServiceMock.Object, _orderSummaryViewModelFactoryMock.Object, _orderFactoryMock.Object);

            _checkoutViewModelFactoryMock
                .Setup(x => x.CreateCheckoutViewModel(It.IsAny<ICart>(), It.IsAny<CheckoutPage>(), It.IsAny<PaymentMethodViewModel<PaymentMethodBase>>()))
                .Returns((ICart cart, CheckoutPage currentPage, PaymentMethodViewModel<PaymentMethodBase> paymentMethodViewModel) => CreateCheckoutViewModel(currentPage, paymentMethodViewModel));

            _orderFactoryMock.Setup(x => x.CreateCardPayment()).Returns(paymentMock.Object);
            _orderRepositoryMock.Setup(x => x.SaveAsPurchaseOrder(_cart)).Returns(orderReference);
            _orderRepositoryMock.Setup(x => x.Load<IPurchaseOrder>(orderReference.OrderGroupId)).Returns(purchaseOrder);

            _contentRepositoryMock.Setup(x => x.Get<StartPage>(It.IsAny<ContentReference>())).Returns(new StartPage());
            _contentRepositoryMock.Setup(x => x.GetChildren<OrderConfirmationPage>(It.IsAny<ContentReference>())).Returns(new[] { new OrderConfirmationPageForTest() { Language = new CultureInfo("en-US") } });

            _cartServiceMock.Setup(x => x.LoadCart(It.IsAny<string>())).Returns(_cart);
            _cartServiceMock.Setup(x => x.ValidateCart(It.IsAny<ICart>())).Returns(new Dictionary<ILineItem, List<ValidationIssue>>());
            _cartServiceMock.Setup(x => x.RequestInventory(It.IsAny<ICart>())).Returns(new Dictionary<ILineItem, List<ValidationIssue>>());

            _cart.AddLineItem(new InMemoryLineItem(), _orderFactoryMock.Object);
        }
Esempio n. 21
0
 public void OnDeleted(OrderReference orderReference)
 {
     _logger.Information($"Deleted order {orderReference.OrderType}: orderid [{orderReference.OrderGroupId}], customer [{orderReference.CustomerId}], name[{orderReference.Name}].");
 }
 public void OnUpdating(OrderReference orderReference)
 {
     _logger.Information(string.Format("Updating order {0}: orderid [{1}], customer [{2}], name[{3}].", orderReference.OrderType, orderReference.OrderGroupId, orderReference.CustomerId, orderReference.Name));
 }