|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Linq; |
| 4 | +using System.Xml; |
4 | 5 | using FluentAssertions; |
| 6 | +using Recurly.Test.Fixtures; |
5 | 7 | using Xunit; |
6 | 8 |
|
7 | 9 | namespace Recurly.Test |
@@ -278,5 +280,88 @@ public void PurchaseWithEOMNetTerms() |
278 | 280 | Assert.Equal(response.ChargeInvoice.NetTerms, 45); |
279 | 281 | response.ChargeInvoice.NetTermsType.Should().Be(NetTermsType.EOM); |
280 | 282 | } |
| 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 | + |
| 295 | + var purchase = new Purchase(account.AccountCode, "USD"); |
| 296 | + purchase.Account = account; |
| 297 | + purchase.VertexTransactionType = "lease"; |
| 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 | + purchase.WriteXml(xmlWriter); |
| 305 | + } |
| 306 | + var xml = xmlOutput.ToString(); |
| 307 | + Assert.Contains("<vertex_transaction_type>lease</vertex_transaction_type>", xml); |
| 308 | + |
| 309 | + // Verify that a valid InvoiceCollection can be deserialized |
| 310 | + // (vertex_transaction_type is only sent in requests, not returned in responses) |
| 311 | + var mockResponse = GetMockInvoiceCollectionResponse(); |
| 312 | + Assert.NotNull(mockResponse.ChargeInvoice); |
| 313 | + Assert.Equal(mockResponse.ChargeInvoice.State, Invoice.InvoiceState.Paid); |
| 314 | + } |
| 315 | + |
| 316 | + [RecurlyFact(TestEnvironment.Type.Unit)] |
| 317 | + public void PurchaseWithAdjustmentsContainingVertexTransactionType() |
| 318 | + { |
| 319 | + // Create a purchase with adjustments that have vertex_transaction_type |
| 320 | + var account = NewAccountWithBillingInfo(); |
| 321 | + |
| 322 | + var adjustment1 = account.NewAdjustment("Adjustment with lease type", 580); |
| 323 | + adjustment1.Currency = "USD"; |
| 324 | + adjustment1.Quantity = 1; |
| 325 | + adjustment1.VertexTransactionType = "lease"; |
| 326 | + |
| 327 | + var adjustment2 = account.NewAdjustment("Adjustment with rental type", 1200); |
| 328 | + adjustment2.Currency = "USD"; |
| 329 | + adjustment2.Quantity = 2; |
| 330 | + adjustment2.UnitAmountInCents = 600; |
| 331 | + adjustment2.VertexTransactionType = "rental"; |
| 332 | + |
| 333 | + var purchase = new Purchase(account.AccountCode, "USD"); |
| 334 | + purchase.Account = account; |
| 335 | + purchase.Adjustments.Add(adjustment1); |
| 336 | + purchase.Adjustments.Add(adjustment2); |
| 337 | + |
| 338 | + // Verify the request serializes vertex_transaction_type correctly for each adjustment |
| 339 | + var xmlOutput = new System.Text.StringBuilder(); |
| 340 | + using (var xmlWriter = new XmlTextWriter(new System.IO.StringWriter(xmlOutput))) |
| 341 | + { |
| 342 | + purchase.WriteXml(xmlWriter); |
| 343 | + } |
| 344 | + var xml = xmlOutput.ToString(); |
| 345 | + |
| 346 | + // Should contain vertex_transaction_type for both adjustments |
| 347 | + Assert.Contains("<vertex_transaction_type>lease</vertex_transaction_type>", xml); |
| 348 | + Assert.Contains("<vertex_transaction_type>rental</vertex_transaction_type>", xml); |
| 349 | + |
| 350 | + // Verify both adjustments are in the XML with their properties |
| 351 | + Assert.Contains("<unit_amount_in_cents>580</unit_amount_in_cents>", xml); |
| 352 | + Assert.Contains("<unit_amount_in_cents>600</unit_amount_in_cents>", xml); |
| 353 | + } |
| 354 | + |
| 355 | + private InvoiceCollection GetMockInvoiceCollectionResponse() |
| 356 | + { |
| 357 | + // Mock the Purchase.Invoice response using a fixture |
| 358 | + var collection = new InvoiceCollection(); |
| 359 | + var xmlFixture = FixtureImporter.Get(FixtureType.Purchases, "invoice-with-vertex-201").Xml; |
| 360 | + using (var reader = new XmlTextReader(new System.IO.StringReader(xmlFixture))) |
| 361 | + { |
| 362 | + collection.ReadXml(reader); |
| 363 | + } |
| 364 | + return collection; |
| 365 | + } |
281 | 366 | } |
282 | 367 | } |
0 commit comments