Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/main/java/com/ning/billing/recurly/model/Purchase.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ public class Purchase extends RecurlyObject {
@XmlElement(name = "transaction_type")
private String transactionType;

@XmlElement(name = "vertex_transaction_type")
private String vertexTransactionType;

@XmlList
@XmlElementWrapper(name = "coupon_codes")
@XmlElement(name = "coupon_code")
Expand Down Expand Up @@ -245,6 +248,14 @@ public void setTransactionType(final Object transactionType) {
this.transactionType = stringOrNull(transactionType);
}

public String getVertexTransactionType() {
return vertexTransactionType;
}

public void setVertexTransactionType(final Object vertexTransactionType) {
this.vertexTransactionType = stringOrNull(vertexTransactionType);
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
Expand All @@ -268,6 +279,7 @@ public String toString() {
sb.append(", shippingAddressId='").append(shippingAddressId).append('\'');
sb.append(", gatewayCode='").append(gatewayCode).append('\'');
sb.append(", transactionType='").append(transactionType).append('\'');
sb.append(", vertexTransactionType='").append(vertexTransactionType).append('\'');
sb.append('}');
return sb.toString();
}
Expand Down Expand Up @@ -333,6 +345,9 @@ public boolean equals(final Object o) {
if (transactionType != null ? !transactionType.equals(purchase.transactionType) : purchase.transactionType != null) {
return false;
}
if (vertexTransactionType != null ? !vertexTransactionType.equals(purchase.vertexTransactionType) : purchase.vertexTransactionType != null) {
return false;
}
if (vatReverseChargeNotes != null ? !vatReverseChargeNotes.equals(purchase.vatReverseChargeNotes) : purchase.vatReverseChargeNotes != null) {
return false;
}
Expand Down Expand Up @@ -361,7 +376,8 @@ public int hashCode() {
billingInfoUuid,
shippingAddressId,
gatewayCode,
transactionType
transactionType,
vertexTransactionType
);
}

Expand Down
89 changes: 88 additions & 1 deletion src/test/java/com/ning/billing/recurly/model/TestPurchase.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,94 @@ public void testSerializationWithBillingInfoUuid() throws Exception {

public void verifyPurchaseWithBillingInfoUuid(final Purchase purchase) {
assertEquals(purchase.getBillingInfoUuid(), "iiznlrvdt8py");
}
}

@Test(groups = "fast")
public void testSerializationWithVertexTransactionType() throws Exception {
final String purchaseData = "<purchase xmlns=\"\">" +
"<currency>USD</currency>" +
" <collection_method>automatic</collection_method>" +
" <vertex_transaction_type>rental</vertex_transaction_type>" +
" <account>" +
" <account_code>test</account_code>" +
" <billing_info>" +
" <first_name>Benjamin</first_name>" +
" <last_name>Du Monde</last_name>" +
" <address1>400 Alabama St</address1>" +
" <city>San Francisco</city>" +
" <state>CA</state>" +
" <zip>94110</zip>" +
" <country>US</country>" +
" <year type=\"integer\">2019</year>" +
" <month type=\"integer\">12</month>" +
" <number>4000-0000-0000-0000</number>" +
" </billing_info>" +
" </account>" +
" <adjustments>" +
" <adjustment>" +
" <unit_amount_in_cents type=\"integer\">1000</unit_amount_in_cents>" +
" <quantity type=\"integer\">1</quantity>" +
" <currency>USD</currency>" +
" <product_code>product-code</product_code>" +
" </adjustment>" +
" </adjustments>" +
"</purchase>";

// test serialization
final Purchase purchase = xmlMapper.readValue(purchaseData, Purchase.class);
verifyPurchaseWithVertexTransactionType(purchase);

// test deseralization
final Purchase purchaseExpected = xmlMapper.readValue(purchaseData, Purchase.class);
assertEquals(purchase, purchaseExpected);
}

public void verifyPurchaseWithVertexTransactionType(final Purchase purchase) {
assertEquals(purchase.getVertexTransactionType(), "rental");
assertEquals(purchase.getCurrency(), "USD");
assertEquals(purchase.getCollectionMethod(), "automatic");
}

@Test(groups = "fast")
public void testSerializationToXmlWithVertexTransactionType() throws Exception {
// Create purchase object programmatically and verify it serializes correctly to XML
final Purchase purchase = new Purchase();
purchase.setCurrency("USD");
purchase.setCollectionMethod("automatic");
purchase.setVertexTransactionType("lease");

final Account account = new Account();
account.setAccountCode("test-account");
purchase.setAccount(account);

// Serialize to XML string
final String xml = xmlMapper.writeValueAsString(purchase);

// Verify the XML contains the vertex_transaction_type element
assert xml.contains("<vertex_transaction_type>lease</vertex_transaction_type>") :
"Serialized XML should contain vertex_transaction_type element";
assert xml.contains("<collection_method>automatic</collection_method>");
assert xml.contains("<currency>USD</currency>");
}

@Test(groups = "fast")
public void testVertexTransactionTypeAllValidValues() throws Exception {
// Test all valid values: sale, rental, lease
final String[] validValues = {"sale", "rental", "lease"};

for (String value : validValues) {
final Purchase purchase = new Purchase();
purchase.setVertexTransactionType(value);
assertEquals(purchase.getVertexTransactionType(), value,
"Should correctly set and get value: " + value);

// Verify serialization/deserialization round-trip
final String xml = xmlMapper.writeValueAsString(purchase);
final Purchase deserializedPurchase = xmlMapper.readValue(xml, Purchase.class);
assertEquals(deserializedPurchase.getVertexTransactionType(), value,
"Should correctly deserialize value: " + value);
}
}

@Test(groups = "fast")
public void testHashCodeAndEquality() throws Exception {
Expand Down