Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix setting recurly error when using RecurlyErrors class #487

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/main/java/com/ning/billing/recurly/model/Errors.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void setRecurlyErrors(final Object recurlyError) {
}
this.recurlyErrors.add(error);
} else {
this.recurlyErrors = (RecurlyErrors) recurlyErrors;
this.recurlyErrors = (RecurlyErrors) recurlyError;
}
}

Expand Down Expand Up @@ -114,4 +114,4 @@ public int hashCode() {
recurlyErrors
);
}
}
}
203 changes: 130 additions & 73 deletions src/test/java/com/ning/billing/recurly/model/TestErrors.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
import org.testng.Assert;
import org.testng.annotations.Test;

import java.util.HashMap;
import java.util.Map;

public class TestErrors extends TestModelBase {

@Test(groups = "fast")
public void testSerializationErrors() throws Exception {
final String errorsData = "<errors>\n" +
" <error field=\"billing_info.address1\" symbol=\"empty\">can't be empty</error>\n" +
" <error field=\"billing_info.year\" symbol=\"less_than\">must be less than 2050</error>\n" +
"</errors>";
" <error field=\"billing_info.address1\" symbol=\"empty\">can't be empty</error>\n" +
" <error field=\"billing_info.year\" symbol=\"less_than\">must be less than 2050</error>\n" +
"</errors>";

final Errors errors = xmlMapper.readValue(errorsData, Errors.class);
Assert.assertEquals(errors.getRecurlyErrors().get(0).getField(), "billing_info.address1");
Expand All @@ -41,71 +44,75 @@ public void testSerializationErrors() throws Exception {
@Test(groups = "fast")
public void testSerializationTransactionErrors() throws Exception {
final String errorsData = "<errors>\n" +
" <transaction_error>\n" +
" <error_code>fraud_ip_address</error_code>\n" +
" <error_category>fraud</error_category>\n" +
" <merchant_message>The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions.</merchant_message>\n" +
" <customer_message>The transaction was declined. Please contact support.</customer_message>\n" +
" </transaction_error>\n" +
" <error field=\"billing_info.base\" symbol=\"fraud_ip_address\">The transaction was declined. Please contact support.</error>\n" +
" <transaction href=\"https://your-subdomain.recurly.com/v2/transactions/3d1c6aa86e3d447eb0f3b4a6e3e074d9\" type=\"credit_card\">\n" +
" <account href=\"https://your-subdomain.recurly.com/v2/accounts/c9cd3b70-1559-11e3-8ffd-0800200c9a66\"/>\n" +
" <uuid>12578bb566572144deb5364d4ebd32ce</uuid>\n" +
" <action>verify</action>\n" +
" <amount_in_cents type=\"integer\">0</amount_in_cents>\n" +
" <tax_in_cents type=\"integer\">0</tax_in_cents>\n" +
" <currency>USD</currency>\n" +
" <status>declined</status>\n" +
" <reference>8433694</reference>\n" +
" <source>billing_info</source>\n" +
" <recurring type=\"boolean\">false</recurring>\n" +
" <test type=\"boolean\">true</test>\n" +
" <voidable type=\"boolean\">false</voidable>\n" +
" <refundable type=\"boolean\">false</refundable>\n" +
" <transaction_error>\n" +
" <error_code>fraud_ip_address</error_code>\n" +
" <error_category>fraud</error_category>\n" +
" <merchant_message>The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions.</merchant_message>\n" +
" <customer_message>The transaction was declined. Please contact support.</customer_message>\n" +
" </transaction_error>\n" +
" <cvv_result code=\"\" nil=\"nil\"></cvv_result>\n" +
" <avs_result code=\"\" nil=\"nil\"></avs_result>\n" +
" <avs_result_street nil=\"nil\"></avs_result_street>\n" +
" <avs_result_postal nil=\"nil\"></avs_result_postal>\n" +
" <created_at type=\"dateTime\">2013-09-04T11:34:21Z</created_at>\n" +
" <details>\n" +
" <account>\n" +
" <account_code>4503f4df-acab-4097-9245-f4c130b5f9ac</account_code>\n" +
" <first_name>248e5</first_name>\n" +
" <last_name>f1a42f</last_name>\n" +
" <company>2a08b4344e</company>\n" +
" <email>[email protected]</email>\n" +
" <billing_info type=\"credit_card\">\n" +
" <first_name>0dec5</first_name>\n" +
" <last_name>91faa8</last_name>\n" +
" <address1>680a5d6012</address1>\n" +
" <address2>cf66c41dea</address2>\n" +
" <city>b77f65bff7</city>\n" +
" <state>c3274dd270</state>\n" +
" <zip>b12f7</zip>\n" +
" <country>f0ba2</country>\n" +
" <phone>6</phone>\n" +
" <vat_number>7</vat_number>\n" +
" <card_type>Visa</card_type>\n" +
" <year type=\"integer\">2015</year>\n" +
" <month type=\"integer\">11</month>\n" +
" <first_six>400000</first_six>\n" +
" <last_four>0093</last_four>\n" +
" </billing_info>\n" +
" </account>\n" +
" </details>\n" +
" </transaction>\n" +
"</errors>";
" <transaction_error>\n" +
" <error_code>fraud_ip_address</error_code>\n" +
" <error_category>fraud</error_category>\n" +
" <merchant_message>The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions.</merchant_message>\n" +
" <customer_message>The transaction was declined. Please contact support.</customer_message>\n" +
" </transaction_error>\n" +
" <error field=\"billing_info.base\" symbol=\"fraud_ip_address\">The transaction was declined. Please contact support.</error>\n" +
" <transaction href=\"https://your-subdomain.recurly.com/v2/transactions/3d1c6aa86e3d447eb0f3b4a6e3e074d9\" type=\"credit_card\">\n" +
" <account href=\"https://your-subdomain.recurly.com/v2/accounts/c9cd3b70-1559-11e3-8ffd-0800200c9a66\"/>\n" +
" <uuid>12578bb566572144deb5364d4ebd32ce</uuid>\n" +
" <action>verify</action>\n" +
" <amount_in_cents type=\"integer\">0</amount_in_cents>\n" +
" <tax_in_cents type=\"integer\">0</tax_in_cents>\n" +
" <currency>USD</currency>\n" +
" <status>declined</status>\n" +
" <reference>8433694</reference>\n" +
" <source>billing_info</source>\n" +
" <recurring type=\"boolean\">false</recurring>\n" +
" <test type=\"boolean\">true</test>\n" +
" <voidable type=\"boolean\">false</voidable>\n" +
" <refundable type=\"boolean\">false</refundable>\n" +
" <transaction_error>\n" +
" <error_code>fraud_ip_address</error_code>\n" +
" <error_category>fraud</error_category>\n" +
" <merchant_message>The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions.</merchant_message>\n" +
" <customer_message>The transaction was declined. Please contact support.</customer_message>\n" +
" </transaction_error>\n" +
" <cvv_result code=\"\" nil=\"nil\"></cvv_result>\n" +
" <avs_result code=\"\" nil=\"nil\"></avs_result>\n" +
" <avs_result_street nil=\"nil\"></avs_result_street>\n" +
" <avs_result_postal nil=\"nil\"></avs_result_postal>\n" +
" <created_at type=\"dateTime\">2013-09-04T11:34:21Z</created_at>\n" +
" <details>\n" +
" <account>\n" +
" <account_code>4503f4df-acab-4097-9245-f4c130b5f9ac</account_code>\n" +
" <first_name>248e5</first_name>\n" +
" <last_name>f1a42f</last_name>\n" +
" <company>2a08b4344e</company>\n" +
" <email>[email protected]</email>\n" +
" <billing_info type=\"credit_card\">\n" +
" <first_name>0dec5</first_name>\n" +
" <last_name>91faa8</last_name>\n" +
" <address1>680a5d6012</address1>\n" +
" <address2>cf66c41dea</address2>\n" +
" <city>b77f65bff7</city>\n" +
" <state>c3274dd270</state>\n" +
" <zip>b12f7</zip>\n" +
" <country>f0ba2</country>\n" +
" <phone>6</phone>\n" +
" <vat_number>7</vat_number>\n" +
" <card_type>Visa</card_type>\n" +
" <year type=\"integer\">2015</year>\n" +
" <month type=\"integer\">11</month>\n" +
" <first_six>400000</first_six>\n" +
" <last_four>0093</last_four>\n" +
" </billing_info>\n" +
" </account>\n" +
" </details>\n" +
" </transaction>\n" +
"</errors>";

final Errors errors = xmlMapper.readValue(errorsData, Errors.class);
Assert.assertEquals(errors.getTransactionError().getErrorCode(), "fraud_ip_address");
Assert.assertEquals(errors.getTransactionError().getMerchantMessage(), "The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions.");
Assert.assertEquals(errors.getTransactionError().getCustomerMessage(), "The transaction was declined. Please contact support.");
Assert.assertEquals(
errors.getTransactionError().getMerchantMessage(),
"The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions.");
Assert.assertEquals(
errors.getTransactionError().getCustomerMessage(),
"The transaction was declined. Please contact support.");

Assert.assertEquals(errors.getTransaction().getUuid(), "12578bb566572144deb5364d4ebd32ce");
Assert.assertEquals(errors.getTransaction().getAction(), "verify");
Expand All @@ -120,29 +127,79 @@ public void testSerializationTransactionErrors() throws Exception {
Assert.assertFalse(errors.getTransaction().getVoidable());
Assert.assertFalse(errors.getTransaction().getRefundable());
Assert.assertEquals(errors.getTransaction().getTransactionError().getErrorCode(), "fraud_ip_address");
Assert.assertEquals(errors.getTransaction().getTransactionError().getMerchantMessage(), "The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions.");
Assert.assertEquals(errors.getTransaction().getTransactionError().getCustomerMessage(), "The transaction was declined. Please contact support.");
Assert.assertEquals(
errors.getTransaction().getTransactionError().getMerchantMessage(),
"The payment gateway declined the transaction because it originated from an IP address known for fraudulent transactions.");
Assert.assertEquals(
errors.getTransaction().getTransactionError().getCustomerMessage(),
"The transaction was declined. Please contact support.");

Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getAccountCode(), "4503f4df-acab-4097-9245-f4c130b5f9ac");
Assert.assertEquals(
errors.getTransaction().getDetails().getAccount().getAccountCode(),
"4503f4df-acab-4097-9245-f4c130b5f9ac");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getFirstName(), "248e5");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getLastName(), "f1a42f");
// TODO Element not consistent with Account API
//Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getCompanyName(), "2a08b4344e");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getEmail(), "[email protected]");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getFirstName(), "0dec5");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getLastName(), "91faa8");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getAddress1(), "680a5d6012");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getAddress2(), "cf66c41dea");
Assert.assertEquals(
errors.getTransaction().getDetails().getAccount().getBillingInfo().getAddress1(),
"680a5d6012");
Assert.assertEquals(
errors.getTransaction().getDetails().getAccount().getBillingInfo().getAddress2(),
"cf66c41dea");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getCity(), "b77f65bff7");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getState(), "c3274dd270");
Assert.assertEquals(
errors.getTransaction().getDetails().getAccount().getBillingInfo().getState(),
"c3274dd270");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getZip(), "b12f7");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getCountry(), "f0ba2");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getPhone(), "6");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getVatNumber(), "7");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getCardType(), "Visa");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getYear(), (Integer) 2015);
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getMonth(), (Integer) 11);
Assert.assertEquals(
errors.getTransaction().getDetails().getAccount().getBillingInfo().getYear(),
(Integer) 2015);
Assert.assertEquals(
errors.getTransaction().getDetails().getAccount().getBillingInfo().getMonth(),
(Integer) 11);
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getFirstSix(), "400000");
Assert.assertEquals(errors.getTransaction().getDetails().getAccount().getBillingInfo().getLastFour(), "0093");
}

@Test(groups = "fast")
public void testShouldCreateRecurlyErrorsFromMap() {
Map<String, String> recurlyErrorMap = new HashMap<String, String>();
recurlyErrorMap.put(
"field",
"account base");
recurlyErrorMap.put(
"",
"transaction declined.");
recurlyErrorMap.put(
"symbol",
"fraud_velocity");

Errors errors = new Errors();
errors.setRecurlyErrors(recurlyErrorMap);

Assert.assertEquals(errors.getRecurlyErrors().size(), 1);
}

@Test(groups = "fast")
public void testShouldCreateRecurlyErrorsFromClass() {
RecurlyError recurlyError = new RecurlyError();
recurlyError.setField("account base");
recurlyError.setSymbol("fraud_velocity");
recurlyError.setMessage("transaction declined.");
RecurlyErrors recurlyErrors = new RecurlyErrors();
recurlyErrors.add(recurlyError);

Errors errors = new Errors();
errors.setRecurlyErrors(recurlyErrors);

Assert.assertEquals(errors.getRecurlyErrors().size(), 1);
}
}