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")); }
public void Components_Can_Load_PriceBrackets() { // Arrange var productFamily = Chargify.GetProductFamilyList().Values.FirstOrDefault(); var familyComponents = Chargify.GetComponentsForProductFamily(productFamily.ID, false).Values; // Act var components = familyComponents.Where(c => c.PricingScheme != PricingSchemeType.Per_Unit && c.Prices != null && c.Prices.Count > 0).ToList(); // Assert Assert.IsNotNull(components); //Assert.IsInstanceOfType(components, typeof(List<IComponentInfo>)); Assert.IsTrue(components.Where(c => c.Prices != null && c.Prices.Count > 0).Count() > 0); Assert.IsTrue(components.FirstOrDefault(c => c.Prices != null && c.Prices.Count > 0).Prices.First().StartingQuantity != int.MinValue); Assert.IsTrue(components.FirstOrDefault(c => c.Prices != null && c.Prices.Count > 0).Prices.First().EndingQuantity != int.MinValue); Assert.IsTrue(components.FirstOrDefault(c => c.Prices != null && c.Prices.Count > 0).Prices.First().UnitPrice != int.MinValue); }
public void Components_AddUsage_ForSubscription() { // Arrange var productFamily = Chargify.GetProductFamilyList().Values.FirstOrDefault(); var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active).Value; var component = Chargify.GetComponentsForProductFamily(productFamily.ID, false).FirstOrDefault(c => c.Value.Kind == ComponentType.Metered_Component).Value; int usageQuantity = 5; string usageDescription = "testing"; // Act var usageResult = Chargify.AddUsage(subscription.SubscriptionID, component.ID, usageQuantity, usageDescription); // Assert Assert.IsNotNull(usageResult); //Assert.IsInstanceOfType(usageResult, typeof(IUsage)); Assert.IsTrue(usageResult.Memo == usageDescription); Assert.IsTrue(usageResult.Quantity == usageQuantity); }
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")); }