示例#1
0
        public void Subscription_Can_EditProduct_WithDelay()
        {
            // Arrange
            var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active && s.Value.PaymentProfile != null).Value as Subscription;
            var otherProduct = Chargify.GetProductList().Values.Where(p => p.Handle != subscription.Product.Handle).FirstOrDefault();

            // Act
            var result = Chargify.EditSubscriptionProduct(subscription.SubscriptionID, otherProduct.Handle, true);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(subscription.Product.Handle, result.Product.Handle);
            Assert.AreNotEqual(int.MinValue, subscription.NextProductId);
            Assert.AreEqual(otherProduct.ID, result.NextProductId);
        }
        public void Notes_CanDelete()
        {
            // Arrange
            var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active && Chargify.GetNotesForSubscription(s.Key) != null && Chargify.GetNotesForSubscription(s.Key).Any()).Value as Subscription;

            Assert.IsNotNull(subscription, "No suitable subscription could be found.");
            var notes = Chargify.GetNotesForSubscription(subscription.SubscriptionID);

            Assert.IsNotNull(notes.FirstOrDefault());

            // Act
            var result = Chargify.DeleteNote(subscription.SubscriptionID, notes.FirstOrDefault().Key);

            // Assert
            Assert.IsTrue(result);
        }
示例#3
0
        public void GetInvoice_ExistingInvoiceId_ReturnInvoiceWithPassedInvoiceId()
        {
            var invoices = Chargify.GetInvoiceList().Values;

            if (!invoices.Any())
            {
                Assert.Inconclusive("There are no valid invoices for use in this test.");
            }

            var expectedInvoice = invoices.FirstOrDefault();

            var invoice = Chargify.GetInvoice(expectedInvoice.ID);

            Assert.IsNotNull(invoice);
            Assert.IsTrue(invoice.ID == expectedInvoice.ID);
        }
        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);
        }
示例#5
0
        public void ComponentAllocation_Can_Get_List()
        {
            // Arrange
            var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active && Chargify.GetComponentsForSubscription(s.Key) != null).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;

            Assert.IsNotNull(component, "A valid component could not be found.");

            // 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_Can_Cancel_Delayed_Product_Change()
        {
            // Arrange
            var subscription        = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active && s.Value.PaymentProfile != null && s.Value.NextProductId <= 0).Value;
            var otherProduct        = Chargify.GetProductList().FirstOrDefault(p => p.Key != subscription.Product.ID);
            var updatedSubscription = Chargify.EditSubscriptionProduct(subscription.SubscriptionID, otherProduct.Value.Handle, true);

            Assert.AreEqual(otherProduct.Key, updatedSubscription.NextProductId);

            // Act
            var result = Chargify.CancelDelayedProductChange(updatedSubscription.SubscriptionID);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.NextProductId <= 0);
        }
        public void Coupon_Remove()
        {
            // Arrange
            var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active && !string.IsNullOrEmpty(s.Value.CouponCode)).Value as Subscription;

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

            // Act
            var result = Chargify.RemoveCoupon(subscription.SubscriptionID, subscription.CouponCode);

            // Assert
            Assert.IsTrue(result);
        }
        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.PricePerUnit > 0).Value;

            // 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
            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() == 1);
            Assert.IsTrue(usedComponents.FirstOrDefault().Value.AllocatedQuantity == 5);

            // Cleanup
            Assert.IsTrue(Chargify.DeleteSubscription(newSubscription.SubscriptionID, "Automatic cancel due to test"));
        }
示例#9
0
        public void Notes_CanGetForSubscription()
        {
            // Arrange
            var subList            = Chargify.GetSubscriptionList();
            var firstSubscription  = subList.FirstOrDefault(s => s.Value.State == SubscriptionState.Active && Chargify.GetNotesForSubscription(s.Key) != null && Chargify.GetNotesForSubscription(s.Key).Any()).Value as Subscription;
            var secondSubscription = subList.FirstOrDefault(s => s.Value.State == SubscriptionState.Active && Chargify.GetNotesForSubscription(s.Key) == null || !Chargify.GetNotesForSubscription(s.Key).Any()).Value as Subscription;

            // Act
            var firstResult  = Chargify.GetNotesForSubscription(firstSubscription.SubscriptionID);
            var secondResult = Chargify.GetNotesForSubscription(secondSubscription.SubscriptionID);

            // Assert
            Assert.IsNotNull(firstResult);
            Assert.IsNotNull(secondResult);
            Assert.AreEqual(0, secondResult.Count);
            Assert.IsTrue(firstResult.Count > 0);
        }
示例#10
0
        private void InitBillingControls()
        {
            DateTime?_expDate = UserContext.Current.Organization.ExpirationTime;

            ISubscription _custSubscr = ChargifyProvider.GetCustomerSubscription(Chargify, OrganizationId, InstanceId);

            if (_custSubscr != null && _custSubscr.CreditCard != null)
            {
                _expDate = _custSubscr.CurrentPeriodEndsAt;
                if (!IsPostBack)
                {
                    SettingCollection paidSettings = SettingProvider.GetAllPricedSettings(OrganizationId, InstanceId);
                    ChargifyProvider.UpdateSubscriptionAllocations(Chargify, _custSubscr.SubscriptionID, UserContext.Current.Instance, paidSettings, paidSettings);
                }
                TotalAmount    = m_TotalSum;
                SubscriptionId = _custSubscr.SubscriptionID;
                lCCStatus.Text = "Credit Card Registered and " + _custSubscr.State.ToString() + ".";
                TimeSpan _dateDiff = (TimeSpan)(_expDate - DateTime.UtcNow);
                if (_expDate.HasValue)
                {
                    smallNextBillDate.Visible   = true;
                    smallNextBillDate.InnerText = "Next billed on " + _expDate.Value.ToString("dd-MMM-yyyy");
                }
            }
            else
            {
                lCCStatus.Text = "No Credit Card on File.";
                if (!IsPostBack)
                {
                    DisablePurchaseButtons();
                }
            }
            if (_custSubscr != null && _custSubscr.CreditCard != null)
            {
                System.Collections.Generic.List <TransactionType> transTypes = new List <TransactionType>();
                transTypes.Add(TransactionType.Payment);
                System.Collections.Generic.IDictionary <int, ITransaction> trans = Chargify.GetTransactionsForSubscription(_custSubscr.SubscriptionID, 1, 25, transTypes);
                if (trans != null && trans.Count > 0)
                {
                    divPaymentHistoryHeader.Visible = true;
                    cgvTransactList.Visible         = true;
                    cgvTransactList.DataSource      = trans.Values;
                    cgvTransactList.DataBind();
                }
            }
        }
示例#11
0
        public void ProductFamily_Can_Create_Simple()
        {
            // Arrange
            var newFamily = new ProductFamily()
            {
                Name = string.Format("Test{0}", Guid.NewGuid().ToString())
            };

            // Act
            var result = Chargify.CreateProductFamily(newFamily);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(IProductFamily));
            Assert.AreEqual(newFamily.Name, result.Name, "Name didn't match");
            Assert.AreEqual(newFamily.Name.ToLowerInvariant(), result.Handle, "Handle wasn't as expected");
        }
示例#12
0
        public void Metadata_Can_List_Subscription_JSON()
        {
            // Arrange
            SetJson(true);

            // Act
            var result = Chargify.GetMetadata <Subscription>();

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.CurrentPage != int.MinValue);
            Assert.IsTrue(result.PerPage != int.MinValue);
            Assert.IsTrue(result.TotalCount != int.MinValue);
            Assert.IsTrue(result.TotalPages != int.MinValue);

            SetJson(false);
        }
        public void Subscription_Create_Using_Existing_Customer()
        {
            // Arrange
            var client          = Chargify;
            var product         = Chargify.GetProductList().Values.FirstOrDefault();
            var exampleCustomer = client.GetCustomerList().Values.DefaultIfEmpty(defaultValue: null).FirstOrDefault();
            var paymentInfo     = GetTestPaymentMethod(exampleCustomer.ToCustomerAttributes() as CustomerAttributes);

            // Act
            var newSubscription = client.CreateSubscription(product.Handle, exampleCustomer.ChargifyID, paymentInfo);

            // Assert
            Assert.IsNotNull(newSubscription);
            Assert.AreEqual(exampleCustomer.FirstName, newSubscription.Customer.FirstName);
            Assert.AreEqual(exampleCustomer.LastName, newSubscription.Customer.LastName);
            Assert.AreEqual(exampleCustomer.ChargifyID, newSubscription.Customer.ChargifyID);
        }
示例#14
0
        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 Subscription_Create_UsingOptions_TooManyProducts()
        {
            // Arrange
            var exampleCustomer = Chargify.GetCustomerList().Values.DefaultIfEmpty(defaultValue: null).FirstOrDefault();
            var paymentInfo     = GetTestPaymentMethod(exampleCustomer.ToCustomerAttributes() as CustomerAttributes);
            var product         = Chargify.GetProductList().Values.FirstOrDefault();
            var options         = new SubscriptionCreateOptions()
            {
                CustomerID           = exampleCustomer.ChargifyID,
                CreditCardAttributes = paymentInfo,
                ProductHandle        = product.Handle,
                ProductID            = product.ID
            };

            // Act
            var result = Chargify.CreateSubscription(options);
        }
        public void Coupon_Read()
        {
            // Arrange
            var productFamily = Chargify.GetProductFamilyList().Values.FirstOrDefault();

            Assert.IsNotNull(productFamily, "No valid product family found.");

            // Act
            var result = Chargify.LoadCoupon(productFamily.ID, 129307);

            // Assert
            Assert.IsNotNull(result);
            //Assert.IsInstanceOfType(result, typeof(ICoupon));
            Assert.IsTrue(result.AmountInCents != int.MinValue);
            Assert.IsTrue(result.AmountInCents > 0);
            Assert.IsTrue(result.Amount == (Convert.ToDecimal(result.AmountInCents) / 100));
        }
        public void Subscription_Load_Where_State_Is_TrialEnded()
        {
            // Arrange
            var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Trial_Ended).Value as Subscription;

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

            // Act
            var retreivedSubscription = Chargify.Find <Subscription>(subscription.SubscriptionID);

            // Assert
            Assert.IsNotNull(retreivedSubscription);
            Assert.IsTrue(retreivedSubscription.State == SubscriptionState.Trial_Ended);
#if !NUNIT
            Assert.IsInstanceOfType(retreivedSubscription, typeof(Subscription));
#endif
        }
        public void Subscription_UpdateBillingDate()
        {
            // Arrange
            var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active).Value;
            var billingDate  = subscription.NextAssessmentAt;

            // Act
            var updatedSubscription = Chargify.UpdateBillingDateForSubscription(subscription.SubscriptionID, billingDate.AddDays(5));

            // Assert
            Assert.IsTrue(billingDate.AddDays(5) == updatedSubscription.NextAssessmentAt);

            // Cleanup
            var restoredSubscription = Chargify.UpdateBillingDateForSubscription(updatedSubscription.SubscriptionID, billingDate);

            Assert.IsTrue(billingDate == restoredSubscription.NextAssessmentAt);
        }
示例#19
0
        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);
        }
示例#20
0
        public void Metadata_Can_Read_Customer()
        {
            // Arrange
            var customer = Chargify.GetCustomerList().FirstOrDefault().Value as Customer;

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

            // Act
            var result = Chargify.GetMetadataFor <Customer>(customer.ChargifyID, null);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.CurrentPage != int.MinValue);
            Assert.IsTrue(result.PerPage != int.MinValue);
            Assert.IsTrue(result.TotalCount != int.MinValue);
            Assert.IsTrue(result.TotalPages != int.MinValue);
            Assert.AreEqual(result.TotalCount, result.Metadata.Count);
        }
示例#21
0
        public void GetInvoiceList_ExistingSubsciptionId_ReturnInvoicesWithSubscriptionId()
        {
            var invoices = Chargify.GetInvoiceList().Values;

            if (!invoices.Any())
            {
                Assert.Inconclusive("There are no valid invoices for use in this test.");
            }

            var expectedInvoice = invoices.FirstOrDefault();

            var invoiceList   = Chargify.GetInvoiceList(expectedInvoice.SubscriptionID);
            var targetInvoice = invoiceList.FirstOrDefault();

            Assert.IsNotNull(targetInvoice);
            Assert.IsTrue(targetInvoice.Value.SubscriptionID == expectedInvoice.SubscriptionID);
            Assert.IsTrue(invoiceList.FirstOrDefault(i => i.Value.SubscriptionID != expectedInvoice.SubscriptionID).Value == null);
        }
        public void Subscription_Can_Pause_FixedTime()
        {
            // Arrange
            var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active).Value as Subscription;

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

            // Act
            var result = Chargify.PauseSubscription(subscription.SubscriptionID, DateTime.Now.AddDays(testDays));

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(SubscriptionState.On_Hold, result.State);
        }
        public void Notes_CanCreate()
        {
            // Arrange
            var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active).Value as Subscription;

            Assert.IsNotNull(subscription, "No suitable subscription could be found.");
            var    noteBody = Guid.NewGuid().ToString();
            Random rand     = new Random();
            var    isSticky = rand.Next(0, 1) == 1 ? true : false;

            // Act
            var result = Chargify.CreateNote(subscription.SubscriptionID, noteBody, isSticky);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(noteBody, result.Body);
            Assert.AreEqual(isSticky, result.Sticky);
        }
        public void Subscription_Create_With_SpecialChars()
        {
            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@", "*****@*****.**", "+1 (123) 456-7890", "@Chargify#$%^&@", referenceId);

            newCustomer.ShippingAddress = @"123 Main St.*()-=_+`~";
            newCustomer.ShippingCity    = @"Kingston{}[]|;':";
            newCustomer.ShippingState   = @"ON<>,.?/";
            var newPaymentInfo = GetTestPaymentMethod(newCustomer);

            // Act
            var newSubscription = Chargify.CreateSubscription(product.Handle, newCustomer, newPaymentInfo);

            // 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.Phone == newCustomer.Phone);
            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.BillingCity == newPaymentInfo.BillingCity);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingCountry == newPaymentInfo.BillingCountry);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingState == newPaymentInfo.BillingState);
            Assert.IsTrue(newSubscription.PaymentProfile.BillingZip == newPaymentInfo.BillingZip);

            // Cleanup
            Assert.IsTrue(Chargify.DeleteSubscription(newSubscription.SubscriptionID, "Automatic cancel due to test"));
        }
        public void Subscription_Can_Pause_FixedTime()
        {
            // Arrange
            var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active).Value as Subscription;
            var testMinutes  = 5;

            // Act
            var result = Chargify.PauseSubscription(subscription.SubscriptionID, DateTime.Now.AddMinutes(testMinutes));

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(SubscriptionState.On_Hold, result.State);
            var totalWait = Convert.ToInt32(Math.Ceiling(1000 * 60 * testMinutes + (testMinutes * 0.10f)));

            Debug.WriteLine($"Waiting {TimeSpan.FromMilliseconds(totalWait).TotalMinutes} minutes to test a delay of {testMinutes} minutes ...");
            Thread.Sleep(totalWait);
            result = Chargify.LoadSubscription(subscription.SubscriptionID);
            Assert.AreEqual(SubscriptionState.Active, result.State);
        }
        public void Customer_CreateCustomer()
        {
            // Arrange
            string referenceID = Guid.NewGuid().ToString();
            var    customer    = new Customer()
            {
                FirstName        = Faker.Name.FirstName(),
                LastName         = Faker.Name.LastName(),
                Email            = Faker.Internet.Email(),
                Phone            = Faker.Phone.PhoneNumber(),
                Organization     = Faker.Company.CompanyName(),
                SystemID         = referenceID,
                ShippingAddress  = Faker.Address.StreetAddress(false),
                ShippingAddress2 = Faker.Address.SecondaryAddress(),
                ShippingCity     = Faker.Address.City(),
                ShippingState    = Faker.Address.StateAbbr(),
                ShippingZip      = Faker.Address.ZipCode(),
                ShippingCountry  = "US",
                TaxExempt        = true
            };

            // Act
            var createdCustomer = Chargify.CreateCustomer(customer);

            // Assert
            Assert.IsNotNull(createdCustomer);
            //Assert.IsInstanceOfType(createdCustomer, typeof(Customer));
            Assert.IsTrue(createdCustomer.SystemID == customer.SystemID);
            Assert.IsTrue(createdCustomer.FirstName == customer.FirstName);
            Assert.IsTrue(createdCustomer.LastName == customer.LastName);
            Assert.IsTrue(createdCustomer.Organization == customer.Organization);
            Assert.IsTrue(createdCustomer.Email == customer.Email);
            Assert.IsTrue(createdCustomer.Phone == customer.Phone);
            Assert.IsTrue(createdCustomer.ShippingAddress == customer.ShippingAddress);
            Assert.IsTrue(createdCustomer.ShippingAddress2 == customer.ShippingAddress2);
            Assert.IsTrue(createdCustomer.ShippingCity == customer.ShippingCity);
            Assert.IsTrue(createdCustomer.ShippingState == customer.ShippingState);
            Assert.IsTrue(createdCustomer.ShippingZip == customer.ShippingZip);
            Assert.IsTrue(createdCustomer.ShippingCountry == customer.ShippingCountry);
            Assert.IsTrue(createdCustomer.TaxExempt);

            // Can't cleanup, Chargify doesn't support customer deletions
        }
        public void Subscription_Can_Be_Purged()
        {
            // Arrange
            var trialingProduct = Chargify.GetProductList().Values.FirstOrDefault(p => p.TrialInterval > 0);
            var referenceId     = Guid.NewGuid().ToString();
            var expMonth        = DateTime.Now.AddMonths(1).Month;
            var expYear         = DateTime.Now.AddMonths(12).Year;

            var newCustomer         = new CustomerAttributes(Faker.Name.FirstName(), Faker.Name.LastName(), Faker.Internet.Email(), Faker.Phone.PhoneNumber(), Faker.Company.CompanyName(), referenceId);
            var newPaymentInfo      = GetTestPaymentMethod(newCustomer);
            var createdSubscription = Chargify.CreateSubscription(trialingProduct.Handle, newCustomer, newPaymentInfo);

            Assert.IsNotNull(createdSubscription);

            Chargify.PurgeSubscription(createdSubscription.SubscriptionID);
            var purgedSubscription = Chargify.Find <Subscription>(createdSubscription.SubscriptionID);

            Assert.IsNull(purgedSubscription);
        }
示例#28
0
        public void Metadata_Can_Read_Subscription()
        {
            // Arrange
            var subscription = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == SubscriptionState.Active).Value as Subscription;

            Assert.IsNotNull(subscription, "No applicable subscription found.");
            this.TestContext.WriteLine("Found subscription {0}", subscription.SubscriptionID);

            // Act
            var result = Chargify.GetMetadataFor <Subscription>(subscription.SubscriptionID, null);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.CurrentPage != int.MinValue);
            Assert.IsTrue(result.PerPage != int.MinValue);
            Assert.IsTrue(result.TotalCount != int.MinValue);
            Assert.IsTrue(result.TotalPages != int.MinValue);
            Assert.AreEqual(result.TotalCount, result.Metadata.Count);
        }
示例#29
0
        public void Payment_Create()
        {
            // Arrange
            var    subscription      = Chargify.GetSubscriptionList().FirstOrDefault(s => s.Value.State == ChargifyNET.SubscriptionState.Active).Value;
            int    amount            = 1234; //$12.34
            string memo              = Guid.NewGuid().ToString();
            var    prePaymentBalance = subscription.BalanceInCents;

            // Act
            var result = Chargify.AddPayment(subscription.SubscriptionID, amount, memo);
            var postPaymentSubscription = Chargify.LoadSubscription(subscription.SubscriptionID);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Success);
            Assert.AreEqual(amount, result.AmountInCents);
            Assert.AreEqual(memo, result.Memo);
            TestContext.WriteLine("SubscriptionID: {0}", subscription.SubscriptionID);
        }
示例#30
0
        public void Can_revoke_billing_portal_access()
        {
            // Arrange
            string referenceID = Guid.NewGuid().ToString();
            var    customer    = new Customer()
            {
                FirstName        = Faker.Name.FirstName(),
                LastName         = Faker.Name.LastName(),
                Email            = Faker.Internet.Email(),
                Phone            = Faker.Phone.PhoneNumber(),
                Organization     = Faker.Company.CompanyName(),
                SystemID         = referenceID,
                ShippingAddress  = Faker.Address.StreetAddress(false),
                ShippingAddress2 = Faker.Address.SecondaryAddress(),
                ShippingCity     = Faker.Address.City(),
                ShippingState    = Faker.Address.StateAbbr(),
                ShippingZip      = Faker.Address.ZipCode(),
                ShippingCountry  = "US",
                TaxExempt        = true
            };

            // Act
            var createdCustomer = Chargify.CreateCustomer(customer);

            Chargify.RevokeBillingPortalAccess(createdCustomer.ChargifyID);
            // Assert

            try
            {
                Chargify.GetManagementLink(createdCustomer.ChargifyID);
                Assert.Fail("Error was expected, but not received");
            }
            catch (ChargifyException chEx)
            {
                Assert.IsNotNull(chEx.ErrorMessages);
                Assert.AreEqual(1, chEx.ErrorMessages.Count);
                Assert.IsTrue(chEx.ErrorMessages.Any(e => e.Message.Contains("Billing Portal")), $"Found '{string.Join(", ", chEx.ErrorMessages.Select(x => x.Message))}'");
                //todo: Need to run test to find out the exact error message
            }

            Chargify.DeleteCustomer(createdCustomer.ChargifyID);
        }