Skip to content

Commit 691483e

Browse files
Merge pull request #492 from sgilrodriguez/vtt_missing_endpoints
2 parents 7a7da19 + a676f97 commit 691483e

File tree

3 files changed

+158
-1
lines changed

3 files changed

+158
-1
lines changed

src/main/java/com/ning/billing/recurly/model/Adjustment.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ public class Adjustment extends RecurlyObject {
172172
@XmlElement(name = "surcharge_in_cents")
173173
private Integer surchargeInCents;
174174

175+
@XmlElement(name = "vertex_transaction_type")
176+
private String vertexTransactionType;
177+
175178
@XmlElementWrapper(name = "custom_fields")
176179
@XmlElement(name = "custom_field")
177180
private CustomFields customFields;
@@ -559,6 +562,14 @@ public void setCustomFields(final CustomFields customFields) {
559562
this.customFields = customFields;
560563
}
561564

565+
public String getVertexTransactionType() {
566+
return vertexTransactionType;
567+
}
568+
569+
public void setVertexTransactionType(final Object vertexTransactionType) {
570+
this.vertexTransactionType = stringOrNull(vertexTransactionType);
571+
}
572+
562573
@Override
563574
public String toString() {
564575
final StringBuilder sb = new StringBuilder();
@@ -609,6 +620,7 @@ public String toString() {
609620
sb.append(", state=").append(state);
610621
sb.append(", prorationRate=").append(prorationRate);
611622
sb.append(", surchargeInCents=").append(surchargeInCents);
623+
sb.append(", vertexTransactionType=").append(vertexTransactionType);
612624
sb.append(", customFields=").append(customFields);
613625
sb.append('}');
614626
return sb.toString();
@@ -756,6 +768,9 @@ public boolean equals(final Object o) {
756768
if (customFields != null ? !customFields.equals(that.customFields) : that.customFields != null) {
757769
return false;
758770
}
771+
if (vertexTransactionType != null ? !vertexTransactionType.equals(that.vertexTransactionType) : that.vertexTransactionType != null) {
772+
return false;
773+
}
759774
return true;
760775
}
761776

@@ -806,6 +821,7 @@ public int hashCode() {
806821
state,
807822
prorationRate,
808823
surchargeInCents,
824+
vertexTransactionType,
809825
customFields
810826
);
811827
}

src/main/java/com/ning/billing/recurly/model/Invoice.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ public class Invoice extends RecurlyObject {
169169
@XmlElement(name = "transaction_type")
170170
private String transactionType;
171171

172+
@XmlElement(name = "vertex_transaction_type")
173+
private String vertexTransactionType;
174+
172175
@XmlElement(name = "dunning_campaign_id")
173176
private String dunningCampaignId;
174177

@@ -561,6 +564,14 @@ public void setTransactionType(final Object transactionType) {
561564
this.transactionType = stringOrNull(transactionType);
562565
}
563566

567+
public String getVertexTransactionType() {
568+
return vertexTransactionType;
569+
}
570+
571+
public void setVertexTransactionType(final Object vertexTransactionType) {
572+
this.vertexTransactionType = stringOrNull(vertexTransactionType);
573+
}
574+
564575
public String getDunningCampaignId() {
565576
return dunningCampaignId;
566577
}
@@ -624,6 +635,8 @@ public String toString() {
624635
sb.append(", address=").append(address);
625636
sb.append(", shippingAddress=").append(shippingAddress);
626637
sb.append(", surchargeInCents=").append(surchargeInCents);
638+
sb.append(", transactionType=").append(transactionType);
639+
sb.append(", vertexTransactionType=").append(vertexTransactionType);
627640
sb.append('}');
628641
return sb.toString();
629642
}
@@ -767,6 +780,9 @@ public boolean equals(final Object o) {
767780
if (transactionType != null ? !transactionType.equals(invoice.transactionType) : invoice.transactionType != null) {
768781
return false;
769782
}
783+
if (vertexTransactionType != null ? !vertexTransactionType.equals(invoice.vertexTransactionType) : invoice.vertexTransactionType != null) {
784+
return false;
785+
}
770786

771787
return true;
772788
}
@@ -817,7 +833,8 @@ public int hashCode() {
817833
address,
818834
shippingAddress,
819835
surchargeInCents,
820-
transactionType
836+
transactionType,
837+
vertexTransactionType
821838
);
822839
}
823840

src/test/java/com/ning/billing/recurly/model/TestPurchase.java

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import static org.testng.Assert.assertEquals;
2525
import static org.testng.Assert.assertNotEquals;
26+
import static org.testng.Assert.assertNull;
2627

2728
public class TestPurchase extends TestModelBase {
2829

@@ -296,6 +297,129 @@ public void testVertexTransactionTypeAllValidValues() throws Exception {
296297
}
297298
}
298299

300+
@Test(groups = "fast")
301+
public void testPurchaseWithAdjustmentLevelVertexTransactionType() throws Exception {
302+
// Test purchase with adjustment-level vertex_transaction_type
303+
final String purchaseData = "<purchase xmlns=\"\">" +
304+
"<currency>USD</currency>" +
305+
" <collection_method>automatic</collection_method>" +
306+
" <vertex_transaction_type>sale</vertex_transaction_type>" +
307+
" <account>" +
308+
" <account_code>test-account</account_code>" +
309+
" </account>" +
310+
" <adjustments>" +
311+
" <adjustment>" +
312+
" <unit_amount_in_cents type=\"integer\">1000</unit_amount_in_cents>" +
313+
" <quantity type=\"integer\">1</quantity>" +
314+
" <currency>USD</currency>" +
315+
" <product_code>product-1</product_code>" +
316+
" <vertex_transaction_type>lease</vertex_transaction_type>" +
317+
" </adjustment>" +
318+
" </adjustments>" +
319+
"</purchase>";
320+
321+
// Deserialize and verify
322+
final Purchase purchase = xmlMapper.readValue(purchaseData, Purchase.class);
323+
assertEquals(purchase.getVertexTransactionType(), "sale");
324+
assertEquals(purchase.getAdjustments().size(), 1);
325+
assertEquals(purchase.getAdjustments().get(0).getVertexTransactionType(), "lease");
326+
}
327+
328+
@Test(groups = "fast")
329+
public void testPurchaseWithMultipleAdjustmentsWithDifferentVertexTransactionTypes() throws Exception {
330+
// Test purchase with multiple adjustments having different vertex_transaction_type values
331+
final String purchaseData = "<purchase xmlns=\"\">" +
332+
"<currency>USD</currency>" +
333+
" <vertex_transaction_type>sale</vertex_transaction_type>" +
334+
" <account>" +
335+
" <account_code>test-account</account_code>" +
336+
" </account>" +
337+
" <adjustments>" +
338+
" <adjustment>" +
339+
" <unit_amount_in_cents type=\"integer\">5000</unit_amount_in_cents>" +
340+
" <quantity type=\"integer\">1</quantity>" +
341+
" <currency>USD</currency>" +
342+
" <product_code>product-lease</product_code>" +
343+
" <vertex_transaction_type>lease</vertex_transaction_type>" +
344+
" </adjustment>" +
345+
" <adjustment>" +
346+
" <unit_amount_in_cents type=\"integer\">3000</unit_amount_in_cents>" +
347+
" <quantity type=\"integer\">1</quantity>" +
348+
" <currency>USD</currency>" +
349+
" <product_code>product-rental</product_code>" +
350+
" <vertex_transaction_type>rental</vertex_transaction_type>" +
351+
" </adjustment>" +
352+
" <adjustment>" +
353+
" <unit_amount_in_cents type=\"integer\">2000</unit_amount_in_cents>" +
354+
" <quantity type=\"integer\">1</quantity>" +
355+
" <currency>USD</currency>" +
356+
" <product_code>product-no-vtt</product_code>" +
357+
" </adjustment>" +
358+
" </adjustments>" +
359+
"</purchase>";
360+
361+
// Deserialize and verify
362+
final Purchase purchase = xmlMapper.readValue(purchaseData, Purchase.class);
363+
assertEquals(purchase.getVertexTransactionType(), "sale");
364+
assertEquals(purchase.getAdjustments().size(), 3);
365+
assertEquals(purchase.getAdjustments().get(0).getVertexTransactionType(), "lease");
366+
assertEquals(purchase.getAdjustments().get(1).getVertexTransactionType(), "rental");
367+
assertNull(purchase.getAdjustments().get(2).getVertexTransactionType());
368+
}
369+
370+
@Test(groups = "fast")
371+
public void testSerializePurchaseWithAdjustmentLevelVertexTransactionType() throws Exception {
372+
// Create purchase programmatically with adjustment-level vertex_transaction_type
373+
final Purchase purchase = new Purchase();
374+
purchase.setCurrency("USD");
375+
purchase.setCollectionMethod("automatic");
376+
purchase.setVertexTransactionType("sale");
377+
378+
final Account account = new Account();
379+
account.setAccountCode("test-account");
380+
purchase.setAccount(account);
381+
382+
// Create adjustments with different vertex_transaction_type values
383+
final Adjustments adjustments = new Adjustments();
384+
385+
final Adjustment adjustment1 = new Adjustment();
386+
adjustment1.setUnitAmountInCents(5000);
387+
adjustment1.setQuantity(1);
388+
adjustment1.setCurrency("USD");
389+
adjustment1.setProductCode("product-lease");
390+
adjustment1.setVertexTransactionType("lease");
391+
adjustments.add(adjustment1);
392+
393+
final Adjustment adjustment2 = new Adjustment();
394+
adjustment2.setUnitAmountInCents(3000);
395+
adjustment2.setQuantity(1);
396+
adjustment2.setCurrency("USD");
397+
adjustment2.setProductCode("product-rental");
398+
adjustment2.setVertexTransactionType("rental");
399+
adjustments.add(adjustment2);
400+
401+
purchase.setAdjustments(adjustments);
402+
403+
// Serialize to XML
404+
final String xml = xmlMapper.writeValueAsString(purchase);
405+
406+
// Verify XML contains both purchase-level and adjustment-level vertex_transaction_type
407+
assert xml.contains("<purchase") : "Should contain purchase root element";
408+
assert xml.contains("<vertex_transaction_type>sale</vertex_transaction_type>") :
409+
"Should contain purchase-level vertex_transaction_type";
410+
assert xml.contains("<vertex_transaction_type>lease</vertex_transaction_type>") :
411+
"Should contain adjustment-level vertex_transaction_type 'lease'";
412+
assert xml.contains("<vertex_transaction_type>rental</vertex_transaction_type>") :
413+
"Should contain adjustment-level vertex_transaction_type 'rental'";
414+
415+
// Verify round-trip serialization/deserialization
416+
final Purchase deserializedPurchase = xmlMapper.readValue(xml, Purchase.class);
417+
assertEquals(deserializedPurchase.getVertexTransactionType(), "sale");
418+
assertEquals(deserializedPurchase.getAdjustments().size(), 2);
419+
assertEquals(deserializedPurchase.getAdjustments().get(0).getVertexTransactionType(), "lease");
420+
assertEquals(deserializedPurchase.getAdjustments().get(1).getVertexTransactionType(), "rental");
421+
}
422+
299423
@Test(groups = "fast")
300424
public void testHashCodeAndEquality() throws Exception {
301425
// create purchase of the same value but difference references

0 commit comments

Comments
 (0)