Skip to content

Commit

Permalink
Merge pull request #828 from recurly/add-net-terms-type-to-dotnet
Browse files Browse the repository at this point in the history
add net_terms_type to invoice, purchase, and subscription
  • Loading branch information
btruncali1 authored Apr 4, 2024
2 parents 6ecdd84 + 2f3f4e3 commit c08c8af
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 6 deletions.
22 changes: 19 additions & 3 deletions Library/Invoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public class RefundOptions
public int TaxInCents { get; protected set; }
public int TotalInCents { get; protected set; }
public string Currency { get; protected set; }

/// <summary>
/// The net terms for the invoice.
/// If net terms type is 'eom', NetTerms must be one of 0, 15, 30, 45, 60, or 90
/// </summary>
public int? NetTerms
{
get { return _netTerms; }
Expand All @@ -98,6 +103,10 @@ public int? NetTerms
private int? _netTerms;
private bool _netTermsChanged = false;

/// <summary>
/// The net terms type for the invoice. Can be a 'net' or 'eom'
/// </summary>
public NetTermsType? NetTermsType { get; set; }
public Collection CollectionMethod { get; set; }
public DateTime? CreatedAt { get; private set; }
public DateTime? UpdatedAt { get; private set; }
Expand Down Expand Up @@ -641,6 +650,10 @@ internal void ReadXml(XmlTextReader reader, string nodeName)
}
break;

case "net_terms_type":
NetTermsType = reader.ReadElementContentAsString().ParseAsEnum<NetTermsType>();
break;

case "collection_method":
var method = reader.ReadElementContentAsString();
if (!method.IsNullOrEmpty())
Expand Down Expand Up @@ -761,15 +774,18 @@ internal override void WriteXml(XmlTextWriter xmlWriter)
if (CollectionMethod == Collection.Manual)
{
xmlWriter.WriteElementString("collection_method", "manual");

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

if (NetTerms.HasValue)
xmlWriter.WriteElementString("net_terms", NetTerms.Value.AsString());

if (NetTermsType.HasValue)
xmlWriter.WriteElementString("net_terms_type", NetTermsType.ToString().EnumNameToTransportCase());

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

Expand Down
19 changes: 19 additions & 0 deletions Library/NetTermsType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Runtime.Serialization;
namespace Recurly
{
/// <summary>
/// Optionally supplied string that may be either net or eom(end-of-month).
/// When 'net', an invoice becomes past due the specified number of net_terms
/// days from the current date. When 'eom' an invoice becomes past due the
/// specified number of net_terms days from the last day of the current month.
/// If NetTermsType is 'eom' then NetTerms must be one of 0, 15, 30, 45, 60, or 90
/// </summary>
public enum NetTermsType
{
[EnumMember(Value = "net")]
NET,

[EnumMember(Value = "eom")]
EOM,
}
}
9 changes: 9 additions & 0 deletions Library/Purchase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ public class Purchase : RecurlyEntity

/// <summary>
/// The net terms for the invoice.
/// If net terms type is 'eom', NetTerms must be one of 0, 15, 30, 45, 60, or 90
/// </summary>
public int? NetTerms { get; set; }

/// <summary>
/// The net terms type for the invoice. Can be a 'net' or 'eom'
/// </summary>
public NetTermsType? NetTermsType { get; set; }

/// <summary>
/// A gift card redemption code to apply to this purchase.
/// </summary>
Expand Down Expand Up @@ -278,6 +284,9 @@ internal override void WriteXml(XmlTextWriter xmlWriter)
if (NetTerms.HasValue)
xmlWriter.WriteElementString("net_terms", NetTerms.Value.ToString());

if (NetTermsType.HasValue)
xmlWriter.WriteElementString("net_terms_type", NetTermsType.ToString().EnumNameToTransportCase());

if (PoNumber != null)
xmlWriter.WriteElementString("po_number", PoNumber);

Expand Down
21 changes: 19 additions & 2 deletions Library/Subscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,16 @@ public SubscriptionAddOnList AddOns
internal const string UrlPrefix = "/subscriptions/";

public string CollectionMethod { get; set; }
/// <summary>
/// The net terms for the subscription.
/// If net terms type is 'eom', NetTerms must be one of 0, 15, 30, 45, 60, or 90
/// </summary>
public int? NetTerms { get; set; }

/// <summary>
/// The net terms type for the subscription. Can be a 'net' or 'eom'
/// </summary>
public NetTermsType? NetTermsType { get; set; }
public string PoNumber { get; set; }

/// <summary>
Expand Down Expand Up @@ -862,6 +871,10 @@ internal override void ReadXml(XmlTextReader reader)
NetTerms = reader.ReadElementContentAsInt();
break;

case "net_terms_type":
NetTermsType = reader.ReadElementContentAsString().ParseAsEnum<NetTermsType>();
break;

case "po_number":
PoNumber = reader.ReadElementContentAsString();
break;
Expand Down Expand Up @@ -1102,12 +1115,16 @@ internal void WriteSubscriptionXml(XmlTextWriter xmlWriter, bool embedded)
{
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 (NetTerms.HasValue)
xmlWriter.WriteElementString("net_terms", NetTerms.Value.AsString());

if (NetTermsType.HasValue)
xmlWriter.WriteElementString("net_terms_type", NetTermsType.ToString().EnumNameToTransportCase());

if (ShippingAddressId.HasValue)
{
xmlWriter.WriteElementString("shipping_address_id", ShippingAddressId.Value.ToString());
Expand Down
12 changes: 12 additions & 0 deletions Library/SubscriptionChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,17 @@ public List<CustomField> CustomFields

public string CollectionMethod { get; set; }

/// <summary>
/// The net terms for the subscription.
/// If net terms type is 'eom', NetTerms must be one of 0, 15, 30, 45, 60, or 90
/// </summary>
public int? NetTerms { get; set; }

/// <summary>
/// The net terms type for the invoice. Can be a 'net' or 'eom'
/// </summary>
public NetTermsType? NetTermsType { get; set; }

public string PoNumber { get; set; }

/// <summary>
Expand Down Expand Up @@ -131,6 +140,9 @@ internal void WriteChangeSubscriptionXml(XmlTextWriter xmlWriter)
if (NetTerms.HasValue)
xmlWriter.WriteElementString("net_terms", NetTerms.Value.AsString());

if (NetTermsType.HasValue)
xmlWriter.WriteElementString("net_terms_type", NetTermsType.ToString().EnumNameToTransportCase());

if (PoNumber != null)
xmlWriter.WriteElementString("po_number", PoNumber);

Expand Down
21 changes: 21 additions & 0 deletions Test/InvoiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,5 +465,26 @@ public void EnterOfflinePayment()
var recordedTransaction = invoice.EnterOfflinePayment(offlineTransaction);
Assert.Equal(recordedTransaction.Status, Recurly.Transaction.TransactionState.Success);
}

[RecurlyFact(TestEnvironment.Type.Integration)]
public void CreateInvoiceWithEOMNetTerms()
{
var account = CreateNewAccountWithBillingInfo();

var adjustment = account.NewAdjustment("USD", 5000, "Test Charge");
adjustment.Create();

var collection = account.InvoicePendingCharges(new Invoice
{
NetTerms = 45,
NetTermsType = NetTermsType.EOM,
});

var invoice = collection.ChargeInvoice;
var response = Invoices.Get(invoice.InvoiceNumber);

Assert.Equal(response.NetTerms, 45);
Assert.Equal(response.NetTermsType, NetTermsType.EOM);
}
}
}
24 changes: 24 additions & 0 deletions Test/PurchaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,5 +254,29 @@ public void AuthAndCapturePurchaseWithCustomFields()
Assert.Equal(capturedResponse.ChargeInvoice.Adjustments[0].CustomFields[0].Value, "purple");
account.Close();
}

[RecurlyFact(TestEnvironment.Type.Integration)]
public void PurchaseWithEOMNetTerms()
{
var account = CreateNewAccountWithBillingInfo();
var currency = "USD";
var plan = new Plan(GetMockPlanCode(), GetMockPlanName()) { Description = "Plan for Purchase Test" };
plan.UnitAmountInCents.Add("USD", 580);
plan.Create();

var purchase = new Purchase(account.AccountCode, currency);

purchase.Account.BillingInfo = account.BillingInfo;
purchase.NetTerms = 45;
purchase.NetTermsType = NetTermsType.EOM;

var sub = new Subscription(plan.PlanCode);
purchase.Subscriptions.Add(sub);

var response = Purchase.Invoice(purchase);
Assert.NotNull(response.ChargeInvoice);
Assert.Equal(response.ChargeInvoice.NetTerms, 45);
response.ChargeInvoice.NetTermsType.Should().Be(NetTermsType.EOM);
}
}
}
28 changes: 27 additions & 1 deletion Test/SubscriptionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ public void UpdateSubscription()
var subChange = new SubscriptionChange()
{
PlanCode = plan2.PlanCode,
BillingInfoUuid = account.GetBillingInfos()[0].Id
BillingInfoUuid = account.GetBillingInfos()[0].Id,
NetTerms = 10,
NetTermsType = NetTermsType.NET
};

Subscription.ChangeSubscription(sub.Uuid, subChange);
Expand All @@ -299,6 +301,8 @@ public void UpdateSubscription()

newSubscription.PendingSubscription.Should().BeNull();
newSubscription.Plan.Should().Be(plan2);
Assert.Equal(newSubscription.NetTerms, 10);
Assert.Equal(newSubscription.NetTermsType, NetTermsType.NET);
}

[RecurlyFact(TestEnvironment.Type.Integration)]
Expand Down Expand Up @@ -934,5 +938,27 @@ public void PreviewSubscriptionWithRamps()
account.Close();
}
}

[RecurlyFact(TestEnvironment.Type.Integration)]
public void CreateSubscriptionWithEOMNetTerms()
{
var plan = new Plan(GetMockPlanCode(), GetMockPlanName()) { Description = "Lookup Subscription Test" };
plan.UnitAmountInCents.Add("USD", 1500);
plan.Create();
PlansToDeactivateOnDispose.Add(plan);

var account = CreateNewAccountWithBillingInfo();

var sub = new Subscription(account, plan, "USD");
sub.NetTerms = 15;
sub.NetTermsType = NetTermsType.EOM;
sub.Create();

var response = Subscriptions.Get(sub.Uuid);

response.Should().Be(sub);
Assert.Equal(response.NetTerms, 15);
response.NetTermsType.Should().Be(NetTermsType.EOM);
}
}
}

0 comments on commit c08c8af

Please sign in to comment.