public void PreviewSubscription()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Preview Subscription Test"
            };

            plan.UnitAmountInCents.Add("USD", 1500);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            var account = CreateNewAccountWithBillingInfo();

            var sub = new Subscription(account, plan, "USD");

            sub.UnitAmountInCents = 100;
            Assert.Null(sub.TaxType);
            Assert.DoesNotThrow(delegate { sub.Preview(); });
            Assert.Equal("usst", sub.TaxType);
            Assert.Equal(Subscription.SubscriptionState.Pending, sub.State);

            sub.Create();
            Assert.Throws <Recurly.RecurlyException>(
                delegate
            {
                sub.Preview();
            }
                );

            sub.Terminate(Subscription.RefundType.None);
            account.Close();
        }
        public void CreateSubscription()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Create Subscription Test"
            };

            plan.UnitAmountInCents.Add("USD", 100);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            var account = CreateNewAccountWithBillingInfo();

            var coup = CreateNewCoupon(3);
            var sub  = new Subscription(account, plan, "USD");

            sub.TotalBillingCycles = 5;
            sub.Coupon             = coup;
            Assert.Null(sub.TaxInCents);
            Assert.Null(sub.TaxType);
            Assert.Null(sub.TaxRate);
            sub.Create();

            sub.ActivatedAt.Should().HaveValue().And.NotBe(default(DateTime));
            sub.State.Should().Be(Subscription.SubscriptionState.Active);
            Assert.Equal(5, sub.TotalBillingCycles);
            Assert.Equal(coup.CouponCode, sub.Coupon.CouponCode);
            Assert.Equal(9, sub.TaxInCents.Value);
            Assert.Equal("usst", sub.TaxType);
            Assert.Equal(0.0875M, sub.TaxRate.Value);

            var sub1 = Subscriptions.Get(sub.Uuid);

            Assert.Equal(5, sub1.TotalBillingCycles);
        }
Example #3
0
        public void CreatePlan()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                AccountingCode         = "accountingcode123",
                SetupFeeAccountingCode = "setupfeeac",
                Description            = "a test plan",
                DisplayDonationAmounts = true,
                DisplayPhoneNumber     = false,
                DisplayQuantity        = true,
                TotalBillingCycles     = 5,
                TrialIntervalUnit      = Plan.IntervalUnit.Months,
                TrialIntervalLength    = 1,
                PlanIntervalUnit       = Plan.IntervalUnit.Days,
                PlanIntervalLength     = 180
            };

            plan.SetupFeeInCents.Add("USD", 500);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            plan.CreatedAt.Should().NotBe(default(DateTime));
            plan.AccountingCode.Should().Be("accountingcode123");
            plan.SetupFeeAccountingCode.Should().Be("setupfeeac");
            plan.Description.Should().Be("a test plan");
            plan.DisplayDonationAmounts.Should().HaveValue().And.Be(true);
            plan.DisplayPhoneNumber.Should().HaveValue().And.Be(false);
            plan.DisplayQuantity.Should().HaveValue().And.Be(true);
            plan.TotalBillingCycles.Should().Be(5);
            plan.TrialIntervalUnit.Should().Be(Plan.IntervalUnit.Months);
            plan.TrialIntervalLength.Should().Be(1);
            plan.PlanIntervalUnit.Should().Be(Plan.IntervalUnit.Days);
            plan.PlanIntervalLength.Should().Be(180);
        }
        public void ListCanceledSubscriptions()
        {
            var p = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Subscription Test"
            };

            p.UnitAmountInCents.Add("USD", 400);
            p.Create();
            PlansToDeactivateOnDispose.Add(p);

            for (var x = 0; x < 2; x++)
            {
                var account = CreateNewAccountWithBillingInfo();

                var sub = new Subscription(account, p, "USD");
                sub.Create();

                sub.Cancel();
            }

            var subs = Subscriptions.List(Subscription.SubscriptionState.Canceled);

            subs.Should().NotBeEmpty();
        }
        public void ListExpiredSubscriptions()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description        = "Subscription Test",
                PlanIntervalLength = 1,
                PlanIntervalUnit   = Plan.IntervalUnit.Months
            };

            plan.UnitAmountInCents.Add("USD", 400);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            for (var x = 0; x < 2; x++)
            {
                var account = CreateNewAccountWithBillingInfo();
                var sub     = new Subscription(account, plan, "USD")
                {
                    StartsAt = DateTime.Now.AddMonths(-5)
                };

                sub.Create();
            }

            var subs = Subscriptions.List(Subscription.SubscriptionState.Expired);

            subs.Should().NotBeEmpty();
        }
        public void ListPastDueSubscriptions()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description        = "Subscription Test",
                PlanIntervalLength = 1,
                PlanIntervalUnit   = Plan.IntervalUnit.Months
            };

            plan.UnitAmountInCents.Add("USD", 200100);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            var subs = new List <Subscription>();

            for (var x = 0; x < 2; x++)
            {
                var account = CreateNewAccountWithBillingInfo();
                var sub     = new Subscription(account, plan, "USD");
                sub.Create();
                subs.Add(sub);
            }

            var list = Subscriptions.List(Subscription.SubscriptionState.PastDue);

            list.Should().NotContain(subs);
        }
        public void ListForAccount()
        {
            var plan1 = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Subscription Test"
            };

            plan1.UnitAmountInCents.Add("USD", 400);
            plan1.Create();
            PlansToDeactivateOnDispose.Add(plan1);

            var plan2 = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Subscription Test"
            };

            plan2.UnitAmountInCents.Add("USD", 500);
            plan2.Create();
            PlansToDeactivateOnDispose.Add(plan2);

            var account = CreateNewAccountWithBillingInfo();

            var sub = new Subscription(account, plan1, "USD");

            sub.Create();

            var sub2 = new Subscription(account, plan2, "USD");

            sub2.Create();

            var list = account.GetSubscriptions(Subscription.SubscriptionState.All);

            list.Should().NotBeEmpty();
        }
Example #8
0
        public void CreateSubscription_BillingInfoHasReason()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Create Subscription Test"
            };

            plan.UnitAmountInCents.Add("USD", 100);
            plan.TrialRequiresBillingInfo = false;
            plan.TrialIntervalLength      = 10;
            plan.TrialIntervalUnit        = Plan.IntervalUnit.Days;
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            var account = CreateNewAccount();

            var coup = CreateNewCoupon(3);
            var sub  = new Subscription(account, plan, "USD");

            sub.TotalBillingCycles = 5;
            sub.Coupon             = coup;
            sub.TrialPeriodEndsAt  = DateTime.UtcNow.AddDays(2);

            Assert.Null(sub.TaxInCents);
            Assert.Null(sub.TaxType);
            Assert.Null(sub.TaxRate);

            sub.Create();
            Assert.True(sub.NoBillingInfoReason != null);
        }
Example #9
0
        public void UpdateNotesSubscription()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Postpone Subscription Test"
            };

            plan.UnitAmountInCents.Add("USD", 100);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            var account = CreateNewAccountWithBillingInfo();

            var sub = new Subscription(account, plan, "USD");

            sub.Create();

            Dictionary <string, string> notes = new Dictionary <string, string>();

            notes.Add("CustomerNotes", "New Customer Notes");
            notes.Add("TermsAndConditions", "New T and C");
            notes.Add("VatReverseChargeNotes", "New VAT Notes");

            sub.UpdateNotes(notes);

            sub.CustomerNotes.Should().Be(notes["CustomerNotes"]);
            sub.TermsAndConditions.Should().Be(notes["TermsAndConditions"]);
            sub.VatReverseChargeNotes.Should().Be(notes["VatReverseChargeNotes"]);
        }
Example #10
0
        public Subscription LookupSubscription()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Lookup Subscription Test"
            };

            plan.UnitAmountInCents.Add("USD", 1500);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            var account = CreateNewAccountWithBillingInfo();

            var sub = new Subscription(account, plan, "USD");

            sub.Create();

            sub.ActivatedAt.Should().HaveValue().And.NotBe(default(DateTime));
            sub.State.Should().Be(Subscription.SubscriptionState.Active);

            var fromService = Subscriptions.Get(sub.Uuid);

            fromService.Should().Be(sub);
            return(sub);
        }
        public void UpdateSubscription()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Update Subscription Plan 1"
            };

            plan.UnitAmountInCents.Add("USD", 1500);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            var plan2 = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Update Subscription Plan 2"
            };

            plan2.UnitAmountInCents.Add("USD", 750);
            plan2.Create();
            PlansToDeactivateOnDispose.Add(plan2);

            var account = CreateNewAccountWithBillingInfo();

            var sub = new Subscription(account, plan, "USD");

            sub.Create();
            sub.Plan = plan2;

            sub.ChangeSubscription(); // change "Now" is default

            var newSubscription = Subscriptions.Get(sub.Uuid);

            newSubscription.PendingSubscription.Should().BeNull();
            newSubscription.Plan.Should().Be(plan2);
        }
        public void LookupSubscriptionPendingChanges()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Lookup Subscription With Pending Changes Test"
            };

            plan.UnitAmountInCents.Add("USD", 1500);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            var account = CreateNewAccountWithBillingInfo();

            var sub = new Subscription(account, plan, "USD");

            sub.Create();
            sub.UnitAmountInCents = 3000;

            sub.ChangeSubscription(Subscription.ChangeTimeframe.Renewal);

            var newSubscription = Subscriptions.Get(sub.Uuid);

            newSubscription.PendingSubscription.Should().NotBeNull();
            newSubscription.PendingSubscription.UnitAmountInCents.Should().Be(3000);
        }
Example #13
0
        public void CreatePlanSmall()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName());

            plan.SetupFeeInCents.Add("USD", 100);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            plan.CreatedAt.Should().NotBe(default(DateTime));
            plan.SetupFeeInCents.Should().Contain("USD", 100);
        }
Example #14
0
        public void ListPlans()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName());

            plan.SetupFeeInCents.Add("USD", 100);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            var plans = Plans.List();

            plans.Should().NotBeEmpty();
        }
Example #15
0
        public void TerminateSubscriptionPartialRefund()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Terminate Partial Refund Subscription Test"
            };

            plan.UnitAmountInCents.Add("USD", 2000);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            var account = CreateNewAccountWithBillingInfo();

            var sub = new Subscription(account, plan, "USD");

            sub.Create();

            sub.Terminate(Subscription.RefundType.Partial);
            sub.State.Should().Be(Subscription.SubscriptionState.Expired);
        }
        public void CreateCouponPlan()
        {
            var plan = new Plan(GetMockPlanCode("coupon plan"), "Coupon Test");

            plan.SetupFeeInCents.Add("USD", 500);
            plan.UnitAmountInCents.Add("USD", 5000);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            var coupon = new Coupon(GetMockCouponCode(), GetMockCouponName(), new Dictionary <string, int>());

            coupon.DiscountInCents.Add("USD", 100);
            coupon.Plans.Add(plan.PlanCode);

            Action a = coupon.Create;

            a.ShouldNotThrow();
            Assert.Equal(1, coupon.Plans.Count);

            //plan.Deactivate(); BaseTest.Dispose() handles this
        }
Example #17
0
        public void LookupPlan()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Test Lookup"
            };

            plan.UnitAmountInCents.Add("USD", 100);
            plan.TaxExempt = true;
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            plan.CreatedAt.Should().NotBe(default(DateTime));

            var fromService = Plans.Get(plan.PlanCode);

            fromService.PlanCode.Should().Be(plan.PlanCode);
            fromService.UnitAmountInCents.Should().Contain("USD", 100);
            fromService.Description.Should().Be("Test Lookup");
            Assert.True(plan.TaxExempt.Value);
        }
Example #18
0
        public void CreateSubscription_TrialRequiresBillingInfo()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Create Subscription Test"
            };

            plan.UnitAmountInCents.Add("USD", 100);
            plan.TrialRequiresBillingInfo = true;
            plan.TrialIntervalLength      = 10;
            plan.TrialIntervalUnit        = Plan.IntervalUnit.Days;
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            var account = CreateNewAccount();

            var coup = CreateNewCoupon(3);
            var sub  = new Subscription(account, plan, "USD");

            sub.TotalBillingCycles = 5;
            sub.Coupon             = coup;
            sub.TrialPeriodEndsAt  = DateTime.UtcNow.AddDays(2);

            Assert.Null(sub.TaxInCents);
            Assert.Null(sub.TaxType);
            Assert.Null(sub.TaxRate);

            try
            {
                sub.Create();
            }
            catch (RecurlyException e)
            {
                Assert.True(e.Errors.Any());
                Assert.True(e.Errors[0].Symbol == "billing_info_required");
                return;
            }

            throw new Exception("test failed");
        }
Example #19
0
        public void CancelSubscription()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Cancel Subscription Test"
            };

            plan.UnitAmountInCents.Add("USD", 100);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            var account = CreateNewAccountWithBillingInfo();

            var sub = new Subscription(account, plan, "USD");

            sub.Create();

            sub.Cancel();

            sub.CanceledAt.Should().HaveValue().And.NotBe(default(DateTime));
            sub.State.Should().Be(Subscription.SubscriptionState.Canceled);
        }
Example #20
0
        public void UpdatePlan()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Test Update"
            };

            plan.UnitAmountInCents.Add("USD", 100);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            plan.UnitAmountInCents["USD"] = 5000;
            plan.SetupFeeInCents["USD"]   = 100;
            plan.TaxExempt = false;

            plan.Update();

            plan = Plans.Get(plan.PlanCode);
            plan.UnitAmountInCents.Should().Contain("USD", 5000);
            plan.SetupFeeInCents.Should().Contain("USD", 100);
            Assert.False(plan.TaxExempt.Value);
        }
Example #21
0
        public void LookupCouponInvoice()
        {
            var discounts = new Dictionary <string, int> {
                { "USD", 1000 }
            };
            var coupon = new Coupon(GetMockCouponCode(), GetMockCouponName(), discounts);

            coupon.Create();

            var plan = new Plan(GetMockPlanCode(), GetMockPlanCode())
            {
                Description = "Test Lookup Coupon Invoice"
            };

            plan.UnitAmountInCents.Add("USD", 1500);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            var account = CreateNewAccountWithBillingInfo();

            var redemption = account.RedeemCoupon(coupon.CouponCode, "USD");

            var sub = new Subscription(account, plan, "USD", coupon.CouponCode);

            sub.Create();

            // TODO complete this test

            var invoices = account.GetInvoices();

            invoices.Should().NotBeEmpty();

            var invoice     = Invoices.Get(invoices.First().InvoiceNumber);
            var fromInvoice = invoice.GetRedemption();

            redemption.Should().Be(fromInvoice);
        }
Example #22
0
        public void PostponeSubscription()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Postpone Subscription Test"
            };

            plan.UnitAmountInCents.Add("USD", 100);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            var account = CreateNewAccountWithBillingInfo();

            var sub = new Subscription(account, plan, "USD");

            sub.Create();
            var renewal = DateTime.Now.AddMonths(3);

            sub.Postpone(renewal);

            var diff = renewal.Date.Subtract(sub.CurrentPeriodEndsAt.Value.Date).Days;

            diff.Should().Be(1);
        }
Example #23
0
        public void ReactivateSubscription()
        {
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Reactivate Subscription Test"
            };

            plan.UnitAmountInCents.Add("USD", 100);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            var account = CreateNewAccountWithBillingInfo();

            var sub = new Subscription(account, plan, "USD");

            sub.Create();

            sub.Cancel();
            sub.State.Should().Be(Subscription.SubscriptionState.Canceled);

            sub.Reactivate();

            sub.State.Should().Be(Subscription.SubscriptionState.Active);
        }
Example #24
0
        public void DeactivatePlan()
        {
            // Arrange
            var plan = new Plan(GetMockPlanCode(), GetMockPlanName())
            {
                Description = "Test Delete"
            };

            plan.UnitAmountInCents.Add("USD", 100);
            plan.Create();
            PlansToDeactivateOnDispose.Add(plan);

            plan = Plans.Get(plan.PlanCode);
            plan.CreatedAt.Should().NotBe(default(DateTime));
            plan.UnitAmountInCents.Should().Contain("USD", 100);

            //Act
            plan.Deactivate();

            //Assert
            Action get = () => Plans.Get(plan.PlanCode);

            get.ShouldThrow <NotFoundException>();
        }