internal void WriteChangeSubscriptionXml(XmlTextWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("subscription"); // Start: subscription

            xmlWriter.WriteElementString("timeframe", TimeFrame.ToString().EnumNameToTransportCase());

            if (Quantity.HasValue)
            {
                xmlWriter.WriteElementString("quantity", Quantity.ToString());
            }

            xmlWriter.WriteStringIfValid("plan_code", PlanCode);
            xmlWriter.WriteIfCollectionHasAny("subscription_add_ons", AddOns);
            xmlWriter.WriteStringIfValid("coupon_code", CouponCode);

            if (UnitAmountInCents.HasValue)
            {
                xmlWriter.WriteElementString("unit_amount_in_cents", UnitAmountInCents.Value.AsString());
            }

            if (CollectionMethod.Like("manual"))
            {
                xmlWriter.WriteElementString("collection_method", "manual");
                xmlWriter.WriteElementString("net_terms", NetTerms.Value.AsString());
                xmlWriter.WriteElementString("po_number", PoNumber);
            }
            else if (CollectionMethod.Like("automatic"))
            {
                xmlWriter.WriteElementString("collection_method", "automatic");
            }

            if (ImportedTrial.HasValue)
            {
                xmlWriter.WriteElementString("imported_trial", ImportedTrial.Value.ToString().ToLower());
            }

            if (RevenueScheduleType.HasValue)
            {
                xmlWriter.WriteElementString("revenue_schedule_type", RevenueScheduleType.Value.ToString().EnumNameToTransportCase());
            }

            if (RemainingBillingCycles.HasValue)
            {
                xmlWriter.WriteElementString("remaining_billing_cycles", RemainingBillingCycles.Value.AsString());
            }

            if (AutoRenew.HasValue)
            {
                xmlWriter.WriteElementString("auto_renew", AutoRenew.Value.AsString());
            }

            if (RenewalBillingCycles.HasValue)
            {
                xmlWriter.WriteElementString("renewal_billing_cycles", RenewalBillingCycles.Value.AsString());
            }

            xmlWriter.WriteIfCollectionHasAny("custom_fields", CustomFields);

            xmlWriter.WriteEndElement(); // End: subscription
        }
Ejemplo n.º 2
0
        internal override void WriteXml(XmlTextWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("plan");

            xmlWriter.WriteElementString("plan_code", PlanCode);
            xmlWriter.WriteElementString("name", Name);
            xmlWriter.WriteStringIfValid("description", Description);
            xmlWriter.WriteStringIfValid("accounting_code", AccountingCode);
            if (PlanIntervalLength > 0)
            {
                xmlWriter.WriteElementString("plan_interval_unit", PlanIntervalUnit.ToString().EnumNameToTransportCase());
                xmlWriter.WriteElementString("plan_interval_length", PlanIntervalLength.AsString());
            }
            if (TrialIntervalLength > 0)
            {
                xmlWriter.WriteElementString("trial_interval_unit", TrialIntervalUnit.ToString().EnumNameToTransportCase());
                xmlWriter.WriteElementString("trial_interval_length", TrialIntervalLength.AsString());
            }

            xmlWriter.WriteIfCollectionHasAny("setup_fee_in_cents", SetupFeeInCents, pair => pair.Key, pair => pair.Value.AsString());

            xmlWriter.WriteIfCollectionHasAny("unit_amount_in_cents", UnitAmountInCents, pair => pair.Key, pair => pair.Value.AsString());

            if (TotalBillingCycles.HasValue && TotalBillingCycles > 0)
            {
                xmlWriter.WriteElementString("total_billing_cycles", TotalBillingCycles.Value.AsString());
            }

            xmlWriter.WriteStringIfValid("unit_name", UnitName);

            if (DisplayDonationAmounts.HasValue)
            {
                xmlWriter.WriteElementString("display_donation_amounts", DisplayDonationAmounts.Value.AsString());
            }

            if (DisplayQuantity.HasValue)
            {
                xmlWriter.WriteElementString("display_quantity", DisplayQuantity.Value.AsString());
            }

            if (DisplayPhoneNumber.HasValue)
            {
                xmlWriter.WriteElementString("display_phone_number", DisplayPhoneNumber.Value.AsString());
            }

            if (BypassHostedConfirmation.HasValue)
            {
                xmlWriter.WriteElementString("bypass_hosted_confirmation", BypassHostedConfirmation.Value.AsString());
            }

            if (TaxExempt.HasValue)
            {
                xmlWriter.WriteElementString("tax_exempt", TaxExempt.Value.AsString());
            }

            xmlWriter.WriteStringIfValid("success_url", SuccessUrl);
            xmlWriter.WriteStringIfValid("cancel_url", CancelUrl);

            xmlWriter.WriteEndElement();
        }
Ejemplo n.º 3
0
        internal override void WriteXml(XmlTextWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("coupon"); // Start: coupon

            xmlWriter.WriteElementString("coupon_code", CouponCode);
            xmlWriter.WriteElementString("name", Name);
            xmlWriter.WriteElementString("hosted_description", HostedDescription);
            xmlWriter.WriteElementString("invoice_description", InvoiceDescription);

            if (RedeemByDate.HasValue)
            {
                xmlWriter.WriteElementString("redeem_by_date", RedeemByDate.Value.ToString("s"));
            }

            if (SingleUse.HasValue)
            {
                xmlWriter.WriteElementString("single_use", SingleUse.Value.AsString());
            }

            if (AppliesForMonths.HasValue)
            {
                xmlWriter.WriteElementString("applies_for_months", AppliesForMonths.Value.AsString());
            }

            if (AppliesToAllPlans.HasValue)
            {
                xmlWriter.WriteElementString("applies_to_all_plans", AppliesToAllPlans.Value.AsString());
            }

            if (MaxRedemptions.HasValue)
            {
                xmlWriter.WriteElementString("max_redemptions", MaxRedemptions.Value.AsString());
            }

            xmlWriter.WriteElementString("discount_type", DiscountType.ToString().EnumNameToTransportCase());

            if (CouponDiscountType.Percent == DiscountType && DiscountPercent.HasValue)
            {
                xmlWriter.WriteElementString("discount_percent", DiscountPercent.Value.AsString());
            }

            if (CouponDiscountType.Dollars == DiscountType)
            {
                xmlWriter.WriteIfCollectionHasAny("discount_in_cents", DiscountInCents, pair => pair.Key,
                                                  pair => pair.Value.AsString());
            }

            xmlWriter.WriteIfCollectionHasAny("plan_codes", Plans, s => "plan_code", s => s);

            xmlWriter.WriteEndElement(); // End: coupon
        }
Ejemplo n.º 4
0
        internal void WriteXml(XmlTextWriter xmlWriter, string xmlName)
        {
            xmlWriter.WriteStartElement(xmlName); // Start: account

            xmlWriter.WriteElementString("account_code", AccountCode);
            xmlWriter.WriteStringIfValid("username", Username);
            xmlWriter.WriteStringIfValid("email", Email);
            xmlWriter.WriteStringIfValid("first_name", FirstName);
            xmlWriter.WriteStringIfValid("last_name", LastName);
            xmlWriter.WriteStringIfValid("company_name", CompanyName);
            xmlWriter.WriteStringIfValid("accept_language", AcceptLanguage);
            xmlWriter.WriteStringIfValid("vat_number", VatNumber);
            xmlWriter.WriteStringIfValid("entity_use_code", EntityUseCode);
            xmlWriter.WriteStringIfValid("cc_emails", CcEmails);
            xmlWriter.WriteStringIfValid("preferred_locale", PreferredLocale);

            xmlWriter.WriteIfCollectionHasAny("shipping_addresses", ShippingAddresses);
            xmlWriter.WriteIfCollectionHasAny("custom_fields", CustomFields);

            // Clear the parent account by writing empty string. Null should not clear parent.
            if (ParentAccountCode != null)
            {
                xmlWriter.WriteElementString("parent_account_code", ParentAccountCode);
            }

            if (TaxExempt.HasValue)
            {
                xmlWriter.WriteElementString("tax_exempt", TaxExempt.Value.AsString());
            }

            xmlWriter.WriteStringIfValid("exemption_certificate", ExemptionCertificate);

            if (_accountAcquisition != null)
            {
                _accountAcquisition.WriteXml(xmlWriter);
            }

            if (_billingInfo != null)
            {
                _billingInfo.WriteXml(xmlWriter);
            }

            if (Address != null)
            {
                Address.WriteXml(xmlWriter);
            }

            xmlWriter.WriteEndElement(); // End: account
        }
Ejemplo n.º 5
0
        protected void WriteChangeSubscriptionXml(XmlTextWriter xmlWriter, ChangeTimeframe timeframe)
        {
            xmlWriter.WriteStartElement("subscription"); // Start: subscription

            xmlWriter.WriteElementString("timeframe", timeframe.ToString().EnumNameToTransportCase());
            xmlWriter.WriteElementString("quantity", Quantity.AsString());
            xmlWriter.WriteStringIfValid("plan_code", _planCode);
            xmlWriter.WriteIfCollectionHasAny("subscription_add_ons", AddOns);
            xmlWriter.WriteStringIfValid("coupon_code", _couponCode);

            if (UnitAmountInCents.HasValue)
            {
                xmlWriter.WriteElementString("unit_amount_in_cents", UnitAmountInCents.Value.AsString());
            }

            if (CollectionMethod.Like("manual"))
            {
                xmlWriter.WriteElementString("collection_method", "manual");
                xmlWriter.WriteElementString("net_terms", NetTerms.Value.AsString());
                xmlWriter.WriteElementString("po_number", PoNumber);
            }
            else if (CollectionMethod.Like("automatic"))
            {
                xmlWriter.WriteElementString("collection_method", "automatic");
            }

            xmlWriter.WriteEndElement(); // End: subscription
        }
Ejemplo n.º 6
0
        internal override void WriteXml(XmlTextWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("account"); // Start: account

            xmlWriter.WriteElementString("account_code", AccountCode);
            xmlWriter.WriteStringIfValid("username", Username);
            xmlWriter.WriteStringIfValid("email", Email);
            xmlWriter.WriteStringIfValid("first_name", FirstName);
            xmlWriter.WriteStringIfValid("last_name", LastName);
            xmlWriter.WriteStringIfValid("company_name", CompanyName);
            xmlWriter.WriteStringIfValid("accept_language", AcceptLanguage);
            xmlWriter.WriteStringIfValid("vat_number", VatNumber);
            xmlWriter.WriteStringIfValid("entity_use_code", EntityUseCode);
            xmlWriter.WriteStringIfValid("cc_emails", CcEmails);

            xmlWriter.WriteIfCollectionHasAny("shipping_addresses", ShippingAddresses);

            if (TaxExempt.HasValue)
            {
                xmlWriter.WriteElementString("tax_exempt", TaxExempt.Value.AsString());
            }

            if (_billingInfo != null)
            {
                _billingInfo.WriteXml(xmlWriter);
            }

            if (Address != null)
            {
                Address.WriteXml(xmlWriter);
            }

            xmlWriter.WriteEndElement(); // End: account
        }
Ejemplo n.º 7
0
        protected void WriteSubscriptionXml(XmlTextWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("subscription"); // Start: subscription

            xmlWriter.WriteElementString("plan_code", _planCode);

            xmlWriter.WriteElementString("currency", Currency);

            xmlWriter.WriteIfCollectionHasAny("subscription_add_ons", AddOns);

            xmlWriter.WriteStringIfValid("coupon_code", _couponCode);

            if (UnitAmountInCents.HasValue)
            {
                xmlWriter.WriteElementString("unit_amount_in_cents", UnitAmountInCents.Value.AsString());
            }

            xmlWriter.WriteElementString("quantity", Quantity.AsString());

            if (TrialPeriodEndsAt.HasValue)
            {
                xmlWriter.WriteElementString("trial_ends_at", TrialPeriodEndsAt.Value.ToString("s"));
            }

            if (StartsAt.HasValue)
            {
                xmlWriter.WriteElementString("starts_at", StartsAt.Value.ToString("s"));
            }

            if (TotalBillingCycles.HasValue)
            {
                xmlWriter.WriteElementString("total_billing_cycles", TotalBillingCycles.Value.AsString());
            }

            if (FirstRenewalDate.HasValue)
            {
                xmlWriter.WriteElementString("first_renewal_date", FirstRenewalDate.Value.ToString("s"));
            }

            if (CollectionMethod.Like("manual"))
            {
                xmlWriter.WriteElementString("collection_method", "manual");
                xmlWriter.WriteElementString("net_terms", NetTerms.Value.AsString());
                xmlWriter.WriteElementString("po_number", PoNumber);
            }
            else if (CollectionMethod.Like("automatic"))
            {
                xmlWriter.WriteElementString("collection_method", "automatic");
            }

            // <account> and billing info
            Account.WriteXml(xmlWriter);

            xmlWriter.WriteEndElement(); // End: subscription
        }
Ejemplo n.º 8
0
        internal override void WriteXml(XmlTextWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("add_on");

            xmlWriter.WriteElementString("add_on_code", AddOnCode);
            xmlWriter.WriteElementString("name", Name);

            xmlWriter.WriteIfCollectionHasAny("unit_amount_in_cents", UnitAmountInCents, pair => pair.Key,
                                              pair => pair.Value.AsString());

            xmlWriter.WriteEndElement();
        }
Ejemplo n.º 9
0
        internal override void WriteXml(XmlTextWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("add_on");

            xmlWriter.WriteElementString("add_on_code", AddOnCode);
            xmlWriter.WriteElementString("name", Name);
            xmlWriter.WriteElementString("accounting_code", AccountingCode);

            if (DefaultQuantity.HasValue)
            {
                xmlWriter.WriteElementString("default_quantity", DefaultQuantity.Value.AsString());
            }

            if (AddOnType.HasValue)
            {
                xmlWriter.WriteElementString("add_on_type", AddOnType.Value.ToString().EnumNameToTransportCase());
            }

            if (UsageType.HasValue)
            {
                xmlWriter.WriteElementString("usage_type", UsageType.Value.ToString().EnumNameToTransportCase());
            }

            if (MeasuredUnitId.HasValue)
            {
                xmlWriter.WriteElementString("measured_unit_id", MeasuredUnitId.ToString());
            }

            if (DisplayQuantityOnHostedPage.HasValue)
            {
                xmlWriter.WriteElementString("display_quantity_on_hosted_page", DisplayQuantityOnHostedPage.Value.AsString());
            }

            if (Optional.HasValue)
            {
                xmlWriter.WriteElementString("optional", Optional.Value.AsString());
            }

            xmlWriter.WriteIfCollectionHasAny("unit_amount_in_cents", UnitAmountInCents, pair => pair.Key,
                                              pair => pair.Value.AsString());

            if (RevenueScheduleType.HasValue)
            {
                xmlWriter.WriteElementString("revenue_schedule_type", RevenueScheduleType.Value.ToString().EnumNameToTransportCase());
            }

            xmlWriter.WriteEndElement();
        }
Ejemplo n.º 10
0
        public void WriteIfCollectionHasAny_renders_key_value_pair_collections_correctly()
        {
            var units = new Dictionary <string, int>
            {
                { "USD", 1000 },
                { "EUR", 800 }
            };

            var stringWriter = new StringWriter();
            var xmlWriter    = new XmlTextWriter(stringWriter);

            xmlWriter.WriteIfCollectionHasAny("unit_amount_in_cents", units, pair => pair.Key, pair => pair.Value.AsString());
            xmlWriter.Flush();
            xmlWriter.Close();

            stringWriter.ToString().Should().Be(ValidKeyValueXml);
        }
Ejemplo n.º 11
0
        public void WriteIfCollectionHasAny_renders_static_names_correctly()
        {
            var list = new List <string>
            {
                "plan1",
                "plan2"
            };

            var stringWriter = new StringWriter();
            var xmlWriter    = new XmlTextWriter(stringWriter);

            xmlWriter.WriteIfCollectionHasAny("plan_codes", list, s => "plan_code", s => s);
            xmlWriter.Flush();
            xmlWriter.Close();

            var actual = stringWriter.ToString();

            actual.Should().Be(StaticNamesXml);
        }
Ejemplo n.º 12
0
        public void WriteIfCollectionHasAny_renders_RecurlyEntity_lists_correctly()
        {
            var list = new List <SubscriptionAddOn>
            {
                new SubscriptionAddOn("addon1", 100),
                new SubscriptionAddOn("addon2", 200, 2)
            };

            var stringWriter = new StringWriter();
            var xmlWriter    = new XmlTextWriter(stringWriter);

            xmlWriter.WriteIfCollectionHasAny("subscription_add_ons", list);
            xmlWriter.Flush();
            xmlWriter.Close();

            var actual = stringWriter.ToString();

            actual.Should().Be(ValidEntityXml);
        }
        protected void WriteSubscriptionXml(XmlTextWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("subscription"); // Start: subscription

            xmlWriter.WriteElementString("plan_code", PlanCode);

            xmlWriter.WriteElementString("currency", Currency);

            xmlWriter.WriteIfCollectionHasAny("subscription_add_ons", AddOns);

            xmlWriter.WriteStringIfValid("coupon_code", _couponCode);

            if (_couponCodes != null && _couponCodes.Length != 0)
            {
                xmlWriter.WriteStartElement("coupon_codes");
                foreach (var _coupon_code in _couponCodes)
                {
                    xmlWriter.WriteElementString("coupon_code", _coupon_code);
                }
                xmlWriter.WriteEndElement();
            }

            xmlWriter.WriteElementString("customer_notes", CustomerNotes);
            xmlWriter.WriteElementString("terms_and_conditions", TermsAndConditions);
            xmlWriter.WriteElementString("vat_reverse_charge_notes", VatReverseChargeNotes);

            if (UnitAmountInCents.HasValue)
            {
                xmlWriter.WriteElementString("unit_amount_in_cents", UnitAmountInCents.Value.AsString());
            }

            xmlWriter.WriteElementString("quantity", Quantity.AsString());

            if (TrialPeriodEndsAt.HasValue)
            {
                xmlWriter.WriteElementString("trial_ends_at", TrialPeriodEndsAt.Value.ToString("s"));
            }

            if (BankAccountAuthorizedAt.HasValue)
            {
                xmlWriter.WriteElementString("bank_account_authorized_at", BankAccountAuthorizedAt.Value.ToString("s"));
            }

            if (StartsAt.HasValue)
            {
                xmlWriter.WriteElementString("starts_at", StartsAt.Value.ToString("s"));
            }

            if (TotalBillingCycles.HasValue)
            {
                xmlWriter.WriteElementString("total_billing_cycles", TotalBillingCycles.Value.AsString());
            }

            if (FirstRenewalDate.HasValue)
            {
                xmlWriter.WriteElementString("first_renewal_date", FirstRenewalDate.Value.ToString("s"));
            }

            if (Bulk.HasValue)
            {
                xmlWriter.WriteElementString("bulk", Bulk.ToString().ToLower());
            }

            if (CollectionMethod.Like("manual"))
            {
                xmlWriter.WriteElementString("collection_method", "manual");
                xmlWriter.WriteElementString("net_terms", NetTerms.Value.AsString());
                xmlWriter.WriteElementString("po_number", PoNumber);
            }
            else if (CollectionMethod.Like("automatic"))
            {
                xmlWriter.WriteElementString("collection_method", "automatic");
            }

            // <account> and billing info
            Account.WriteXml(xmlWriter);

            xmlWriter.WriteEndElement(); // End: subscription
        }
Ejemplo n.º 14
0
        internal override void WriteXml(XmlTextWriter xmlWriter)
        {
            xmlWriter.WriteStartElement("coupon"); // Start: coupon

            xmlWriter.WriteElementString("coupon_code", CouponCode);
            xmlWriter.WriteElementString("name", Name);
            xmlWriter.WriteElementString("hosted_description", HostedDescription);
            xmlWriter.WriteElementString("invoice_description", InvoiceDescription);

            if (RedeemByDate.HasValue)
            {
                xmlWriter.WriteElementString("redeem_by_date", RedeemByDate.Value.ToString("s"));
            }

            if (SingleUse.HasValue)
            {
                xmlWriter.WriteElementString("single_use", SingleUse.Value.AsString());
            }

            if (AppliesForMonths.HasValue)
            {
                xmlWriter.WriteElementString("applies_for_months", AppliesForMonths.Value.AsString());
            }
            if (Duration != null)
            {
                xmlWriter.WriteElementString("duration", Duration.ToString().EnumNameToTransportCase());
            }
            if (TemporalUnit != null)
            {
                xmlWriter.WriteElementString("temporal_unit", TemporalUnit.ToString().EnumNameToTransportCase());
            }
            if (TemporalAmount.HasValue)
            {
                xmlWriter.WriteElementString("temporal_amount", TemporalAmount.Value.ToString());
            }

            if (AppliesToAllPlans.HasValue)
            {
                xmlWriter.WriteElementString("applies_to_all_plans", AppliesToAllPlans.Value.AsString());
            }

            if (AppliesToNonPlanCharges.HasValue)
            {
                xmlWriter.WriteElementString("applies_to_non_plan_charges", AppliesToNonPlanCharges.Value.AsString());
            }

            if (MaxRedemptions.HasValue)
            {
                xmlWriter.WriteElementString("max_redemptions", MaxRedemptions.Value.AsString());
            }

            if (MaxRedemptionsPerAccount.HasValue)
            {
                xmlWriter.WriteElementString("max_redemptions_per_account", MaxRedemptionsPerAccount.Value.AsString());
            }

            xmlWriter.WriteElementString("discount_type", DiscountType.ToString().EnumNameToTransportCase());

            xmlWriter.WriteElementString("redemption_resource", RedemptionResource.ToString().EnumNameToTransportCase());

            xmlWriter.WriteElementString("coupon_type", Type.ToString().EnumNameToTransportCase());

            if (Type == CouponType.Bulk)
            {
                xmlWriter.WriteElementString("unique_code_template", UniqueCodeTemplate);
            }

            if (CouponDiscountType.Percent == DiscountType && DiscountPercent.HasValue)
            {
                xmlWriter.WriteElementString("discount_percent", DiscountPercent.Value.AsString());
            }

            if (CouponDiscountType.Dollars == DiscountType)
            {
                xmlWriter.WriteIfCollectionHasAny("discount_in_cents", DiscountInCents, pair => pair.Key,
                                                  pair => pair.Value.AsString());
            }

            xmlWriter.WriteIfCollectionHasAny("plan_codes", Plans, s => "plan_code", s => s);

            if (FreeTrialAmount.HasValue)
            {
                xmlWriter.WriteElementString("free_trial_amount", FreeTrialAmount.Value.AsString());
            }

            if (FreeTrialUnit.HasValue)
            {
                xmlWriter.WriteElementString("free_trial_unit", FreeTrialUnit.Value.ToString().EnumNameToTransportCase());
            }

            xmlWriter.WriteEndElement(); // End: coupon
        }
Ejemplo n.º 15
0
        internal void WriteSubscriptionXml(XmlTextWriter xmlWriter, bool embedded)
        {
            xmlWriter.WriteStartElement("subscription"); // Start: subscription

            xmlWriter.WriteElementString("plan_code", PlanCode);

            if (!embedded)
            {
                // <account> and billing info
                Account.WriteXml(xmlWriter);
                xmlWriter.WriteElementString("currency", Currency);
                xmlWriter.WriteElementString("customer_notes", CustomerNotes);
                xmlWriter.WriteElementString("terms_and_conditions", TermsAndConditions);
                xmlWriter.WriteElementString("vat_reverse_charge_notes", VatReverseChargeNotes);
                xmlWriter.WriteElementString("po_number", PoNumber);
            }

            xmlWriter.WriteIfCollectionHasAny("subscription_add_ons", AddOns);

            xmlWriter.WriteStringIfValid("coupon_code", _couponCode);

            if (_couponCodes != null && _couponCodes.Length != 0)
            {
                xmlWriter.WriteStartElement("coupon_codes");
                foreach (var _coupon_code in _couponCodes)
                {
                    xmlWriter.WriteElementString("coupon_code", _coupon_code);
                }
                xmlWriter.WriteEndElement();
            }

            if (UnitAmountInCents.HasValue)
            {
                xmlWriter.WriteElementString("unit_amount_in_cents", UnitAmountInCents.Value.AsString());
            }

            xmlWriter.WriteElementString("quantity", Quantity.AsString());

            if (TrialPeriodEndsAt.HasValue)
            {
                xmlWriter.WriteElementString("trial_ends_at", TrialPeriodEndsAt.Value.ToString("s"));
            }

            if (BankAccountAuthorizedAt.HasValue)
            {
                xmlWriter.WriteElementString("bank_account_authorized_at", BankAccountAuthorizedAt.Value.ToString("s"));
            }

            if (StartsAt.HasValue)
            {
                xmlWriter.WriteElementString("starts_at", StartsAt.Value.ToString("s"));
            }

            if (TotalBillingCycles.HasValue)
            {
                xmlWriter.WriteElementString("total_billing_cycles", TotalBillingCycles.Value.AsString());
            }

            if (FirstRenewalDate.HasValue)
            {
                xmlWriter.WriteElementString("first_renewal_date", FirstRenewalDate.Value.ToString("s"));
            }

            if (Bulk.HasValue)
            {
                xmlWriter.WriteElementString("bulk", Bulk.ToString().ToLower());
            }

            if (CollectionMethod.Like("manual"))
            {
                xmlWriter.WriteElementString("collection_method", "manual");

                if (NetTerms.HasValue)
                {
                    xmlWriter.WriteElementString("net_terms", NetTerms.Value.AsString());
                }
            }
            else if (CollectionMethod.Like("automatic"))
            {
                xmlWriter.WriteElementString("collection_method", "automatic");
            }

            if (ShippingAddressId.HasValue)
            {
                xmlWriter.WriteElementString("shipping_address_id", ShippingAddressId.Value.ToString());
            }

            if (ImportedTrial.HasValue)
            {
                xmlWriter.WriteElementString("imported_trial", ImportedTrial.Value.ToString().ToLower());
            }

            if (RevenueScheduleType.HasValue)
            {
                xmlWriter.WriteElementString("revenue_schedule_type", RevenueScheduleType.Value.ToString().EnumNameToTransportCase());
            }

            if (RemainingBillingCycles.HasValue)
            {
                xmlWriter.WriteElementString("remaining_billing_cycles", RemainingBillingCycles.Value.AsString());
            }

            if (AutoRenew.HasValue)
            {
                xmlWriter.WriteElementString("auto_renew", AutoRenew.Value.AsString());
            }

            if (RenewalBillingCycles.HasValue)
            {
                xmlWriter.WriteElementString("renewal_billing_cycles", RenewalBillingCycles.Value.AsString());
            }

            xmlWriter.WriteIfCollectionHasAny("custom_fields", CustomFields);

            if (!ShippingMethodCode.IsNullOrEmpty())
            {
                xmlWriter.WriteElementString("shipping_method_code", ShippingMethodCode);
            }

            if (ShippingAmountInCents.HasValue)
            {
                xmlWriter.WriteElementString("shipping_amount_in_cents", ShippingAmountInCents.Value.AsString());
            }

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