protected void ReadPendingSubscription(XmlTextReader reader) { while (reader.Read()) { if (reader.Name == "pending_subscription" && reader.NodeType == XmlNodeType.EndElement) break; if (reader.NodeType != XmlNodeType.Element) continue; switch (reader.Name) { case "plan": ReadPlanXml(reader); break; case "unit_amount_in_cents": UnitAmountInCents = reader.ReadElementContentAsInt(); break; case "quantity": Quantity = reader.ReadElementContentAsInt(); break; case "subscription_add_ons": AddOns = new SubscriptionAddOnList(this); AddOns.ReadXml(reader); break; } } }
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; } } }