Пример #1
0
        /// <summary>
        /// Runs the workflow.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="warnings">The warnings.</param>
        /// <returns>OrderWorkflowResult.</returns>
        public virtual OrderWorkflowResult RunWorkflow(string name, Dictionary<string, string> warnings = null)
        {
            var result = new OrderService(OrderRepository, SearchService, WorkflowService, null, null).ExecuteWorkflow(name, Cart);

            if (result.WorkflowResult.Warnings != null && warnings != null)
            {
                foreach (var warning in result.WorkflowResult.Warnings.Distinct())
                {
                    warnings.Add(warning.Code, warning.Parameters["Message"]);
                }
            }
            Cart = result.OrderGroup as ShoppingCart;
            return result;
        }
Пример #2
0
        /// <summary>
        /// Runs the workflow.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="orderGroup"></param>
        /// <returns>OrderWorkflowResult.</returns>
        public virtual OrderWorkflowResult RunWorkflow(string name, OrderGroup orderGroup = null)
        {
            orderGroup = orderGroup ?? Cart;
            var result = new OrderService(OrderRepository, SearchService, WorkflowService, null, null).ExecuteWorkflow(name, orderGroup);

            if (result.OrderGroup is ShoppingCart)
            {
                Cart = result.OrderGroup as ShoppingCart;
            }
            return result;
        }
		public void can_create_payment_sale_and_credit()
		{
			var order = CreateOrder();

			var mockUnitOfWork = new Mock<IUnitOfWork>();
			var repository = new Mock<IOrderRepository>();
			repository.Setup(x => x.Orders).Returns(() => new[] { order }.AsQueryable());
			repository.Setup(x => x.UnitOfWork).Returns(mockUnitOfWork.Object);
			repository.SetupAllProperties();

			var paymentMethodsRepository = new Mock<IPaymentMethodRepository>();

            var gateway = new PaymentGateway
            {
                GatewayId = "gwAuthorizeNet",
                ClassType = "VirtoCommerce.PaymentGateways.AuthorizeNetPaymentGateway, VirtoCommerce.PaymentGateways",
                Name = "Authorize.Net",
                SupportsRecurring = false,
                SupportedTransactionTypes = 0x1F
            };


			paymentMethodsRepository.Setup(x => x.PaymentGateways).Returns(() => new[] { gateway }.AsQueryable());

			var pm = new PaymentMethod
			{
				Description = "Credit Card",
				Name = "CreditCard",
				PaymentGateway = gateway,
				PaymentGatewayId = gateway.GatewayId,

			};
			var methodLanguage = new PaymentMethodLanguage
			{
				DisplayName = pm.Description,
				LanguageCode = "en-US",
				PaymentMethodId = pm.PaymentMethodId,
			};
			pm.PaymentMethodLanguages.Add(methodLanguage);

			pm.PaymentMethodPropertyValues.Add(new PaymentMethodPropertyValue
			{
				ValueType = GatewayProperty.ValueTypes.ShortString.GetHashCode(),
				Name = "MerchantLogin",
				ShortTextValue = "87WmkB7W"
			});
			pm.PaymentMethodPropertyValues.Add(new PaymentMethodPropertyValue
			{
				ValueType = GatewayProperty.ValueTypes.ShortString.GetHashCode(),
				Name = "MerchantPassword",
				ShortTextValue = "8hAuD275892cBFcb"
			});
			pm.PaymentMethodPropertyValues.Add(new PaymentMethodPropertyValue
			{
				ValueType = GatewayProperty.ValueTypes.Boolean.GetHashCode(),
				Name = "TestMode",
				BooleanValue = true
			});
            //pm.PaymentMethodPropertyValues.Add(new PaymentMethodPropertyValue
            //{
            //    ValueType = GatewayProperty.ValueTypes.ShortString.GetHashCode(),
            //    Name = "GatewayURL",
            //    ShortTextValue = "https://test.authorize.net/gateway/transact.dll"
            //});

			paymentMethodsRepository.Setup(x => x.PaymentMethods).Returns(() => new[] { pm }.AsQueryable());

			paymentMethodsRepository.SetupAllProperties();

			var storesrep = new Mock<IStoreRepository>();
			storesrep.Setup(x => x.Stores).Returns(() => new List<Store>(){new Store
			{
			    CreditCardSavePolicy = CreditCardSavePolicy.LastFourDigits.GetHashCode(),
                StoreId = "SampleStore"
			}}.AsQueryable());
			storesrep.SetupAllProperties();

			Payment payment = new CreditCardPayment
				{
					PaymentMethodId = pm.PaymentMethodId,
					PaymentType = PaymentType.CreditCard.GetHashCode(),
					Status = PaymentStatus.Pending.ToString(),
					CreditCardCustomerName = "John Doe",
					PaymentMethodName = "VisaCard",
					ValidationCode = "RE21321-21",
					Amount = 32.53m,
					CreditCardExpirationMonth = 12,
					CreditCardExpirationYear = 2014,
					CreditCardNumber = "4007000000027",
					CreditCardType = "VISA",
					CreditCardSecurityCode = "123",
					BillingAddressId = order.OrderForms[0].BillingAddressId,
					OrderFormId = order.OrderForms[0].OrderFormId,
					TransactionType = TransactionType.Sale.ToString()
				};

			var orderService = new OrderService(repository.Object, null, null, paymentMethodsRepository.Object, storesrep.Object);

			var result = orderService.CreatePayment(payment);

			Assert.True(result.IsSuccess, result.Message);
			Assert.True(order.OrderForms[0].Payments.Any(p => p.PaymentId == payment.PaymentId), "Sale payment was not added");

			//Check if sale can be credited
			var creditPayment = (Payment)new CreditCardPayment().InjectFrom(payment);
			creditPayment.PaymentId = Guid.NewGuid().ToString();
			creditPayment.TransactionType = TransactionType.Credit.ToString();
			payment.Status = PaymentStatus.Completed.ToString();

			var creditresult = orderService.CreatePayment(creditPayment);
			Assert.True(creditresult.IsSuccess, creditresult.Message);
			Assert.True(order.OrderForms[0].Payments.Any(p => p.PaymentId == creditPayment.PaymentId), "Credit payment was not added");
		}