Exemplo n.º 1
0
 public static RecurlyAccount NewAccount(string testName)
 {
     RecurlyAccount acct = new RecurlyAccount(DateTime.Now.Millisecond.ToString() + "-acct");
     acct.FirstName = "Verena";
     acct.LastName = "Test";
     acct.CompanyName = testName;
     acct.Email = "*****@*****.**";
     return acct;
 }
        public static RecurlySubscription Get(RecurlyAccount account)
        {
            RecurlySubscription sub = new RecurlySubscription(account);

            HttpStatusCode statusCode = RecurlyClient.PerformRequest(RecurlyClient.HttpRequestMethod.Get,
                                                                     SubscriptionUrl(account.AccountCode),
                                                                     new RecurlyClient.ReadXmlDelegate(sub.ReadXml));

            if (statusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }

            return(sub);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Lookup a Recurly account
        /// </summary>
        /// <param name="accountCode"></param>
        /// <returns></returns>
        public static RecurlyAccount Get(string accountCode)
        {
            RecurlyAccount account = new RecurlyAccount();

            HttpStatusCode statusCode = RecurlyClient.PerformRequest(RecurlyClient.HttpRequestMethod.Get,
                                                                     UrlPrefix + System.Web.HttpUtility.UrlEncode(accountCode),
                                                                     new RecurlyClient.ReadXmlDelegate(account.ReadXml));

            if (statusCode == HttpStatusCode.NotFound)
            {
                return(null);
            }

            return(account);
        }
Exemplo n.º 4
0
        public static RecurlyBillingInfo NewBillingInfo(RecurlyAccount account)
        {
            RecurlyBillingInfo billingInfo = new RecurlyBillingInfo(account);
            billingInfo.FirstName = account.FirstName;
            billingInfo.LastName = account.LastName;
            billingInfo.Address1 = "123 Test St";
            billingInfo.City = "San Francsico";
            billingInfo.State = "CA";
            billingInfo.Country = "US";
            billingInfo.PostalCode = "94105";
            billingInfo.CreditCard.ExpirationMonth = DateTime.Now.Month;
            billingInfo.CreditCard.ExpirationYear = DateTime.Now.Year + 1;
            billingInfo.CreditCard.Number = "1";
            billingInfo.CreditCard.VerificationValue = "123";

            return billingInfo;
        }
 public RecurlyBillingInfo(RecurlyAccount account) : this()
 {
     this.AccountCode = account.AccountCode;
 }
 public RecurlySubscription(RecurlyAccount account)
 {
     this.Account  = account;
     this.Quantity = 1;
 }
        public static void Create(RecurlyAccount acct, int amountInCents, string description)
        {
            RecurlyTransaction toCreate = new RecurlyTransaction();

            toCreate.Account = acct;
            toCreate.AmountInCents = amountInCents;
            toCreate.Description = description;

            RecurlyClient.PerformRequest(RecurlyClient.HttpRequestMethod.Post,
                UrlPrefix,
                new RecurlyClient.WriteXmlDelegate(toCreate.WriteXml));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Lookup a Recurly account
        /// </summary>
        /// <param name="accountCode"></param>
        /// <returns></returns>
        public static RecurlyAccount Get(string accountCode)
        {
            RecurlyAccount account = new RecurlyAccount();

            HttpStatusCode statusCode = RecurlyClient.PerformRequest(RecurlyClient.HttpRequestMethod.Get,
                UrlPrefix + System.Web.HttpUtility.UrlEncode(accountCode),
                new RecurlyClient.ReadXmlDelegate(account.ReadXml));

            if (statusCode == HttpStatusCode.NotFound)
                return null;

            return account;
        }
        internal void ReadXml(XmlTextReader reader)
        {
            while (reader.Read())
            {
                // End of subscription element, get out of here
                if (reader.Name == "subscription" && reader.NodeType == XmlNodeType.EndElement)
                    break;

                if (reader.NodeType == XmlNodeType.Element)
                {
                    DateTime dateVal;
                    switch (reader.Name)
                    {
                        case "account":
                            Account = new RecurlyAccount(reader);
                            break;

                        case "plan_code":
                            PlanCode = reader.ReadElementContentAsString();
                            break;

                        case "state":
                            State = reader.ReadElementContentAsString();
                            break;

                        case "quantity":
                            Quantity = reader.ReadElementContentAsInt();
                            break;

                        case "unit_amount_in_cents":
                            UnitAmountInCents = reader.ReadElementContentAsInt();
                            break;

                        case "activated_at":
                            if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                                ActivatedAt = dateVal;
                            break;

                        case "canceled_at":
                            if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                                CanceledAt = dateVal;
                            break;

                        case "expires_at":
                            if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                                ExpiresAt = dateVal;
                            break;

                        case "current_period_started_at":
                            if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                                CurrentPeriodStartedAt = dateVal;
                            break;

                        case "current_period_ends_at":
                            if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                                CurrentPeriodEndsAt = dateVal;
                            break;

                        case "trial_started_at":
                            if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                                TrialPeriodStartedAt = dateVal;
                            break;

                        case "trial_ends_at":
                            if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal))
                                trialPeriodEndsAt = dateVal;
                            break;

                        case "pending_subscription":
                            // TODO: Parse pending subscription
                            break;
                    }
                }
            }
        }
 public RecurlySubscription(RecurlyAccount account)
 {
     this.Account = account;
     this.Quantity = 1;
 }
 internal RecurlyPayPalBillingInfo(RecurlyAccount account)
     : base(account.AccountCode)
 {
 }
 protected void WriteCreateXml(XmlTextWriter writer, RecurlyAccount account, string couponCode, int? billingCycles, DateTime? firstRenewalDate)
 {
     writer.WriteStartElement(ElementName); // Start: subscription
         writer.WriteElementString(PlanCodeElement, PlanCode); //Required
         account.WriteXml(writer); //Required
         writer.WriteElementStringIfProvided(CouponCodeElement,couponCode);
         writer.WriteElementIntIfProvided(UnitAmountInCentsElement, UnitAmountInCents);
         writer.WriteElementString(CurrencyElement,Currency); //Required
         writer.WriteElementIntIfProvided(QuantityElement, Quantity > 1 ? Quantity : new int?());
         writer.WriteElementDateTimeIfProvided(TrialEndsAtElement, TrialEndsAt);
         writer.WriteElementDateTimeIfFuture(StartsAtElement,ActivatedAt);
         writer.WriteElementIntIfProvided(TotalBillingCyclesElement, billingCycles);
         writer.WriteElementDateTimeIfProvided(FirstRenewalDateElement, firstRenewalDate);
         writer.WriteElementListIfAny(AddonsElement, Addons, (w, a) => a.WriteXml(w));
         WriteManualInvoiceElement(writer);
     writer.WriteEndElement(); // End: subscription
 }
        /// <summary>
        /// Create a new subscription.
        /// </summary>
        /// <param name="account"></param>
        /// <param name="couponCode"></param>
        /// <param name="currency"></param>
        /// <param name="startsAt"></param>
        /// <param name="billingCycles"></param>
        /// <param name="firstRenewalDate"></param>
        /// <param name="manualInvoice"></param>
        /// <returns></returns>
        public bool Create(RecurlyAccount account, string couponCode = null, string currency = null, DateTime? startsAt = null, int? billingCycles = null, DateTime? firstRenewalDate = null, RecurlyManualInvoiceDetails manualInvoice = null)
        {
            if (String.IsNullOrWhiteSpace(PlanCode)) throw new InvalidOperationException("PlanCode must be provided in order to create a subscription");

            Currency = String.IsNullOrWhiteSpace(currency) ? RecurlyClient.Currency : currency;

            if (billingCycles == 0)
                throw new ArgumentOutOfRangeException("billingCycles","Billing cycles must be greater than 0 if provided");

            if (Quantity < 1)
                throw new InvalidOperationException("Quantity must be greater than 0");

            if(manualInvoice != null)
            {
                CollectionMethod = CollectionMethods.Manual;
                ManualInvoiceDetails = manualInvoice;
            }

            if (CollectionMethod == CollectionMethods.Automatic && ManualInvoiceDetails != null)
                System.Diagnostics.Debug.WriteLine("Subscription has manual invoice details but is set to automatic collection. ManualInvoiceDetails will be ignored.");

            ActivatedAt = startsAt.HasValue ? startsAt.Value : DateTime.MinValue;

            if (firstRenewalDate.HasValue && startsAt.HasValue && firstRenewalDate.Value < startsAt.Value)
                    throw new ArgumentOutOfRangeException("firstRenewalDate", "First renewal date cannot be before the start date");

            var statusCode = RecurlyClient.PerformRequest(RecurlyClient.HttpRequestMethod.Post, Settings.Default.PathSubscriptionCreate,
                                         writer => WriteCreateXml(writer,account,couponCode,billingCycles,firstRenewalDate), ReadXml);

            return statusCode == HttpStatusCode.Created;
        }
Exemplo n.º 14
0
 public bool Equals(RecurlyAccount account)
 {
     return(this.AccountCode == account.AccountCode);
 }
 public RecurlyCreditCardBillingInfo(RecurlyAccount account)
     : base(account.AccountCode)
 {
 }
Exemplo n.º 16
0
        /// <summary>
        /// Lookup a Recurly account
        /// </summary>
        /// <param name="accountCode"></param>
        /// <returns></returns>
        public static RecurlyAccount Get(string accountCode)
        {
            var account = new RecurlyAccount();

            var statusCode = RecurlyClient.PerformRequest(RecurlyClient.HttpRequestMethod.Get,
                UrlPrefix + System.Web.HttpUtility.UrlEncode(accountCode),
                account.ReadXml);

            return statusCode == HttpStatusCode.NotFound ? null : account;
        }
        public static RecurlySubscription Get(RecurlyAccount account)
        {
            RecurlySubscription sub = new RecurlySubscription(account);

            HttpStatusCode statusCode = RecurlyClient.PerformRequest(RecurlyClient.HttpRequestMethod.Get,
                SubscriptionUrl(account.AccountCode),
                new RecurlyClient.ReadXmlDelegate(sub.ReadXml));

            if (statusCode == HttpStatusCode.NotFound)
                return null;

            return sub;
        }
Exemplo n.º 18
0
 public bool Equals(RecurlyAccount account)
 {
     return this.AccountCode == account.AccountCode;
 }
Exemplo n.º 19
0
 public RecurlyBillingInfo(RecurlyAccount account)
     : this()
 {
     this.AccountCode = account.AccountCode;
 }
 public RecurlySubscription(RecurlyAccount account)
 {
     Account = account;
     Quantity = 1;
 }