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");
		}
        public void can_create_payment_authorize_and_capture()
        {
            var orderGroup = CreateCart();

            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.Full.GetHashCode(),
                StoreId = "SampleStore"
			}}.AsQueryable());
            storesrep.SetupAllProperties();

            orderGroup.OrderForms[0].Payments.Clear();
            orderGroup.OrderForms[0].Payments.Add(new CreditCardPayment
            {
                PaymentType = PaymentType.CreditCard.GetHashCode(),
                CreditCardCustomerName = "John Doe",
                CreditCardExpirationMonth = 1,
                CreditCardExpirationYear = 2016,
                CreditCardNumber = "4007000000027",
                CreditCardType = "VISA",
                CreditCardSecurityCode = "123",
                PaymentMethodId = pm.PaymentMethodId,
                PaymentMethodName = pm.Description,
                Amount = 32.53m,
                TransactionType = TransactionType.Authorization.ToString(),
                Status = PaymentStatus.Pending.ToString(),
                OrderForm = orderGroup.OrderForms[0],
                BillingAddressId = orderGroup.OrderAddresses.First().OrderAddressId
            });

            orderGroup.Total = orderGroup.OrderForms.SelectMany(orderForm => orderForm.Payments).Sum(payment => payment.Amount);

            var activity = new ProcessPaymentActivity(paymentMethodsRepository.Object, storesrep.Object);

            var result = InvokeActivity(activity, orderGroup);


            foreach (var payment in result.OrderGroup.OrderForms[0].Payments)
            {
                Assert.True(payment.Status == PaymentStatus.Completed.ToString());
            }

            var authPayemnt =
                result.OrderGroup.OrderForms[0].Payments.FirstOrDefault(
                    x =>
                        x.TransactionType == TransactionType.Authorization.ToString() &&
                        x.Status == PaymentStatus.Completed.ToString());

            Assert.NotNull(authPayemnt);

            authPayemnt.TransactionType = TransactionType.Capture.ToString();
            authPayemnt.Status = PaymentStatus.Pending.ToString();

            result = InvokeActivity(activity, orderGroup);

            foreach (var payment in result.OrderGroup.OrderForms[0].Payments)
            {
                Assert.True(payment.Status == PaymentStatus.Completed.ToString());
            }

        }
Ejemplo n.º 3
0
		public void Can_run_activity_processpayment()
		{
			var orderGroup = CreateCart();

			var paymentMethodsRepository = new Mock<IPaymentMethodRepository>();

			//Test authorize.Net gateway (Cannot test until license available)
			//var gateway = new PaymentGateway
			//	{
			//		GatewayId = "gwAuthorizeNet",
			//		ClassType = "VirtoCommerce.PaymentGateways.ICharge.IchargePaymentGateway, VirtoCommerce.PaymentGateways",
			//		Name = "Authorize.Net",
			//		SupportsRecurring = false,
			//		SupportedTransactionTypes = 0x1F
			//	};

			var gateway = new PaymentGateway
				{
					ClassType = "VirtoCommerce.PaymentGateways.DefaultPaymentGateway, VirtoCommerce.PaymentGateways",
					Name = "DefaultPaymentGateway",
					SupportsRecurring = false
				};

			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>().AsQueryable());
			storesrep.SetupAllProperties();

			orderGroup.OrderForms[0].Payments.Clear();
			orderGroup.OrderForms[0].Payments.Add(new CreditCardPayment
			{
				PaymentType = PaymentType.CreditCard.GetHashCode(),
				CreditCardCustomerName = "John Doe",
				CreditCardExpirationMonth = 1,
				CreditCardExpirationYear = 2016,
				CreditCardNumber = "4007000000027",
				CreditCardType = "VISA",
				CreditCardSecurityCode = "123",
				PaymentMethodId = pm.PaymentMethodId,
				PaymentMethodName = pm.Description,
				Amount = 32.53m,
				TransactionType = TransactionType.Sale.ToString(),
				Status = PaymentStatus.Pending.ToString(),
				OrderForm = orderGroup.OrderForms[0],
				BillingAddressId = orderGroup.OrderAddresses.First().OrderAddressId
			});

			orderGroup.Total = orderGroup.OrderForms.SelectMany(orderForm => orderForm.Payments).Sum(payment => payment.Amount);

			var activity = new ProcessPaymentActivity(paymentMethodsRepository.Object, storesrep.Object);

			var result = InvokeActivity(activity, orderGroup);

			var order = result.OrderGroup;

			foreach (var payment in order.OrderForms[0].Payments)
			{
				Assert.False(payment.Status == PaymentStatus.Pending.ToString());
			}
		}