Skip to content

Commit

Permalink
Merge pull request #66 from recurly/open_amount_refund
Browse files Browse the repository at this point in the history
Support open amount refund
  • Loading branch information
cbarton committed Jan 27, 2015
2 parents 07f4201 + f4da20e commit 0a4ef7f
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 1 deletion.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Unreleased
* added; invoice address on previews
* added; `invoice.OriginalInvoiceNumber`
* added; VatLocationValid to Account
* added; Open Amount Refunds to Invoice

1.1.7 (stable) / 2014-12-19
==================
Expand Down
17 changes: 16 additions & 1 deletion Library/Invoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ public Invoice Refund(IEnumerable<Adjustment> adjustments, bool prorate = false,
return null;
}

public Invoice RefundAmount(int amountInCents) {
var refundInvoice = new Invoice();
var refund = new OpenAmountRefund(amountInCents);

var response = Client.Instance.PerformRequest(Client.HttpRequestMethod.Post,
UrlPrefix + InvoiceNumber + "/refund",
refund.WriteXml,
refundInvoice.ReadXml);

if (HttpStatusCode.Created == response || HttpStatusCode.OK == response)
return refundInvoice;
else
return null;
}

#region Read and Write XML documents

internal override void ReadXml(XmlTextReader reader)
Expand Down Expand Up @@ -264,7 +279,7 @@ internal override void ReadXml(XmlTextReader reader)

internal override void WriteXml(XmlTextWriter writer)
{
throw new NotImplementedException();
throw new System.NotImplementedException();
}

#endregion
Expand Down
26 changes: 26 additions & 0 deletions Library/OpenAmountRefund.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Xml;

namespace Recurly
{
class OpenAmountRefund : RecurlyEntity
{
public int AmountInCents { get; protected set; }

internal OpenAmountRefund(int amountInCents)
{
AmountInCents = amountInCents;
}

internal override void ReadXml(XmlTextReader reader)
{
throw new System.NotImplementedException();
}

internal override void WriteXml(XmlTextWriter writer)
{
writer.WriteStartElement("invoice");
writer.WriteElementString("amount_in_cents", AmountInCents.AsString());
writer.WriteEndElement();
}
}
}
1 change: 1 addition & 0 deletions Library/Recurly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<ItemGroup>
<Compile Include="Account.cs" />
<Compile Include="Address.cs" />
<Compile Include="OpenAmountRefund.cs" />
<Compile Include="Configuration\Settings.cs" />
<Compile Include="Extensions\EnumerableExtensions.cs" />
<Compile Include="Extensions\EnumExtensions.cs" />
Expand Down
26 changes: 26 additions & 0 deletions Test/InvoiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,31 @@ public void RefundMultiple()

account.Close();
}


[Fact]
public void RefundOpenAmount()
{
var account = CreateNewAccountWithBillingInfo();

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

var invoice = account.InvoicePendingCharges();

invoice.MarkSuccessful();

invoice.State.Should().Be(Invoice.InvoiceState.Collected);

Assert.Equal(1, invoice.Adjustments.Count);
Assert.Equal(1, invoice.Adjustments.Capacity);

// refund
var refundInvoice = invoice.RefundAmount(100); // 1 dollar
Assert.NotEqual(invoice.Uuid, refundInvoice.Uuid);
Assert.Equal(-91, refundInvoice.SubtotalInCents); // 91 cents

account.Close();
}
}
}

0 comments on commit 0a4ef7f

Please sign in to comment.