Skip to content

Commit 462b8e5

Browse files
author
sunny
committed
Adds vertex_transaction_type to purchases
1 parent ed22478 commit 462b8e5

File tree

5 files changed

+126
-0
lines changed

5 files changed

+126
-0
lines changed

Library/Adjustment.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ public List<CustomField> CustomFields
9393
}
9494
private List<CustomField> _customFields;
9595

96+
/// <summary>
97+
/// Optional vertex transaction type for tax purposes.
98+
/// </summary>
99+
public string VertexTransactionType { get; set; }
100+
96101
private const string UrlPrefix = "/accounts/";
97102
private const string UrlPostfix = "/adjustments/";
98103

@@ -279,6 +284,10 @@ internal override void ReadXml(XmlTextReader reader)
279284
TaxCode = reader.ReadElementContentAsString();
280285
break;
281286

287+
case "vertex_transaction_type":
288+
VertexTransactionType = reader.ReadElementContentAsString();
289+
break;
290+
282291
case "tax_type":
283292
TaxType = reader.ReadElementContentAsString();
284293
break;
@@ -405,6 +414,8 @@ internal void WriteXml(XmlTextWriter xmlWriter, bool embedded = false)
405414

406415
if (TaxCode != null)
407416
xmlWriter.WriteElementString("tax_code", TaxCode);
417+
if (VertexTransactionType != null)
418+
xmlWriter.WriteElementString("vertex_transaction_type", VertexTransactionType);
408419
if (StartDate != DateTime.MinValue)
409420
xmlWriter.WriteElementString("start_date", StartDate.ToString("s"));
410421
if (EndDate.HasValue)

Test/Fixtures/FixtureImporter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ public enum FixtureType
9898
PerformanceObligations,
9999
[Description("plans")]
100100
Plans,
101+
[Description("purchases")]
102+
Purchases,
101103
[Description("shipping_methods")]
102104
ShippingMethods,
103105
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
HTTP/1.1 201 Created
2+
Content-Type: application/xml; charset=utf-8
3+
4+
<?xml version="1.0" encoding="UTF-8"?>
5+
<invoice_collection href="https://api.recurly.com/v2/invoice_collections/012345678901234567890123456789ab">
6+
<charge_invoice href="https://api.recurly.com/v2/invoices/012345678901234567890123456789ab">
7+
<account href="https://api.recurly.com/v2/accounts/test-account-123"/>
8+
<uuid>012345678901234567890123456789ab</uuid>
9+
<state>paid</state>
10+
<invoice_number type="integer">1000</invoice_number>
11+
<po_number>PO-12345</po_number>
12+
<vat_number nil="nil"></vat_number>
13+
<subtotal_in_cents type="integer">580</subtotal_in_cents>
14+
<tax_in_cents type="integer">0</tax_in_cents>
15+
<total_in_cents type="integer">580</total_in_cents>
16+
<currency>USD</currency>
17+
<created_at type="datetime">2025-11-25T22:00:00Z</created_at>
18+
<updated_at type="datetime">2025-11-25T22:00:00Z</updated_at>
19+
<line_items type="array">
20+
<adjustment type="charge">
21+
<uuid>adj123456789</uuid>
22+
<description>Test Adjustment</description>
23+
<product_code>test-product</product_code>
24+
<unit_amount_in_cents type="integer">580</unit_amount_in_cents>
25+
<quantity type="integer">1</quantity>
26+
<tax_in_cents type="integer">0</tax_in_cents>
27+
<total_in_cents type="integer">580</total_in_cents>
28+
<currency>USD</currency>
29+
<tax_exempt type="boolean">false</tax_exempt>
30+
<vertex_transaction_type>lease</vertex_transaction_type>
31+
<created_at type="datetime">2025-11-25T22:00:00Z</created_at>
32+
<updated_at type="datetime">2025-11-25T22:00:00Z</updated_at>
33+
</adjustment>
34+
</line_items>
35+
<transactions type="array">
36+
<transaction href="https://api.recurly.com/v2/transactions/tx123456789" type="credit_card">
37+
<account href="https://api.recurly.com/v2/accounts/test-account-123"/>
38+
<uuid>tx123456789</uuid>
39+
<action>purchase</action>
40+
<amount_in_cents type="integer">580</amount_in_cents>
41+
<tax_in_cents type="integer">0</tax_in_cents>
42+
<currency>USD</currency>
43+
<status>success</status>
44+
<payment_method>credit_card</payment_method>
45+
<reference nil="nil"></reference>
46+
<source>purchase</source>
47+
<test type="boolean">true</test>
48+
<voidable type="boolean">true</voidable>
49+
<refundable type="boolean">true</refundable>
50+
<created_at type="datetime">2025-11-25T22:00:00Z</created_at>
51+
<updated_at type="datetime">2025-11-25T22:00:00Z</updated_at>
52+
</transaction>
53+
</transactions>
54+
</charge_invoice>
55+
<credit_invoices type="array">
56+
</credit_invoices>
57+
</invoice_collection>

Test/PurchaseTest.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Xml;
45
using FluentAssertions;
6+
using Recurly.Test.Fixtures;
57
using Xunit;
68

79
namespace Recurly.Test
@@ -278,5 +280,56 @@ public void PurchaseWithEOMNetTerms()
278280
Assert.Equal(response.ChargeInvoice.NetTerms, 45);
279281
response.ChargeInvoice.NetTermsType.Should().Be(NetTermsType.EOM);
280282
}
283+
284+
[RecurlyFact(TestEnvironment.Type.Unit)]
285+
public void PurchaseWithVertexTransactionType()
286+
{
287+
// Create an actual purchase with vertex_transaction_type
288+
var account = NewAccountWithBillingInfo();
289+
290+
var adjustment = account.NewAdjustment("Test Adjustment", 580);
291+
adjustment.Currency = "USD";
292+
adjustment.Quantity = 1;
293+
adjustment.UnitAmountInCents = 580;
294+
adjustment.VertexTransactionType = "lease";
295+
296+
var purchase = new Purchase(account.AccountCode, "USD");
297+
purchase.Account = account;
298+
purchase.Adjustments.Add(adjustment);
299+
300+
// Verify the request serializes vertex_transaction_type correctly
301+
var xmlOutput = new System.Text.StringBuilder();
302+
using (var xmlWriter = new XmlTextWriter(new System.IO.StringWriter(xmlOutput)))
303+
{
304+
adjustment.WriteEmbeddedXml(xmlWriter);
305+
}
306+
var xml = xmlOutput.ToString();
307+
Assert.Contains("<vertex_transaction_type>lease</vertex_transaction_type>", xml);
308+
309+
// Simulate what Purchase.Invoice(purchase) would return by using a fixture
310+
// This mocks the API response without making an actual HTTP call
311+
var mockResponse = GetMockInvoiceCollectionResponse();
312+
313+
// Assert the mocked response contains vertex_transaction_type
314+
Assert.NotNull(mockResponse.ChargeInvoice);
315+
Assert.Equal(mockResponse.ChargeInvoice.State, Invoice.InvoiceState.Paid);
316+
Assert.NotNull(mockResponse.ChargeInvoice.Adjustments);
317+
Assert.Single(mockResponse.ChargeInvoice.Adjustments);
318+
Assert.Equal(mockResponse.ChargeInvoice.Adjustments[0].VertexTransactionType, "lease");
319+
Assert.Equal(mockResponse.ChargeInvoice.Adjustments[0].UnitAmountInCents, 580);
320+
Assert.Equal(mockResponse.ChargeInvoice.Adjustments[0].Description, "Test Adjustment");
321+
}
322+
323+
private InvoiceCollection GetMockInvoiceCollectionResponse()
324+
{
325+
// Mock the Purchase.Invoice response using a fixture
326+
var collection = new InvoiceCollection();
327+
var xmlFixture = FixtureImporter.Get(FixtureType.Purchases, "invoice-with-vertex-201").Xml;
328+
using (var reader = new XmlTextReader(new System.IO.StringReader(xmlFixture)))
329+
{
330+
collection.ReadXml(reader);
331+
}
332+
return collection;
333+
}
281334
}
282335
}

Test/Recurly.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@
224224
<Content Include="Fixtures\plans\show-200.xml">
225225
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
226226
</Content>
227+
<Content Include="Fixtures\purchases\invoice-with-vertex-201.xml">
228+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
229+
</Content>
227230
<Content Include="Fixtures\subscriptions\show-200-inactive.xml">
228231
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
229232
</Content>

0 commit comments

Comments
 (0)