Пример #1
0
        public void ComponentAllocation_Can_Create_Using_Object()
        {
            // Arrange
            var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active).Value;
            var component    = Chargify.GetComponentsForSubscription(subscription.SubscriptionID).FirstOrDefault(c => c.Value.Kind == "quantity_based_component" || c.Value.Kind == "on_off_component").Value;

            var allocation = new ComponentAllocation()
            {
                Quantity        = 1,
                Memo            = Guid.NewGuid().ToString(),
                UpgradeScheme   = ComponentUpgradeProrationScheme.Prorate_Delay_Capture,
                DowngradeScheme = ComponentDowngradeProrationScheme.No_Prorate
            };

            // Act
            var result = Chargify.CreateComponentAllocation(subscription.SubscriptionID, component.ComponentID, allocation);

            // Assert
            Assert.IsNotNull(result);
            //Assert.IsInstanceOfType(result, typeof(IComponentAllocation));
            Assert.AreEqual(allocation.Quantity, result.Quantity, "The quantities don't match");
            Assert.AreEqual(allocation.Memo, result.Memo, "The memo text differs");
            Assert.AreEqual(allocation.UpgradeScheme, result.UpgradeScheme, "The upgrade scheme received isn't the same as submitted");
            Assert.AreEqual(allocation.DowngradeScheme, result.DowngradeScheme, "The downgrade scheme received isn't the same as submitted");
        }
Пример #2
0
        public void ComponentAllocation_Can_Create_Using_Quantity_Only()
        {
            // Arrange
            var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active).Value;
            var component    = Chargify.GetComponentsForSubscription(subscription.SubscriptionID).FirstOrDefault(c => c.Value.Kind == "quantity_based_component").Value; // || c.Value.Kind == "on_off_component"

            int quantityToAllocate      = 1;
            IComponentAllocation result = null;

            // Act
            try
            {
                result = Chargify.CreateComponentAllocation(subscription.SubscriptionID, component.ComponentID, quantityToAllocate);
            }
            catch (ChargifyException cEx)
            {
                Assert.Fail(cEx.ToString());
            }

            // Assert
            Assert.IsNotNull(result);
            //Assert.IsInstanceOfType(result, typeof(IComponentAllocation));
            Assert.AreEqual(quantityToAllocate, result.Quantity);
            Assert.AreEqual(string.Empty, result.Memo);
            // Can't really tell the following, but the default for a site with no changes is to not prorate.
            Assert.AreEqual(ComponentUpgradeProrationScheme.No_Prorate, result.UpgradeScheme);
            Assert.AreEqual(ComponentDowngradeProrationScheme.No_Prorate, result.DowngradeScheme);
        }
Пример #3
0
        public void Components_Load_ForSubscription()
        {
            // Arrange
            var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active).Value;

            // Act
            var results = Chargify.GetComponentsForSubscription(subscription.SubscriptionID);

            // Assert
            Assert.IsNotNull(results);
        }
        public void Subscription_Create_WithTwoComponents()
        {
            // Arrange
            var product        = Chargify.GetProductList().Values.FirstOrDefault();
            var referenceID    = Guid.NewGuid().ToString();
            var expMonth       = DateTime.Now.AddMonths(1).Month;
            var expYear        = DateTime.Now.AddMonths(12).Year;
            var newCustomer    = new CustomerAttributes("Scott", "Pilgrim", "*****@*****.**", "Chargify", referenceID);
            var newPaymentInfo = GetTestPaymentMethod(newCustomer);

            Dictionary <int, string> componentsToUse = new Dictionary <int, string>()
            {
                { 998, "5" },
                { 6776, "1" }
            };

            // Act
            var newSubscription = Chargify.CreateSubscription(product.Handle, newCustomer, newPaymentInfo, componentsToUse);
            var subComponents   = Chargify.GetComponentsForSubscription(newSubscription.SubscriptionID);
            var usedComponents  = from c in subComponents
                                  where componentsToUse.ContainsKey(c.Value.ComponentID)
                                  select c;

            // Assert
#if !NUNIT
            Assert.IsInstanceOfType(newSubscription, typeof(Subscription));
#endif
            Assert.IsNotNull(newSubscription);
            Assert.IsNotNull(newSubscription.Customer);
            Assert.IsNotNull(newSubscription.PaymentProfile);
            Assert.IsTrue(newSubscription.SubscriptionID > int.MinValue);
            Assert.IsTrue(newSubscription.Customer.ChargifyID > int.MinValue);
            Assert.IsTrue(newSubscription.Customer.FirstName == newCustomer.FirstName);
            Assert.IsTrue(newSubscription.Customer.LastName == newCustomer.LastName);
            Assert.IsTrue(newSubscription.Customer.Email == newCustomer.Email);
            Assert.IsTrue(newSubscription.Customer.Organization == newCustomer.Organization);
            Assert.IsTrue(newSubscription.Customer.SystemID == referenceID);
            Assert.IsTrue(newSubscription.PaymentProfile.FirstName == newPaymentInfo.FirstName);
            Assert.IsTrue(newSubscription.PaymentProfile.LastName == newPaymentInfo.LastName);
            Assert.IsTrue(newSubscription.PaymentProfile.ExpirationMonth == newPaymentInfo.ExpirationMonth);
            Assert.IsTrue(newSubscription.PaymentProfile.ExpirationYear == newPaymentInfo.ExpirationYear);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingAddress == newPaymentInfo.BillingAddress);
            //Assert.IsTrue(newSubscription.PaymentProfile.BillingAddress2 == newPaymentInfo.BillingAddress2);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingCity == newPaymentInfo.BillingCity);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingCountry == newPaymentInfo.BillingCountry);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingState == newPaymentInfo.BillingState);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingZip == newPaymentInfo.BillingZip);
            Assert.IsTrue(usedComponents.Count() == 2);
            Assert.IsTrue(usedComponents.FirstOrDefault().Value.AllocatedQuantity == 5);

            // Cleanup
            Assert.IsTrue(Chargify.DeleteSubscription(newSubscription.SubscriptionID, "Automatic cancel due to test"));
        }
        public void Subscription_Create_WithTwoComponents()
        {
            // Arrange
            var product         = Chargify.GetProductList().Values.FirstOrDefault();
            var referenceId     = Guid.NewGuid().ToString();
            var newCustomer     = new CustomerAttributes("Scott", "Pilgrim", "*****@*****.**", "Chargify", referenceId);
            var newPaymentInfo  = GetTestPaymentMethod(newCustomer);
            var components      = Chargify.GetComponentsForProductFamily(product.ProductFamily.ID);
            var componentsToUse = components.Take(2).ToDictionary(v => v.Key, v => "1");

            // Act
            Assert.IsNotNull(product, "Product couldn't be found");
            var newSubscription = Chargify.CreateSubscription(product.Handle, newCustomer, newPaymentInfo, componentsToUse);
            var subComponents   = Chargify.GetComponentsForSubscription(newSubscription.SubscriptionID);
            var usedComponents  = from c in subComponents
                                  where componentsToUse.ContainsKey(c.Value.ComponentID)
                                  select c;

            // Assert
#if !NUNIT
            Assert.IsInstanceOfType(newSubscription, typeof(Subscription));
#endif
            Assert.IsNotNull(newSubscription);
            Assert.IsNotNull(newSubscription.Customer);
            Assert.IsNotNull(newSubscription.PaymentProfile);
            Assert.IsTrue(newSubscription.SubscriptionID > int.MinValue);
            Assert.IsTrue(newSubscription.Customer.ChargifyID > int.MinValue);
            Assert.IsTrue(newSubscription.Customer.FirstName == newCustomer.FirstName);
            Assert.IsTrue(newSubscription.Customer.LastName == newCustomer.LastName);
            Assert.IsTrue(newSubscription.Customer.Email == newCustomer.Email);
            Assert.IsTrue(newSubscription.Customer.Organization == newCustomer.Organization);
            Assert.IsTrue(newSubscription.Customer.SystemID == referenceId);
            Assert.IsTrue(newSubscription.PaymentProfile.FirstName == newPaymentInfo.FirstName);
            Assert.IsTrue(newSubscription.PaymentProfile.LastName == newPaymentInfo.LastName);
            Assert.IsTrue(newSubscription.PaymentProfile.ExpirationMonth == newPaymentInfo.ExpirationMonth);
            Assert.IsTrue(newSubscription.PaymentProfile.ExpirationYear == newPaymentInfo.ExpirationYear);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingAddress == newPaymentInfo.BillingAddress);
            //Assert.IsTrue(newSubscription.PaymentProfile.BillingAddress2 == newPaymentInfo.BillingAddress2);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingCity == newPaymentInfo.BillingCity);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingCountry == newPaymentInfo.BillingCountry);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingState == newPaymentInfo.BillingState);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingZip == newPaymentInfo.BillingZip);
            Assert.IsTrue(usedComponents.Count() == componentsToUse.Count);
            foreach (var component in usedComponents)
            {
                Assert.IsTrue(componentsToUse.ContainsKey(component.Key));
                //Assert.AreEqual(decimal.Parse(componentsToUse[component.Key]), component.Value.AllocatedQuantity);
            }

            // Cleanup
            Assert.IsTrue(Chargify.DeleteSubscription(newSubscription.SubscriptionID, "Automatic cancel due to test"));
        }
        public void Subscription_Create_WithComponent()
        {
            // Arrange
            var product        = Chargify.GetProductList().Values.FirstOrDefault();
            var productFamily  = Chargify.GetProductFamilyList().Values.FirstOrDefault();
            var referenceId    = Guid.NewGuid().ToString();
            var expMonth       = DateTime.Now.AddMonths(1).Month;
            var expYear        = DateTime.Now.AddMonths(12).Year;
            var newCustomer    = new CustomerAttributes("Scott", "Pilgrim", "*****@*****.**", "Chargify", referenceId);
            var newPaymentInfo = GetTestPaymentMethod(newCustomer);
            var component      = Chargify.GetComponentsForProductFamily(productFamily.ID).FirstOrDefault(d => d.Value.Kind == ComponentType.Quantity_Based_Component && d.Value.Prices.Any(p => p.UnitPrice > 0m)).Value;

            Assert.IsNotNull(component, "Couldn't find any usable component.");

            // Act
            var newSubscription = Chargify.CreateSubscription(product.Handle, newCustomer, newPaymentInfo, component.ID, 5);
            var subComponents   = Chargify.GetComponentsForSubscription(newSubscription.SubscriptionID);
            var usedComponents  = from c in subComponents
                                  where c.Value.ComponentID == component.ID
                                  select c;

            // Assert
#if !NUNIT
            Assert.IsInstanceOfType(newSubscription, typeof(Subscription));
#endif
            Assert.IsNotNull(newSubscription);
            Assert.IsNotNull(newSubscription.Customer);
            Assert.IsNotNull(newSubscription.PaymentProfile);
            Assert.IsTrue(newSubscription.SubscriptionID > int.MinValue);
            Assert.IsTrue(newSubscription.Customer.ChargifyID > int.MinValue);
            Assert.IsTrue(newSubscription.Customer.FirstName == newCustomer.FirstName);
            Assert.IsTrue(newSubscription.Customer.LastName == newCustomer.LastName);
            Assert.IsTrue(newSubscription.Customer.Email == newCustomer.Email);
            Assert.IsTrue(newSubscription.Customer.Organization == newCustomer.Organization);
            Assert.IsTrue(newSubscription.Customer.SystemID == referenceId);
            Assert.IsTrue(newSubscription.PaymentProfile.FirstName == newPaymentInfo.FirstName);
            Assert.IsTrue(newSubscription.PaymentProfile.LastName == newPaymentInfo.LastName);
            Assert.IsTrue(newSubscription.PaymentProfile.ExpirationMonth == newPaymentInfo.ExpirationMonth);
            Assert.IsTrue(newSubscription.PaymentProfile.ExpirationYear == newPaymentInfo.ExpirationYear);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingAddress == newPaymentInfo.BillingAddress);
            //Assert.IsTrue(newSubscription.PaymentProfile.BillingAddress2 == newPaymentInfo.BillingAddress2);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingCity == newPaymentInfo.BillingCity);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingCountry == newPaymentInfo.BillingCountry);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingState == newPaymentInfo.BillingState);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingZip == newPaymentInfo.BillingZip);
            Assert.IsTrue(usedComponents.Count() == 1);
            Assert.IsTrue(usedComponents.FirstOrDefault().Value.AllocatedQuantity == 5);

            // Cleanup
            Assert.IsTrue(Chargify.DeleteSubscription(newSubscription.SubscriptionID, "Automatic cancel due to test"));
        }
Пример #7
0
        public void ComponentAllocation_Can_Get_List()
        {
            // Arrange
            var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active).Value;
            var component    = Chargify.GetComponentsForSubscription(subscription.SubscriptionID).FirstOrDefault(c => (c.Value.Kind == "quantity_based_component" || c.Value.Kind == "on_off_component") && c.Value.AllocatedQuantity > 0).Value;

            // Act
            var result = Chargify.GetAllocationListForSubscriptionComponent(subscription.SubscriptionID, component.ComponentID);

            // Assert
            Assert.IsNotNull(result);
            //Assert.IsInstanceOfType(result, typeof(Dictionary<int, List<IComponentAllocation>>));
            Assert.IsTrue(result.Values.Count > 0, "There is no allocation history");
        }
        public void Subscription_Load_ComponentsFor()
        {
            // Arrange
            var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active).Value as Subscription;

            Assert.IsNotNull(subscription, "No applicable subscription found.");

            // Act
            var subscriptionComponents = Chargify.GetComponentsForSubscription(subscription.SubscriptionID);

            // Assert
            Assert.IsNotNull(subscriptionComponents);
            Assert.IsTrue(subscriptionComponents.Count > 0);
        }
        public void Components_Load_ForSubscription()
        {
            // Arrange
            var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active).Value;

            if (subscription == null)
            {
                Assert.Inconclusive("A valid subscription could not be found.");
            }

            // Act
            var results = Chargify.GetComponentsForSubscription(subscription.SubscriptionID);

            // Assert
            Assert.IsNotNull(results);
        }
        public void Components_Create_Subscription_Multiple_Components()
        {
            // Arrange
            var product = Chargify.GetProductList().Values.FirstOrDefault();

            Assert.IsNotNull(product, "Product couldn't be found");
            var referenceId    = Guid.NewGuid().ToString();
            var newCustomer    = new CustomerAttributes("Scott", "Pilgrim", "*****@*****.**", "Chargify", referenceId);
            var newPaymentInfo = GetTestPaymentMethod(newCustomer);
            // Find components that allow for a simple allocated_quantity = 1 to work for this simple test
            var components      = Chargify.GetComponentsForProductFamily(product.ProductFamily.ID).Values.Where(c => c.Kind == ComponentType.Quantity_Based_Component || c.Kind == ComponentType.On_Off_Component);
            var componentsToUse = components.Take(2).ToList();
            var options         = new SubscriptionCreateOptions()
            {
                CustomerAttributes   = newCustomer,
                CreditCardAttributes = newPaymentInfo,
                ProductHandle        = product.Handle,
                Components           = new System.Collections.Generic.List <ComponentDetails>
                {
                    new ComponentDetails()
                    {
                        ComponentID = componentsToUse.First().ID, AllocatedQuantity = 1
                    },
                    new ComponentDetails()
                    {
                        ComponentID = componentsToUse.Last().ID, AllocatedQuantity = 1
                    }
                }
            };

            // Act
            var newSubscription = Chargify.CreateSubscription(options);
            var subComponents   = Chargify.GetComponentsForSubscription(newSubscription.SubscriptionID);
            var usedComponents  = from c in subComponents
                                  where componentsToUse.Any(x => x.ID == c.Value.ComponentID)
                                  select c;

            // Assert
            Assert.IsInstanceOfType(newSubscription, typeof(Subscription));
            Assert.IsNotNull(newSubscription);
            Assert.IsNotNull(newSubscription.Customer);
            Assert.IsNotNull(newSubscription.PaymentProfile);
            Assert.IsTrue(newSubscription.SubscriptionID > int.MinValue);
            Assert.IsTrue(newSubscription.Customer.ChargifyID > int.MinValue);
            Assert.IsTrue(newSubscription.Customer.FirstName == newCustomer.FirstName);
            Assert.IsTrue(newSubscription.Customer.LastName == newCustomer.LastName);
            Assert.IsTrue(newSubscription.Customer.Email == newCustomer.Email);
            Assert.IsTrue(newSubscription.Customer.Organization == newCustomer.Organization);
            Assert.IsTrue(newSubscription.Customer.SystemID == referenceId);
            Assert.IsTrue(newSubscription.PaymentProfile.FirstName == newPaymentInfo.FirstName);
            Assert.IsTrue(newSubscription.PaymentProfile.LastName == newPaymentInfo.LastName);
            Assert.IsTrue(newSubscription.PaymentProfile.ExpirationMonth == newPaymentInfo.ExpirationMonth);
            Assert.IsTrue(newSubscription.PaymentProfile.ExpirationYear == newPaymentInfo.ExpirationYear);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingAddress == newPaymentInfo.BillingAddress);
            //Assert.IsTrue(newSubscription.PaymentProfile.BillingAddress2 == newPaymentInfo.BillingAddress2);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingCity == newPaymentInfo.BillingCity);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingCountry == newPaymentInfo.BillingCountry);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingState == newPaymentInfo.BillingState);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingZip == newPaymentInfo.BillingZip);
            Assert.IsTrue(usedComponents.Count() == componentsToUse.Count);
            foreach (var component in usedComponents)
            {
                Assert.IsTrue(componentsToUse.Any(x => x.ID == component.Key));
                //Assert.AreEqual(decimal.Parse(componentsToUse[component.Key]), component.Value.AllocatedQuantity);
            }

            // Cleanup
            Assert.IsTrue(Chargify.DeleteSubscription(newSubscription.SubscriptionID, "Automatic cancel due to test"));
        }