Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V2] Add RevRec Settings to Adjustments #822

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion Library/Adjustment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Recurly
/// <summary>
/// Represents adjustments - credits and charges - on accounts.
/// </summary>
public class Adjustment : RecurlyEntity
public class Adjustment : RevRecEntity
{
// The currently valid adjustment types
public enum AdjustmentType : short
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -171,6 +173,9 @@ internal override void ReadXml(XmlTextReader reader)
break;

if (reader.NodeType != XmlNodeType.Element) continue;

ReadRevRecPobNode(reader);

switch (reader.Name)
{
case "account":
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion Library/RevRecEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
33 changes: 32 additions & 1 deletion Test/AdjustmentTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Linq;
using System.Xml;
using FluentAssertions;
using Recurly.Test.Fixtures;
using Xunit;

namespace Recurly.Test
Expand Down Expand Up @@ -124,7 +126,7 @@ public void GetAdjustmentWithCustomFieldsByUuid()
}

/// <summary>
/// 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
/// </summary>
[RecurlyFact(TestEnvironment.Type.Integration)]
Expand Down Expand Up @@ -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("<liability_gl_account_id>suaz415ebc94</liability_gl_account_id>");
xml.Should().Contain("<revenue_gl_account_id>sxo2b1hpjrye</revenue_gl_account_id>");
xml.Should().Contain("<performance_obligation_id>7pu</performance_obligation_id>");
}
}
}
2 changes: 2 additions & 0 deletions Test/Fixtures/FixtureImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public enum FixtureType
Accounts,
[Description("addons")]
AddOns,
[Description("adjustments")]
Adjustments,
[Description("business_entities")]
BusinessEntities,
[Description("external_payment_phases")]
Expand Down
29 changes: 29 additions & 0 deletions Test/Fixtures/adjustments/revrec.show-200.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8

<?xml version="1.0" encoding="UTF-8"?>
<adjustment href="https://api.recurly.com/v2/adjustments/abcdef1234567890" type="charge">
<account href="https://api.recurly.com/v2/accounts/account"/>
<invoice href="https://api.recurly.com/v2/invoices/1234"/>
<subscription href="https://api.recurly.com/v2/subscriptions/1234567890abcdef"/>
<uuid>abcdef1234567890</uuid>
<state>invoiced</state>
<description>$12 Annual Subscription</description>
<item_code></item_code>
<accounting_code></accounting_code>
<liability_gl_account_code>100</liability_gl_account_code>
<revenue_gl_account_code>200</revenue_gl_account_code>
<performance_obligation_id>7pu</performance_obligation_id>
<product_code nil="nil"></product_code>
<origin>plan</origin>
<unit_amount_in_cents type="integer">1200</unit_amount_in_cents>
<quantity type="integer">1</quantity>
<discount_in_cents type="integer">0</discount_in_cents>
<tax_in_cents type="integer">0</tax_in_cents>
<total_in_cents type="integer">1200</total_in_cents>
<currency>USD</currency>
<taxable type="boolean">false</taxable>
<start_date type="datetime">2011-04-30T07:00:00Z</start_date>
<end_date type="datetime">2011-04-30T07:00:00Z</end_date>
<created_at type="datetime">2011-08-31T03:30:00Z</created_at>
</adjustment>
3 changes: 3 additions & 0 deletions Test/Recurly.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@
<Content Include="Fixtures\adjustments\show-200.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Fixtures\adjustments\revrec.show-200.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Fixtures\adjustments\show-404.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down
Loading