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 }
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); xmlWriter.WriteEndElement(); // End: coupon }
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 (_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()); 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 }
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(); }
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 }
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 }
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(); }
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); } // <account> and billing info Account.WriteXml(xmlWriter); xmlWriter.WriteEndElement(); // End: subscription }
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); }
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); }
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); }
internal override void WriteXml(XmlTextWriter xmlWriter) { xmlWriter.WriteStartElement("add_on"); xmlWriter.WriteElementString("add_on_code", AddOnCode); xmlWriter.WriteElementString("name", Name); xmlWriter.WriteElementString("default_quantity", DefaultQuantity.AsString()); xmlWriter.WriteElementString("accounting_code", AccountingCode); 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()); xmlWriter.WriteEndElement(); }