Beispiel #1
0
        public void OrderSystem_Payments_AuthorizeNET_CreateNew()
        {
            CreditCardPayment payment;
            string            cardType = "Visa";
            int expMonth = 4;
            int expYear  = DateTime.UtcNow.AddYears(5).Year;

            // Create cart
            Cart cart = OrderHelper.CreateCartForPaymentPlan();

            // Create payment plan
            PaymentPlan plan = cart.SaveAsPaymentPlan();

            // Set some payment plan values
            plan.CycleMode           = PaymentPlanCycle.Months;
            plan.CycleLength         = 1;
            plan.MaxCyclesCount      = 12;
            plan.StartDate           = DateTime.UtcNow;
            plan.EndDate             = DateTime.UtcNow.AddMonths(13);
            plan.LastTransactionDate = DateTime.UtcNow;

            //create cc payment to validate test account
            payment                  = (CreditCardPayment)plan.OrderForms[0].Payments[0];
            payment.CardType         = cardType;
            payment.CreditCardNumber = "4012888818888";
            payment.ExpirationMonth  = expMonth;
            payment.ExpirationYear   = expYear;

            // Execute workflow
            plan.RunWorkflow("CartCheckout");

            // Update last transaction date
            plan.LastTransactionDate = DateTime.UtcNow;
            // Encrease cycle count
            plan.CompletedCyclesCount++;

            // Save changes
            plan.AcceptChanges();

            plan = OrderContext.Current.GetPaymentPlan(plan.CustomerId, plan.OrderGroupId);

            // Validate payment plan
            Assert.IsTrue(!String.IsNullOrEmpty(plan.OrderForms[0].Payments[0].AuthorizationCode));
            // Delete payment plan
            plan.Delete();
            plan.AcceptChanges();
            // Assert that payment plan is deleted
            Assert.IsTrue(plan.ObjectState == MetaObjectState.Deleted);

            // Delete cart
            cart.Delete();
            cart.AcceptChanges();
            // Assert that cart is deleted
            Assert.IsTrue(cart.ObjectState == MetaObjectState.Deleted);
        }
Beispiel #2
0
        public void OrderSystem_Payments_AuthorizeNET_CreateNewAndCancelError()
        {
            CreditCardPayment payment;
            string            cardType = "MasterCard";
            int expMonth = 4;
            int expYear  = DateTime.UtcNow.AddYears(5).Year;

            // Create cart
            Cart cart = OrderHelper.CreateCartForPaymentPlan();

            // Create payment plan
            PaymentPlan plan = cart.SaveAsPaymentPlan();

            // ---------- Step 1. Create subscription -----------

            // Set some payment plan values
            plan.CycleMode           = PaymentPlanCycle.Months;
            plan.CycleLength         = 1;
            plan.MaxCyclesCount      = 12;
            plan.StartDate           = DateTime.UtcNow;
            plan.EndDate             = DateTime.UtcNow.AddMonths(13);
            plan.LastTransactionDate = DateTime.UtcNow;

            //create cc payment to validate test account
            payment                  = (CreditCardPayment)plan.OrderForms[0].Payments[0];
            payment.CardType         = cardType;
            payment.CreditCardNumber = "5424000000000015";
            payment.ExpirationMonth  = expMonth;
            payment.ExpirationYear   = expYear;

            // Execute workflow
            plan.RunWorkflow("CartCheckout");

            // Update last transaction date
            plan.LastTransactionDate = DateTime.UtcNow;
            // Encrease cycle count
            plan.CompletedCyclesCount++;

            // Save changes
            plan.AcceptChanges();

            plan = OrderContext.Current.GetPaymentPlan(plan.CustomerId, plan.OrderGroupId);

            // Validate payment plan
            Assert.IsTrue(!String.IsNullOrEmpty(plan.OrderForms[0].Payments[0].AuthorizationCode));

            // ---------- Step 2. Cancel subscription -----------
            // get cancel status
            PaymentMethodDto dto = PaymentManager.GetPaymentMethodBySystemName("authorize", "en-us", true);

            Assert.IsTrue(dto.PaymentMethod.Count > 0, "Authorize.NET payment method not found for en-us language.");

            PaymentMethodDto.PaymentMethodParameterRow[] rows = (PaymentMethodDto.PaymentMethodParameterRow[])dto.PaymentMethodParameter.Select(String.Format("Parameter = '{0}'", AuthorizePaymentGateway._CancelStatusParameterName));
            Assert.IsTrue(rows != null && rows.Length > 0, "CancelStatus parameter for the Authorize.NET gateway not net.");

            string cancelStatus = rows[0].Value;

            // set status cancel status for the payment plan
            plan.Status = cancelStatus;
            // change AuthorizationCode to generate payment provider error
            plan.OrderForms[0].Payments[0].AuthorizationCode = "000000";

            // Execute workflow
            try
            {
                plan.RunWorkflow("CartCheckout");
            }
            catch (PaymentException ex)
            {
                if (ex.Type != PaymentException.ErrorType.ProviderError)
                {
                    throw;
                }
                else
                {
                    Console.Error.WriteLine(ex.Message);
                }
            }

            // ---------- Step 3. Perform cleanup -----------

            // Delete payment plan
            plan.Delete();
            plan.AcceptChanges();
            // Assert that payment plan is deleted
            Assert.IsTrue(plan.ObjectState == MetaObjectState.Deleted);

            // Delete cart
            cart.Delete();
            cart.AcceptChanges();
            // Assert that cart is deleted
            Assert.IsTrue(cart.ObjectState == MetaObjectState.Deleted);
        }
Beispiel #3
0
        public void OrderSystem_Payments_AuthorizeNET_CreateNewError()
        {
            CreditCardPayment payment;
            string            cardType = "Visa";
            int expMonth = 4;
            int expYear  = DateTime.UtcNow.AddYears(5).Year;

            // Create cart
            Cart cart = OrderHelper.CreateCartForPaymentPlan();

            // Create payment plan
            PaymentPlan plan = cart.SaveAsPaymentPlan();

            // Set some payment plan values
            // Monthly subscription for a year
            plan.CycleMode      = PaymentPlanCycle.Months;
            plan.CycleLength    = 1;
            plan.MaxCyclesCount = 12;
            plan.StartDate      = DateTime.UtcNow.AddDays(-10);
            plan.EndDate        = DateTime.UtcNow.AddMonths(13);

            //create cc payment to validate test account
            payment                  = (CreditCardPayment)plan.OrderForms[0].Payments[0];
            payment.CardType         = cardType;
            payment.CreditCardNumber = "4012888818888";
            payment.ExpirationMonth  = expMonth;
            payment.ExpirationYear   = expYear;

            // Execute workflow
            try
            {
                plan.RunWorkflow("CartCheckout");
            }
            catch (PaymentException ex)
            {
                if (ex.Type != PaymentException.ErrorType.ProviderError)
                {
                    throw;
                }
                else
                {
                    Console.Error.WriteLine(ex.Message);
                }
            }

            // Update last transaction date
            plan.LastTransactionDate = DateTime.UtcNow;
            // Encrease cycle count
            plan.CompletedCyclesCount++;
            // Save changes
            plan.AcceptChanges();

            plan = OrderContext.Current.GetPaymentPlan(plan.CustomerId, plan.OrderGroupId);

            // Validate payment plan
            Assert.AreEqual(plan.CompletedCyclesCount, 1);
            // Delete payment plan
            plan.Delete();
            plan.AcceptChanges();
            // Assert that payment plan is deleted
            Assert.IsTrue(plan.ObjectState == MetaObjectState.Deleted);

            // Delete cart
            cart.Delete();
            cart.AcceptChanges();
            // Assert that cart is deleted
            Assert.IsTrue(cart.ObjectState == MetaObjectState.Deleted);
        }