Skip to content

Commit

Permalink
proration_settings
Browse files Browse the repository at this point in the history
  • Loading branch information
smagdicatrecurly committed May 3, 2024
1 parent 21e5fdc commit 81d9660
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Library/ProrationSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;

namespace Recurly
{
public class ProrationSettings
{
public enum Options
{
ProratedAmount,
FullAmount,
None
}

/// <summary>
/// Proration behavior to be applied to charges for the subscription change.
/// Can be set to FullAmount, ProratedAmount, or None.
/// When not set, default proration settings will be applied.
/// </summary>
public Options? Charge { get; set; }

/// <summary>
/// Proration behavior to be applied to credits for the subscription change.
/// Can be set to FullAmount, ProratedAmount, or None.
/// When not set, default proration settings will be applied.
/// </summary>
public Options? Credit { get; set; }
}
}
20 changes: 20 additions & 0 deletions Library/SubscriptionChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public enum ChangeTimeframe : short

public string PlanCode { get; set; }

/// <summary>
/// Proration settings to be applied to the subscription change.
/// If not set, the default proration behavior will apply.
/// </summary>
public ProrationSettings ProrationSettings { get; set; }

/// <summary>
/// List of custom fields
/// </summary>
Expand Down Expand Up @@ -127,6 +133,20 @@ internal void WriteChangeSubscriptionXml(XmlTextWriter xmlWriter)

xmlWriter.WriteStringIfValid("plan_code", PlanCode);

if (ProrationSettings != null)
{
xmlWriter.WriteStartElement("proration_settings");

if (ProrationSettings.Charge != null)
xmlWriter.WriteElementString("charge", ProrationSettings.Charge.Value.ToString().EnumNameToTransportCase());

if (ProrationSettings.Credit != null)
xmlWriter.WriteElementString("credit", ProrationSettings.Credit.Value.ToString().EnumNameToTransportCase());

xmlWriter.WriteEndElement();
}


if (AddOns != null)
xmlWriter.WriteIfCollectionHasAny("subscription_add_ons", AddOns);

Expand Down
45 changes: 45 additions & 0 deletions Test/SubscriptionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,51 @@ public void UpdateSubscription()
Assert.Equal(newSubscription.NetTermsType, NetTermsType.NET);
}

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

var plan2 = new Plan(GetMockPlanCode(), GetMockPlanName())
{
Description = "Update Subscription Plan 2"
};
plan2.UnitAmountInCents.Add("USD", 750);
plan2.Create();
PlansToDeactivateOnDispose.Add(plan2);

var account = CreateNewAccountWithBillingInfo();

var sub = new Subscription(account, plan, "USD");
sub.Create();

var subChange = new SubscriptionChange()
{
PlanCode = plan2.PlanCode,
BillingInfoUuid = account.GetBillingInfos()[0].Id,
NetTerms = 10,
NetTermsType = NetTermsType.NET,
ProrationSettings = new ProrationSettings()
{
Charge = ProrationSettings.Options.FullAmount,
Credit = ProrationSettings.Options.None
}
};

Assert.Equal(subChange.ProrationSettings.Charge, ProrationSettings.Options.FullAmount);
Assert.Equal(subChange.ProrationSettings.Credit, ProrationSettings.Options.None);

Subscription.ChangeSubscription(sub.Uuid, subChange);

var newSubscription = Subscriptions.Get(sub.Uuid);
}

[RecurlyFact(TestEnvironment.Type.Integration)]
public void CancelSubscription()
{
Expand Down

0 comments on commit 81d9660

Please sign in to comment.