Exemplo n.º 1
0
        public void GetSubscriptionAction3()
        {
            Subscription        sub;
            Plan                newPlan;
            PayPalInterval      interval;
            Guid                userId;
            SubscriptionActions actions;

            sub      = new Subscription();
            sub.Plan = paidPlan;

            newPlan = paidPlan2;

            interval = new PayPalInterval(1, IntervalUnits.Years);

            userId = Guid.NewGuid();

            actions = PayPalManagement.GetSubscriptionAction(sub, newPlan, interval, userId);

            Assert.AreEqual(ActionTypes.Modify, actions.Action);
            Assert.AreEqual(199.99, actions.NewSubscription.Cost);
            Assert.AreEqual(null, actions.NewSubscription.EndTime);
            Assert.IsTrue(actions.NewSubscription.Id != Guid.Empty);
            Assert.AreEqual("1 Y", actions.NewSubscription.PayPalInterval);
            Assert.AreEqual(newPlan, actions.NewSubscription.Plan);
            Assert.AreEqual(userId, actions.NewSubscription.UserId);
        }
Exemplo n.º 2
0
 public void Units()
 {
     ppi       = new PayPalInterval("4 W");
     ppi.Units = IntervalUnits.Months;
     Assert.AreEqual(4, ppi.Quantity);
     Assert.AreEqual(IntervalUnits.Months, ppi.Units);
 }
Exemplo n.º 3
0
 public void Quantity()
 {
     ppi          = new PayPalInterval("4 W");
     ppi.Quantity = 6;
     Assert.AreEqual(6, ppi.Quantity);
     Assert.AreEqual(IntervalUnits.Weeks, ppi.Units);
 }
Exemplo n.º 4
0
        public void AddTo4()
        {
            DateTime now = DateTime.Now;

            ppi = new PayPalInterval(6, IntervalUnits.Years);

            Assert.AreEqual(now.AddYears(6), ppi.AddTo(now));
        }
Exemplo n.º 5
0
        public void AddTo3()
        {
            DateTime now = DateTime.Now;

            ppi = new PayPalInterval(5, IntervalUnits.Months);

            Assert.AreEqual(now.AddMonths(5), ppi.AddTo(now));
        }
Exemplo n.º 6
0
        public void AddTo2()
        {
            DateTime now = DateTime.Now;

            ppi = new PayPalInterval(7, IntervalUnits.Days);

            Assert.AreEqual(now.AddDays(7), ppi.AddTo(now));
        }
Exemplo n.º 7
0
        /// <summary>
        ///		Modifies the subscription and adds the appropriate interval of
        ///		time t the subscription.
        /// </summary>
        private void renewAccount()
        {
            PayPalInterval ppi;

            _saveSubscription = _existingSubscription;

            _log.DebugFormat("Renewing account for subscription '{0}'", _saveSubscription.Id);

            if (_saveSubscription.StartTime == null)
            {
                _saveSubscription.StartTime = _dbNow;
            }

            //Parse the interval, and add it to the subscription
            ppi = new PayPalInterval(_saveSubscription.PayPalInterval);

            _saveSubscription.EndTime = ppi.AddTo(_dbNow);
        }
Exemplo n.º 8
0
 public void ctor()
 {
     ppi = new PayPalInterval(7, IntervalUnits.Weeks);
     Assert.AreEqual(7, ppi.Quantity);
     Assert.AreEqual(IntervalUnits.Weeks, ppi.Units);
 }
Exemplo n.º 9
0
 public void Parse4()
 {
     ppi = new PayPalInterval("3 Y");
     Assert.AreEqual(3, ppi.Quantity);
     Assert.AreEqual(IntervalUnits.Years, ppi.Units);
 }
Exemplo n.º 10
0
 public void Parse3()
 {
     ppi = new PayPalInterval("3 W");
     Assert.AreEqual(3, ppi.Quantity);
     Assert.AreEqual(IntervalUnits.Weeks, ppi.Units);
 }
Exemplo n.º 11
0
 public void Parse2()
 {
     ppi = new PayPalInterval("5 D");
     Assert.AreEqual(5, ppi.Quantity);
     Assert.AreEqual(IntervalUnits.Days, ppi.Units);
 }
Exemplo n.º 12
0
 public void TestToString4()
 {
     ppi = new PayPalInterval("5 Y");
     Assert.AreEqual("5 Y", ppi.ToString());
 }
Exemplo n.º 13
0
 public void Parse()
 {
     ppi = new PayPalInterval("3 M");
     Assert.AreEqual(3, ppi.Quantity);
     Assert.AreEqual(IntervalUnits.Months, ppi.Units);
 }
Exemplo n.º 14
0
        public static SubscriptionActions GetSubscriptionAction(Subscription currentSubscription, Plan newPlan, PayPalInterval interval, Guid userId)
        {
            SubscriptionActions actions;

            actions = new SubscriptionActions();

            //They need a subscription if they're switching to a paid plan
            if (newPlan.Id == 1)
            {
                actions.Action = ActionTypes.Cancel;
            }
            else
            {
                actions.Action          = ActionTypes.Modify;
                actions.NewSubscription = getNewSubscription(newPlan, interval.Units == IntervalUnits.Months, userId);
            }

            if (currentSubscription == null || currentSubscription.Plan == null || currentSubscription.Plan.Id == 1)
            {
                if (newPlan.Id == 1)
                {
                    actions.Action = ActionTypes.NoChange;
                }
                else
                {
                    //The modify method will create a new subscription when upgrading from the free account
                    actions.Action = ActionTypes.StartPlan;
                }
            }

            return(actions);
        }