internal override void WriteXml(XmlTextWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("billing_info"); // Start: billing_info

            //if a recurly js token is supplied we don't want to send billing info here
            if (string.IsNullOrEmpty(TokenId))
            {
                xmlWriter.WriteStringIfValid("first_name", FirstName);
                xmlWriter.WriteStringIfValid("last_name", LastName);
                xmlWriter.WriteStringIfValid("name_on_account", NameOnAccount);
                xmlWriter.WriteStringIfValid("address1", Address1);
                xmlWriter.WriteStringIfValid("address2", Address2);
                xmlWriter.WriteStringIfValid("city", City);
                xmlWriter.WriteStringIfValid("state", State);
                xmlWriter.WriteStringIfValid("zip", PostalCode);
                xmlWriter.WriteStringIfValid("country", Country);
                xmlWriter.WriteStringIfValid("phone", PhoneNumber);
                xmlWriter.WriteStringIfValid("vat_number", VatNumber);
                xmlWriter.WriteStringIfValid("currency", Currency);

                if (!IpAddress.IsNullOrEmpty())
                {
                    xmlWriter.WriteElementString("ip_address", IpAddress);
                }
                else
                {
                    Debug.WriteLine("Recurly Client Library: Recording IP Address is strongly recommended.");
                }

                if (!CreditCardNumber.IsNullOrEmpty())
                {
                    xmlWriter.WriteElementString("number", CreditCardNumber);
                    xmlWriter.WriteElementString("month", ExpirationMonth.AsString());
                    xmlWriter.WriteElementString("year", ExpirationYear.AsString());

                    xmlWriter.WriteStringIfValid("verification_value", VerificationValue);
                }

                if (!AccountNumber.IsNullOrEmpty())
                {
                    xmlWriter.WriteElementString("routing_number", RoutingNumber);
                    xmlWriter.WriteElementString("account_number", AccountNumber);
                    xmlWriter.WriteElementString("account_type", AccountType.ToString().EnumNameToTransportCase());
                }

                if (!PaypalBillingAgreementId.IsNullOrEmpty())
                {
                    xmlWriter.WriteElementString("paypal_billing_agreement_id", PaypalBillingAgreementId);
                }

                if (!AmazonBillingAgreementId.IsNullOrEmpty())
                {
                    xmlWriter.WriteElementString("amazon_billing_agreement_id", AmazonBillingAgreementId);
                }
            }

            xmlWriter.WriteStringIfValid("token_id", TokenId);

            xmlWriter.WriteEndElement(); // End: billing_info
        }
        internal override void WriteXml(XmlTextWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("billing_info"); // Start: billing_info

            //if a recurly js token is supplied we don't want to send billing info here
            if (string.IsNullOrEmpty(TokenId))
            {
                xmlWriter.WriteStringIfValid("first_name", FirstName);
                xmlWriter.WriteStringIfValid("last_name", LastName);
                xmlWriter.WriteStringIfValid("company", Company);
                xmlWriter.WriteStringIfValid("name_on_account", NameOnAccount);
                xmlWriter.WriteStringIfValid("address1", Address1);
                xmlWriter.WriteStringIfValid("address2", Address2);
                xmlWriter.WriteStringIfValid("city", City);
                xmlWriter.WriteStringIfValid("state", State);
                xmlWriter.WriteStringIfValid("zip", PostalCode);
                xmlWriter.WriteStringIfValid("country", Country);
                xmlWriter.WriteStringIfValid("phone", PhoneNumber);
                xmlWriter.WriteStringIfValid("vat_number", VatNumber);
                xmlWriter.WriteStringIfValid("currency", Currency);

                if (!IpAddress.IsNullOrEmpty())
                {
                    xmlWriter.WriteElementString("ip_address", IpAddress);
                }
                else
                {
                    Debug.WriteLine("Recurly Client Library: Recording IP Address is strongly recommended.");
                }

                if (!CreditCardNumber.IsNullOrEmpty())
                {
                    xmlWriter.WriteElementString("number", CreditCardNumber);
                    xmlWriter.WriteElementString("month", ExpirationMonth.AsString());
                    xmlWriter.WriteElementString("year", ExpirationYear.AsString());

                    xmlWriter.WriteStringIfValid("verification_value", VerificationValue);
                }

                if (!AccountNumber.IsNullOrEmpty())
                {
                    xmlWriter.WriteElementString("routing_number", RoutingNumber);
                    xmlWriter.WriteElementString("account_number", AccountNumber);
                    xmlWriter.WriteElementString("account_type", AccountType.ToString().EnumNameToTransportCase());
                }

                if (!PaypalBillingAgreementId.IsNullOrEmpty())
                {
                    xmlWriter.WriteElementString("paypal_billing_agreement_id", PaypalBillingAgreementId);
                }

                if (!AmazonBillingAgreementId.IsNullOrEmpty())
                {
                    xmlWriter.WriteElementString("amazon_billing_agreement_id", AmazonBillingAgreementId);
                }

                if (!AmazonRegion.IsNullOrEmpty())
                {
                    xmlWriter.WriteElementString("amazon_region", AmazonRegion);
                }

                if (ExternalHppType.HasValue)
                {
                    xmlWriter.WriteElementString("external_hpp_type", ExternalHppType.Value.ToString().EnumNameToTransportCase());
                }

                if (!GatewayCode.IsNullOrEmpty())
                {
                    xmlWriter.WriteElementString("gateway_code", GatewayCode);
                    xmlWriter.WriteElementString("gateway_token", GatewayToken);

                    // EnumNameToTransportCase() turns MasterCard into "master_card",
                    // but it needs to be "master" for the server to accept it.
                    // Check for this edge case before writing the card_type tag.
                    var card = CardType.ToString().EnumNameToTransportCase();
                    if (card == "master_card")
                    {
                        card = "master";
                    }

                    xmlWriter.WriteElementString("card_type", card);
                }
            }

            xmlWriter.WriteStringIfValid("token_id", TokenId);

            xmlWriter.WriteEndElement(); // End: billing_info
        }