internal override void ReadXml(XmlTextReader reader) { _saved = true; string href; while (reader.Read()) { if (reader.Name == "subscription" && reader.NodeType == XmlNodeType.EndElement) break; if (reader.NodeType != XmlNodeType.Element) continue; DateTime dateVal; Int32 billingCycles; switch (reader.Name) { case "account": href = reader.GetAttribute("href"); if (null != href) _accountCode = Uri.UnescapeDataString(href.Substring(href.LastIndexOf("/") + 1)); break; case "plan": ReadPlanXml(reader); break; case "uuid": Uuid = reader.ReadElementContentAsString(); break; case "state": State = reader.ReadElementContentAsString().ParseAsEnum<SubscriptionState>(); break; case "unit_amount_in_cents": UnitAmountInCents = reader.ReadElementContentAsInt(); break; case "currency": Currency = reader.ReadElementContentAsString(); break; case "quantity": Quantity = 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 "bank_account_authorized_at": if (DateTime.TryParse(reader.ReadElementContentAsString(), out dateVal)) BankAccountAuthorizedAt = dateVal; break; case "subscription_add_ons": // overwrite existing list with what came back from Recurly AddOns = new SubscriptionAddOnList(this); AddOns.ReadXml(reader); break; case "invoice": href = reader.GetAttribute("href"); if (null != href) _invoiceNumber = Uri.UnescapeDataString(href.Substring(href.LastIndexOf("/") + 1)); break; case "pending_subscription": PendingSubscription = new Subscription { IsPendingSubscription = true }; PendingSubscription.ReadPendingSubscription(reader); // TODO test all returned properties are read break; case "collection_method": CollectionMethod = reader.ReadElementContentAsString(); break; case "net_terms": NetTerms = reader.ReadElementContentAsInt(); break; case "po_number": PoNumber = reader.ReadElementContentAsString(); break; case "total_billing_cycles": if (Int32.TryParse(reader.ReadElementContentAsString(), out billingCycles)) TotalBillingCycles = billingCycles; break; case "remaining_billing_cycles": if (Int32.TryParse(reader.ReadElementContentAsString(), out billingCycles)) RemainingBillingCycles = billingCycles; break; case "tax_in_cents": TaxInCents = reader.ReadElementContentAsInt(); break; case "tax_type": TaxType = reader.ReadElementContentAsString(); break; case "tax_rate": TaxRate = reader.ReadElementContentAsDecimal(); 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 "address": Address = new Address(reader); break; } } }
internal override void ReadXml(XmlTextReader reader) { while (reader.Read()) { if (reader.Name == "account" && reader.NodeType == XmlNodeType.EndElement) break; if (reader.NodeType != XmlNodeType.Element) continue; switch (reader.Name) { case "account_code": AccountCode = reader.ReadElementContentAsString(); break; case "state": // TODO investigate in case of incoming data representing multiple states, as https://dev.recurly.com/docs/get-account says is possible State = reader.ReadElementContentAsString().ParseAsEnum<AccountState>(); break; case "username": Username = reader.ReadElementContentAsString(); break; case "email": Email = reader.ReadElementContentAsString(); break; case "first_name": FirstName = reader.ReadElementContentAsString(); break; case "last_name": LastName = reader.ReadElementContentAsString(); break; case "company_name": CompanyName = reader.ReadElementContentAsString(); break; case "vat_number": VatNumber = reader.ReadElementContentAsString(); break; case "tax_exempt": TaxExempt = reader.ReadElementContentAsBoolean(); break; case "entity_use_code": EntityUseCode = reader.ReadElementContentAsString(); break; case "accept_language": AcceptLanguage = reader.ReadElementContentAsString(); break; case "hosted_login_token": HostedLoginToken = reader.ReadElementContentAsString(); break; case "created_at": CreatedAt = reader.ReadElementContentAsDateTime(); break; case "address": Address = new Address(reader); break; case "vat_location_valid": if (reader.GetAttribute("nil") == null) { VatLocationValid = reader.ReadElementContentAsBoolean(); } break; } } }
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)); 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 "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(); 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; } } }