Пример #1
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;
                }
            }
        }
Пример #2
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;
                }
            }
        }