Example #1
0
        /// <summary>
        /// Gets all adjustments for this account
        /// </summary>
        /// <param name="filter">Optional filter criteria</param>
        /// <param name="type">Adjustment type to retrieve. Optional, default: All.</param>
        /// <param name="state">State of the Adjustments to retrieve. Optional, default: Any.</param>
        /// <returns></returns>
        public RecurlyList <Adjustment> GetAdjustments(FilterCriteria filter, Adjustment.AdjustmentType type = Adjustment.AdjustmentType.All,
                                                       Adjustment.AdjustmentState state = Adjustment.AdjustmentState.Any)
        {
            var adjustments = new AdjustmentList();

            filter = filter ?? FilterCriteria.Instance;
            var parameters = filter.ToNamedValueCollection();

            if (type != Adjustment.AdjustmentType.All)
            {
                parameters["type"] = type.ToString().EnumNameToTransportCase();
            }
            if (state != Adjustment.AdjustmentState.Any)
            {
                parameters["state"] = state.ToString().EnumNameToTransportCase();
            }


            var statusCode = Client.Instance.PerformRequest(Client.HttpRequestMethod.Get,
                                                            UrlPrefix + Uri.EscapeDataString(AccountCode) + "/adjustments/"
                                                            + "?" + parameters.ToString()
                                                            , adjustments.ReadXmlList);

            return(statusCode == HttpStatusCode.NotFound ? null : adjustments);
        }
        /// <summary>
        /// Gets all adjustments for this account, by type
        /// </summary>
        /// <param name="type">Adjustment type to retrieve. Optional, default: All.</param>
        /// <param name="state">State of the Adjustments to retrieve. Optional, default: Any.</param>
        /// <returns></returns>
        public RecurlyList <Adjustment> GetAdjustments(Adjustment.AdjustmentType type   = Adjustment.AdjustmentType.All,
                                                       Adjustment.AdjustmentState state = Adjustment.AdjustmentState.Any)
        {
            var adjustments = new AdjustmentList();
            var statusCode  = Client.Instance.PerformRequest(Client.HttpRequestMethod.Get,
                                                             UrlPrefix + Uri.EscapeUriString(AccountCode) + "/adjustments/"
                                                             + Build.QueryStringWith(Adjustment.AdjustmentState.Any == state ? "" : "state=" + state.ToString().EnumNameToTransportCase())
                                                             .AndWith(Adjustment.AdjustmentType.All == type ? "" : "type=" + type.ToString().EnumNameToTransportCase())
                                                             , adjustments.ReadXmlList);

            return(statusCode == HttpStatusCode.NotFound ? null : adjustments);
        }
Example #3
0
        /// <summary>
        /// Gets all adjustments for this account, by type
        /// </summary>
        /// <param name="type">Adjustment type to retrieve. Optional, default: All.</param>
        /// <param name="state">State of the Adjustments to retrieve. Optional, default: Any.</param>
        /// <returns></returns>
        public RecurlyList <Adjustment> GetAdjustments(Adjustment.AdjustmentType type   = Adjustment.AdjustmentType.All,
                                                       Adjustment.AdjustmentState state = Adjustment.AdjustmentState.Any, DateTime beginTime = new DateTime(), int perPage = 50)
        {
            beginTime = DateTime.SpecifyKind(beginTime, DateTimeKind.Utc);

            var adjustments = new AdjustmentList();
            var statusCode  = Client.Instance.PerformRequest(Client.HttpRequestMethod.Get,
                                                             UrlPrefix + Uri.EscapeDataString(AccountCode) + "/adjustments/"
                                                             + Build.QueryStringWith(Adjustment.AdjustmentState.Any == state ? "" : "state=" + state.ToString().EnumNameToTransportCase())
                                                             .AndWith(Adjustment.AdjustmentType.All == type ? "" : "type=" + type.ToString().EnumNameToTransportCase())
                                                             .AndWith("per_Page=" + perPage)
                                                             .AndWith(beginTime == DateTime.MinValue ? "" : "begin_time=" + beginTime.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ssK"))
                                                             , adjustments.ReadXmlList);

            return(statusCode == HttpStatusCode.NotFound ? null : adjustments);
        }
Example #4
0
        internal void ReadXml(XmlTextReader reader, string nodeName)
        {
            while (reader.Read())
            {
                // End of invoice element, get out of here
                if (reader.Name == nodeName && reader.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }

                if (reader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                DateTime dt;
                int      m;

                switch (reader.Name)
                {
                case "account":
                    var accountHref = reader.GetAttribute("href");
                    AccountCode = Uri.UnescapeDataString(accountHref.Substring(accountHref.LastIndexOf("/") + 1));
                    break;

                case "original_invoice":
                    var             originalInvoiceHref = reader.GetAttribute("href");
                    var             invoiceNumber       = Uri.UnescapeDataString(originalInvoiceHref.Substring(originalInvoiceHref.LastIndexOf("/") + 1));
                    MatchCollection matches             = Regex.Matches(invoiceNumber, "([^\\d]{2})(\\d+)");

                    if (matches.Count == 1)
                    {
                        OriginalInvoiceNumberPrefix = matches[0].Groups[1].Value;
                        OriginalInvoiceNumber       = int.Parse(matches[0].Groups[2].Value);
                    }
                    else
                    {
                        OriginalInvoiceNumber = int.Parse(invoiceNumber);
                    }
                    break;

                case "uuid":
                    Uuid = reader.ReadElementContentAsString();
                    break;

                case "state":
                    var state = reader.ReadElementContentAsString();
                    if (!state.IsNullOrEmpty())
                    {
                        State = state.ParseAsEnum <InvoiceState>();
                    }
                    break;

                case "invoice_number":
                    if (Int32.TryParse(reader.ReadElementContentAsString(), out m))
                    {
                        InvoiceNumber = m;
                    }
                    break;

                case "invoice_number_prefix":
                    InvoiceNumberPrefix = reader.ReadElementContentAsString();
                    break;

                case "po_number":
                    PoNumber = reader.ReadElementContentAsString();
                    break;

                case "vat_number":
                    VatNumber = reader.ReadElementContentAsString();
                    break;

                case "subtotal_in_cents":
                    SubtotalInCents = reader.ReadElementContentAsInt();
                    break;

                case "tax_in_cents":
                    TaxInCents = reader.ReadElementContentAsInt();
                    break;

                case "total_in_cents":
                    TotalInCents = reader.ReadElementContentAsInt();
                    break;

                case "currency":
                    Currency = reader.ReadElementContentAsString();
                    break;

                case "created_at":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dt))
                    {
                        CreatedAt = dt;
                    }
                    break;

                case "updated_at":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dt))
                    {
                        UpdatedAt = dt;
                    }
                    break;

                case "closed_at":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dt))
                    {
                        ClosedAt = dt;
                    }
                    break;

                case "tax_type":
                    TaxType = reader.ReadElementContentAsString();
                    break;

                case "tax_rate":
                    TaxRate = reader.ReadElementContentAsDecimal();
                    break;

                case "tax_region":
                    TaxRegion = reader.ReadElementContentAsString();
                    break;

                case "net_terms":
                    if (int.TryParse(reader.ReadElementContentAsString(), out m))
                    {
                        _netTerms = m;
                    }
                    break;

                case "collection_method":
                    var method = reader.ReadElementContentAsString();
                    if (!method.IsNullOrEmpty())
                    {
                        CollectionMethod = method.ParseAsEnum <Collection>();
                    }
                    break;

                case "customer_notes":
                    CustomerNotes = reader.ReadElementContentAsString();
                    break;

                case "terms_and_conditions":
                    TermsAndConditions = reader.ReadElementContentAsString();
                    break;

                case "vat_reverse_charge_notes":
                    VatReverseChargeNotes = reader.ReadElementContentAsString();
                    break;

                case "gateway_code":
                    GatewayCode = reader.ReadElementContentAsString();
                    break;

                case "line_items":
                    // overrite existing value with the Recurly API response
                    Adjustments = new AdjustmentList();
                    Adjustments.ReadXml(reader);
                    break;

                case "transactions":
                    // overrite existing value with the Recurly API response
                    Transactions = new TransactionList();
                    Transactions.ReadXml(reader);
                    break;

                case "address":
                    Address           = new Address(reader);
                    _referenceAddress = (Address)Address.Clone();
                    break;

                case "shipping_address":
                    ShippingAddress = new ShippingAddress(reader);
                    break;

                case "subtotal_before_discount_in_cents":
                    if (int.TryParse(reader.ReadElementContentAsString(), out m))
                    {
                        SubtotalBeforeDiscountInCents = m;
                    }
                    break;

                case "discount_in_cents":
                    if (int.TryParse(reader.ReadElementContentAsString(), out m))
                    {
                        DiscountInCents = m;
                    }
                    break;

                case "balance_in_cents":
                    if (int.TryParse(reader.ReadElementContentAsString(), out m))
                    {
                        BalanceInCents = m;
                    }
                    break;

                case "due_on":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dt))
                    {
                        DueOn = dt;
                    }
                    break;

                case "type":
                    Type = reader.ReadElementContentAsString();
                    break;

                case "origin":
                    Origin = reader.ReadElementContentAsString();
                    break;

                case "attempt_next_collection_at":
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out dt))
                    {
                        AttemptNextCollectionAt = dt;
                    }
                    break;

                case "recovery_reason":
                    RecoveryReason = reader.ReadElementContentAsString();
                    break;

                case "all_line_items":
                    AllLineItemsLink = reader.ReadElementContentAsString();
                    break;
                }
            }
        }
Example #5
0
 public Invoice()
 {
     Adjustments  = new AdjustmentList();
     Transactions = new TransactionList();
 }
Example #6
0
        internal override void ReadXml(XmlTextReader reader)
        {
            while (reader.Read())
            {
                // End of invoice element, get out of here
                if (reader.Name == "invoice" && reader.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }

                if (reader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                switch (reader.Name)
                {
                case "account":
                    var accountHref = reader.GetAttribute("href");
                    AccountCode = Uri.UnescapeDataString(accountHref.Substring(accountHref.LastIndexOf("/") + 1));
                    break;

                case "original_invoice":
                    var             originalInvoiceHref = reader.GetAttribute("href");
                    var             invoiceNumber       = Uri.UnescapeDataString(originalInvoiceHref.Substring(originalInvoiceHref.LastIndexOf("/") + 1));
                    MatchCollection matches             = Regex.Matches(invoiceNumber, "([^\\d]{2})(\\d+)");

                    if (matches.Count == 1)
                    {
                        OriginalInvoiceNumberPrefix = matches[0].Groups[1].Value;
                        OriginalInvoiceNumber       = int.Parse(matches[0].Groups[2].Value);
                    }
                    else
                    {
                        OriginalInvoiceNumber = int.Parse(invoiceNumber);
                    }
                    break;

                case "uuid":
                    Uuid = reader.ReadElementContentAsString();
                    break;

                case "state":
                    State = reader.ReadElementContentAsString().ParseAsEnum <InvoiceState>();
                    break;

                case "invoice_number":
                    int invNumber;
                    if (Int32.TryParse(reader.ReadElementContentAsString(), out invNumber))
                    {
                        InvoiceNumber = invNumber;
                    }
                    break;

                case "invoice_number_prefix":
                    InvoiceNumberPrefix = reader.ReadElementContentAsString();
                    break;

                case "po_number":
                    PoNumber = reader.ReadElementContentAsString();
                    break;

                case "vat_number":
                    VatNumber = reader.ReadElementContentAsString();
                    break;

                case "subtotal_in_cents":
                    SubtotalInCents = reader.ReadElementContentAsInt();
                    break;

                case "tax_in_cents":
                    TaxInCents = reader.ReadElementContentAsInt();
                    break;

                case "total_in_cents":
                    TotalInCents = reader.ReadElementContentAsInt();
                    break;

                case "currency":
                    Currency = reader.ReadElementContentAsString();
                    break;

                case "created_at":
                    DateTime createdAt;
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out createdAt))
                    {
                        CreatedAt = createdAt;
                    }
                    break;

                case "updated_at":
                    DateTime updatedAt;
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out updatedAt))
                    {
                        UpdatedAt = updatedAt;
                    }
                    break;

                case "closed_at":
                    DateTime closedAt;
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out closedAt))
                    {
                        ClosedAt = closedAt;
                    }
                    break;

                case "tax_type":
                    TaxType = reader.ReadElementContentAsString();
                    break;

                case "tax_rate":
                    TaxRate = reader.ReadElementContentAsDecimal();
                    break;

                case "tax_region":
                    TaxRegion = reader.ReadElementContentAsString();
                    break;

                case "net_terms":
                    NetTerms = reader.ReadElementContentAsInt();
                    break;

                case "collection_method":
                    CollectionMethod = reader.ReadElementContentAsString().ParseAsEnum <Collection>();
                    break;

                case "customer_notes":
                    CustomerNotes = reader.ReadElementContentAsString();
                    break;

                case "terms_and_conditions":
                    TermsAndConditions = reader.ReadElementContentAsString();
                    break;

                case "vat_reverse_charge_notes":
                    VatReverseChargeNotes = reader.ReadElementContentAsString();
                    break;

                case "line_items":
                    // overrite existing value with the Recurly API response
                    Adjustments = new AdjustmentList();
                    Adjustments.ReadXml(reader);
                    break;

                case "transactions":
                    // overrite existing value with the Recurly API response
                    Transactions = new TransactionList();
                    Transactions.ReadXml(reader);
                    break;

                case "address":
                    Address = new Address(reader);
                    break;

                case "subtotal_after_discount_in_cents":
                    int s;
                    if (int.TryParse(reader.ReadElementContentAsString(), out s))
                    {
                        SubtotalAfterDiscountInCents = s;
                    }
                    break;

                case "attempt_next_collection_at":
                    DateTime d;
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out d))
                    {
                        AttemptNextCollectionAt = d;
                    }
                    break;

                case "recovery_reason":
                    RecoveryReason = reader.ReadElementContentAsString();
                    break;

                case "all_line_items":
                    AllLineItemsLink = reader.ReadElementContentAsString();
                    break;
                }
            }
        }
Example #7
0
 internal Invoice()
 {
     Adjustments  = new AdjustmentList();
     Transactions = new TransactionList();
 }
Example #8
0
        internal override void ReadXml(XmlTextReader reader)
        {
            while (reader.Read())
            {
                // End of invoice element, get out of here
                if (reader.Name == "invoice" && reader.NodeType == XmlNodeType.EndElement)
                {
                    break;
                }

                if (reader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                switch (reader.Name)
                {
                case "account":
                    var accountHref = reader.GetAttribute("href");
                    AccountCode = Uri.UnescapeDataString(accountHref.Substring(accountHref.LastIndexOf("/") + 1));
                    break;

                case "subscription":
                    var subHref = reader.GetAttribute("href");
                    SubscriptionUuid = Uri.UnescapeDataString(subHref.Substring(subHref.LastIndexOf("/") + 1));
                    break;

                case "original_invoice":
                    var originalInvoiceHref = reader.GetAttribute("href");
                    var invoiceNumber       = Uri.UnescapeDataString(originalInvoiceHref.Substring(originalInvoiceHref.LastIndexOf("/") + 1));
                    OriginalInvoiceNumber = Convert.ToInt32(invoiceNumber);
                    break;

                case "uuid":
                    Uuid = reader.ReadElementContentAsString();
                    break;

                case "state":
                    State = reader.ReadElementContentAsString().ParseAsEnum <InvoiceState>();
                    break;

                case "invoice_number":
                    int invNumber;
                    if (Int32.TryParse(reader.ReadElementContentAsString(), out invNumber))
                    {
                        InvoiceNumber = invNumber;
                    }
                    break;

                case "po_number":
                    PoNumber = reader.ReadElementContentAsString();
                    break;

                case "vat_number":
                    VatNumber = reader.ReadElementContentAsString();
                    break;

                case "subtotal_in_cents":
                    SubtotalInCents = reader.ReadElementContentAsInt();
                    break;

                case "tax_in_cents":
                    TaxInCents = reader.ReadElementContentAsInt();
                    break;

                case "total_in_cents":
                    TotalInCents = reader.ReadElementContentAsInt();
                    break;

                case "currency":
                    Currency = reader.ReadElementContentAsString();
                    break;

                case "created_at":
                    DateTime createdAt;
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out createdAt))
                    {
                        CreatedAt = createdAt;
                    }
                    break;

                case "closed_at":
                    DateTime closedAt;
                    if (DateTime.TryParse(reader.ReadElementContentAsString(), out closedAt))
                    {
                        ClosedAt = closedAt;
                    }
                    break;

                case "tax_type":
                    TaxType = reader.ReadElementContentAsString();
                    break;

                case "tax_rate":
                    TaxRate = reader.ReadElementContentAsDecimal();
                    break;

                case "net_terms":
                    NetTerms = reader.ReadElementContentAsInt();
                    break;

                case "collection_method":
                    CollectionMethod = reader.ReadElementContentAsString();
                    break;

                case "line_items":
                    // overrite existing value with the Recurly API response
                    Adjustments = new AdjustmentList();
                    Adjustments.ReadXml(reader);
                    break;

                case "transactions":
                    // overrite existing value with the Recurly API response
                    Transactions = new TransactionList();
                    Transactions.ReadXml(reader);
                    break;

                case "address":
                    Address = new Address(reader);
                    break;
                }
            }
        }