From 3a041aadb6ea06b904bf9d8c000f6f58649d49f4 Mon Sep 17 00:00:00 2001 From: Chris Smola Date: Tue, 20 Feb 2024 13:40:29 -0500 Subject: [PATCH] adds revrec settings to adjustments --- Library/Adjustment.cs | 18 +++++++++- Library/RevRecEntity.cs | 8 ++++- Test/AdjustmentTest.cs | 33 ++++++++++++++++++- Test/Fixtures/FixtureImporter.cs | 2 ++ Test/Fixtures/adjustments/revrec.show-200.xml | 29 ++++++++++++++++ Test/Recurly.Test.csproj | 3 ++ 6 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 Test/Fixtures/adjustments/revrec.show-200.xml diff --git a/Library/Adjustment.cs b/Library/Adjustment.cs index 08dd6947..fa63a954 100644 --- a/Library/Adjustment.cs +++ b/Library/Adjustment.cs @@ -7,7 +7,7 @@ namespace Recurly /// /// Represents adjustments - credits and charges - on accounts. /// - public class Adjustment : RecurlyEntity + public class Adjustment : RevRecEntity { // The currently valid adjustment types public enum AdjustmentType : short @@ -39,6 +39,8 @@ public enum RevenueSchedule : short public string Uuid { get; protected set; } public string Description { get; set; } public string AccountingCode { get; set; } + public string LiabilityGlAccountCode { get; private set; } + public string RevenueGlAccountCode { get; private set; } public string ProductCode { get; set; } public string ItemCode { get; set; } public string ExternalSku { get; set; } @@ -171,6 +173,9 @@ internal override void ReadXml(XmlTextReader reader) break; if (reader.NodeType != XmlNodeType.Element) continue; + + ReadRevRecPobNode(reader); + switch (reader.Name) { case "account": @@ -195,6 +200,14 @@ internal override void ReadXml(XmlTextReader reader) AccountingCode = reader.ReadElementContentAsString(); break; + case "liability_gl_account_code": + LiabilityGlAccountCode = reader.ReadElementContentAsString(); + break; + + case "revenue_gl_account_code": + RevenueGlAccountCode = reader.ReadElementContentAsString(); + break; + case "product_code": ProductCode = reader.ReadElementContentAsString(); break; @@ -372,6 +385,9 @@ internal void WriteXml(XmlTextWriter xmlWriter, bool embedded = false) xmlWriter.WriteElementString("currency", Currency); if (RevenueScheduleType.HasValue) xmlWriter.WriteElementString("revenue_schedule_type", RevenueScheduleType.Value.ToString().EnumNameToTransportCase()); + + WriteRevRecNodes(xmlWriter); + if (TaxCode != null) xmlWriter.WriteElementString("tax_code", TaxCode); if (StartDate != DateTime.MinValue) diff --git a/Library/RevRecEntity.cs b/Library/RevRecEntity.cs index 71a881a1..66524293 100644 --- a/Library/RevRecEntity.cs +++ b/Library/RevRecEntity.cs @@ -21,11 +21,17 @@ internal protected void ReadRevRecNode(XmlTextReader reader) break; case "performance_obligation_id": - PerformanceObligationId = reader.ReadElementContentAsString(); + ReadRevRecPobNode(reader); break; }; } + internal protected void ReadRevRecPobNode(XmlTextReader reader) + { + if (reader.Name == "performance_obligation_id") + PerformanceObligationId = reader.ReadElementContentAsString(); + } + internal protected void WriteRevRecNodes(XmlTextWriter writer) { writer.WriteValidStringOrNil("liability_gl_account_id", LiabilityGlAccountId); diff --git a/Test/AdjustmentTest.cs b/Test/AdjustmentTest.cs index 6fd3b079..fe0f1e71 100644 --- a/Test/AdjustmentTest.cs +++ b/Test/AdjustmentTest.cs @@ -1,6 +1,8 @@ using System; using System.Linq; +using System.Xml; using FluentAssertions; +using Recurly.Test.Fixtures; using Xunit; namespace Recurly.Test @@ -124,7 +126,7 @@ public void GetAdjustmentWithCustomFieldsByUuid() } /// - /// This test will return two adjustments: one to negate the charge, the + /// This test will return two adjustments: one to negate the charge, the /// other for the balance /// [RecurlyFact(TestEnvironment.Type.Integration)] @@ -244,5 +246,34 @@ public void AdjustmentBillForAccountCode() Assert.Equal(account.AccountCode, fromService.BillForAccountCode); } + + public void CheckForRevRecData() + { + var adjustment = new Adjustment(); + + var xmlFixture = FixtureImporter.Get(FixtureType.Adjustments, "revrec.show-200").Xml; + XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(xmlFixture)); + adjustment.ReadXml(reader); + + adjustment.LiabilityGlAccountCode.Should().Be("100"); + adjustment.RevenueGlAccountCode.Should().Be("200"); + adjustment.PerformanceObligationId.Should().Be("7pu"); + } + + [RecurlyFact(TestEnvironment.Type.Unit)] + public void CheckForRevRecDataOut() + { + var adjustment = new Adjustment(); + + adjustment.LiabilityGlAccountId = "suaz415ebc94"; + adjustment.RevenueGlAccountId = "sxo2b1hpjrye"; + adjustment.PerformanceObligationId = "7pu"; + + var xml = XmlToString(adjustment.WriteXml); + + xml.Should().Contain("suaz415ebc94"); + xml.Should().Contain("sxo2b1hpjrye"); + xml.Should().Contain("7pu"); + } } } diff --git a/Test/Fixtures/FixtureImporter.cs b/Test/Fixtures/FixtureImporter.cs index 19bb4832..07f9ad64 100644 --- a/Test/Fixtures/FixtureImporter.cs +++ b/Test/Fixtures/FixtureImporter.cs @@ -80,6 +80,8 @@ public enum FixtureType Accounts, [Description("addons")] AddOns, + [Description("adjustments")] + Adjustments, [Description("business_entities")] BusinessEntities, [Description("external_payment_phases")] diff --git a/Test/Fixtures/adjustments/revrec.show-200.xml b/Test/Fixtures/adjustments/revrec.show-200.xml new file mode 100644 index 00000000..e6beac93 --- /dev/null +++ b/Test/Fixtures/adjustments/revrec.show-200.xml @@ -0,0 +1,29 @@ +HTTP/1.1 200 OK +Content-Type: application/xml; charset=utf-8 + + + + + + + abcdef1234567890 + invoiced + $12 Annual Subscription + + + 100 + 200 + 7pu + + plan + 1200 + 1 + 0 + 0 + 1200 + USD + false + 2011-04-30T07:00:00Z + 2011-04-30T07:00:00Z + 2011-08-31T03:30:00Z + diff --git a/Test/Recurly.Test.csproj b/Test/Recurly.Test.csproj index 4f3783e6..ed5d1146 100644 --- a/Test/Recurly.Test.csproj +++ b/Test/Recurly.Test.csproj @@ -128,6 +128,9 @@ Always + + Always + Always