Пример #1
0
        /// <summary>
        /// This method is called before the order is completed. This method should check all the parameters
        /// and validate the credit card or other parameters accepted.
        /// </summary>
        /// <param name="form">The form.</param>
        /// <param name="model">The model.</param>
        /// <returns>payment</returns>
        public Payment PreProcess(OrderForm form, PaymentModel model)
        {
            var cardPayment = new CreditCardPayment
                {
                    BillingAddressId = form.BillingAddressId,
                    CreditCardCustomerName = model.CustomerName,
                    CreditCardNumber = model.CardNumber,
                    CreditCardExpirationMonth = model.ExpirationMonth,
                    CreditCardExpirationYear = model.ExpirationYear,
                    CreditCardSecurityCode = model.CardVerificationNumber,
                    CreditCardType = model.CardType,
                    PaymentType = PaymentType.CreditCard.GetHashCode(),
                    PaymentTypeId = 0,
                    PaymentMethodName = model.DisplayName,
                    PaymentMethodId = model.Id,
					Amount = form.Total
                };

            return cardPayment;
        }
		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 PaymentModel()
		{
			NewPayment = new CreditCardPayment();
		}