//sub.AddOns.Add(planAddOn, quantity, unitInCents)
        //sub.AddOns.Add(planAddOn, quantity) // unitInCents=this.Plan.UnitAmountInCents[this.Currency]
        //sub.AddOns.Add(planAddOn) // default quantity=1, unitInCents=this.Plan.UnitAmountInCents[this.Currency]
        public void Add(AddOn planAddOn, int quantity = 1)
        {
            var unitAmount = _subscription.Plan.UnitAmountInCents[_subscription.Currency];
            var sub        = new SubscriptionAddOn(planAddOn.AddOnCode, unitAmount, quantity);

            base.Add(sub);
        }
Exemplo n.º 2
0
        public AddOn GetAddOn(string addOnCode)
        {
            if (string.IsNullOrWhiteSpace(addOnCode))
            {
                return(null);
            }

            var addOn = new AddOn();

            var status = Client.Instance.PerformRequest(Client.HttpRequestMethod.Get,
                                                        UrlPrefix + Uri.EscapeDataString(PlanCode) + "/add_ons/" + Uri.EscapeDataString(addOnCode),
                                                        addOn.ReadXml);

            if (status != HttpStatusCode.OK)
            {
                return(null);
            }

            // PlanCode is needed to update the AddOn
            // TODO: need a cleaner way of getting the plan code from xml
            //       should be using the hrefs of the resources
            addOn.PlanCode = PlanCode;

            return(addOn);
        }
Exemplo n.º 3
0
        public AddOn GetAddOn(string addOnCode)
        {
            var addOn = new AddOn();

            var status = Client.Instance.PerformRequest(Client.HttpRequestMethod.Get,
                                                        UrlPrefix + Uri.EscapeUriString(PlanCode) + "/add_ons/" + Uri.EscapeUriString(addOnCode),
                                                        addOn.ReadXml);

            return(status == HttpStatusCode.OK ? addOn : null);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds the given <see cref="T:Recurly.AddOn"/> to the current Subscription.
        ///
        /// Sample usage:
        /// <code>
        /// sub.AddOns.Add(planAddOn, quantity, unitInCents)
        /// sub.AddOns.Add(planAddOn, quantity) // unitInCents = planAddOn.UnitAmountInCents[this.Currency]
        /// sub.AddOns.Add(planAddOn) // default quantity = 1, unitInCents = planAddOn.UnitAmountInCents[this.Currency]
        /// </code>
        /// </summary>
        /// <param name="planAddOn">The <see cref="T:Recurly.AddOn"/> to add to the current Subscription.</param>
        /// <param name="quantity">The quantity of the add-on. Optional, default is 1.</param>
        public void Add(AddOn planAddOn, int quantity = 1)
        {
            int amount = 0;

            if (planAddOn.UnitAmountInCents.Count > 0 && !planAddOn.UnitAmountInCents.TryGetValue(_subscription.Currency, out amount))
            {
                throw new ValidationException(
                          "The given AddOn does not have UnitAmountInCents for the currency of the subscription (" + _subscription.Currency + ")."
                          , new Errors());
            }
            var sub = new SubscriptionAddOn(planAddOn.AddOnCode, planAddOn.AddOnType, amount, quantity);

            base.Add(sub);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds the given <see cref="T:Recurly.AddOn"/> to the current Subscription.
        ///
        /// Sample usage:
        /// <code>
        /// sub.AddOns.Add(planAddOn, quantity, unitInCents)
        /// sub.AddOns.Add(planAddOn, quantity) // unitInCents = planAddOn.UnitAmountInCents[this.Currency]
        /// sub.AddOns.Add(planAddOn) // default quantity = 1, unitInCents = planAddOn.UnitAmountInCents[this.Currency]
        /// </code>
        /// </summary>
        /// <param name="planAddOn">The <see cref="T:Recurly.AddOn"/> to add to the current Subscription.</param>
        /// <param name="quantity">The quantity of the add-on. Optional, default is 1.</param>
        public void Add(AddOn planAddOn, int quantity = 1)
        {
            int amount = 0;

            if (_subscription == null)
            {
                throw new ValidationException(
                          "SubscriptionAddOnList must be initialized with a Subscription in order to use this method. Try Add(AddOn planAddOn, int quantity, int unitAmountInCents) instead."
                          , new Errors());
            }

            if (planAddOn.UnitAmountInCents.Count > 0 && !planAddOn.UnitAmountInCents.TryGetValue(_subscription.Currency, out amount))
            {
                throw new ValidationException(
                          "The given AddOn does not have UnitAmountInCents for the currency of the subscription (" + _subscription.Currency + ")."
                          , new Errors());
            }
            int?unitAmountInCents = planAddOn.AddOnType.HasValue && (planAddOn.AddOnType.Value == AddOn.Type.Usage) ? (int?)null : amount;

            var sub = new SubscriptionAddOn(planAddOn.AddOnCode, planAddOn.AddOnType, unitAmountInCents, quantity);

            base.Add(sub);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns an new add on associated with this plan.
        /// </summary>
        /// <param name="addOnCode"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public AddOn NewAddOn(string addOnCode, string name)
        {
            var a = new AddOn(PlanCode, addOnCode, name);

            return(a);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Adds the given <see cref="T:Recurly.AddOn"/> to the current Subscription.
        ///
        /// Sample usage:
        /// <code>
        /// sub.AddOns.Add(planAddOn, quantity, unitInCents)
        /// sub.AddOns.Add(planAddOn, quantity) // unitInCents = planAddOn.UnitAmountInCents[this.Currency]
        /// sub.AddOns.Add(planAddOn) // default quantity = 1, unitInCents = planAddOn.UnitAmountInCents[this.Currency]
        /// </code>
        /// </summary>
        /// <param name="planAddOn">The <see cref="T:Recurly.AddOn"/> to add to the current Subscription.</param>
        /// <param name="quantity">The quantity of the add-on. Optional, default is 1.</param>
        /// <param name="unitAmountInCents">Overrides the UnitAmountInCents of the add-on.</param>
        public void Add(AddOn planAddOn, int quantity, int unitAmountInCents)
        {
            var sub = new SubscriptionAddOn(planAddOn.AddOnCode, planAddOn.AddOnType, unitAmountInCents, quantity);

            base.Add(sub);
        }
Exemplo n.º 8
0
 /// <summary>
 /// Returns an new add on associated with this plan.
 /// </summary>
 /// <param name="addOnCode"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 public AddOn NewAddOn(string addOnCode, string name)
 {
     var a = new AddOn(PlanCode, addOnCode, name);
     return a;
 }
Exemplo n.º 9
0
        public AddOn GetAddOn(string addOnCode)
        {
            var addOn = new AddOn();

            var status = Client.Instance.PerformRequest(Client.HttpRequestMethod.Get,
                UrlPrefix + Uri.EscapeUriString(PlanCode) + "/add_ons/" + Uri.EscapeUriString(addOnCode),
                addOn.ReadXml);

            if (null != addOn)
                addOn.PlanCode = PlanCode;

            return status == HttpStatusCode.OK ? addOn : null;
        }
Exemplo n.º 10
0
 /// <summary>
 /// Returns an new add on associated with this plan.
 /// </summary>
 /// <param name="addOnCode"></param>
 /// <param name="name"></param>
 /// <returns></returns>
 public AddOn CreateAddOn(string addOnCode, string name)
 {
     AddOn a = new AddOn(this.PlanCode, addOnCode, name);
     return a;
 }
Exemplo n.º 11
0
 public bool Equals(AddOn addon)
 {
     return(PlanCode == addon.PlanCode && AddOnCode == addon.AddOnCode);
 }
Exemplo n.º 12
0
        public AddOn GetAddOn(string addOnCode)
        {
            var addOn = new AddOn();

            var status = Client.Instance.PerformRequest(Client.HttpRequestMethod.Get,
                UrlPrefix + Uri.EscapeUriString(PlanCode) + "/add_ons/" + Uri.EscapeUriString(addOnCode),
                addOn.ReadXml);

            if (status != HttpStatusCode.OK) return null;

            // PlanCode is needed to update the AddOn
            // TODO: need a cleaner way of getting the plan code from xml
            //       should be using the hrefs of the resources
            addOn.PlanCode = PlanCode;

            return addOn;
        }