Details
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/AuditedEntitlementDao.java b/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/AuditedEntitlementDao.java
index b2816ce..455fe64 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/AuditedEntitlementDao.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/engine/dao/AuditedEntitlementDao.java
@@ -567,7 +567,7 @@ public class AuditedEntitlementDao implements EntitlementDao {
final String baseProductName = (futureBaseEvent instanceof ApiEventChange) ?
((ApiEventChange) futureBaseEvent).getEventPlan() : null;
- final boolean createCancelEvent = (futureBaseEvent != null) &&
+ final boolean createCancelEvent = (futureBaseEvent != null && targetAddOnPlan != null) &&
((futureBaseEvent instanceof ApiEventCancel) ||
((!addonUtils.isAddonAvailableFromPlanName(baseProductName, futureBaseEvent.getEffectiveDate(), targetAddOnPlan)) ||
(addonUtils.isAddonIncludedFromPlanName(baseProductName, futureBaseEvent.getEffectiveDate(), targetAddOnPlan))));
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountTimelineJson.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountTimelineJson.java
index dfe5ca5..29b1d29 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountTimelineJson.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/AccountTimelineJson.java
@@ -124,20 +124,22 @@ public class AccountTimelineJson {
for (final Payment payment : payments) {
final List<RefundJson> refunds = new ArrayList<RefundJson>();
for (final Refund refund : refundsByPayment.get(payment.getId())) {
- refunds.add(new RefundJson(refund));
+ final List<AuditLog> auditLogs = refundsAuditLogs.get(refund.getId());
+ refunds.add(new RefundJson(refund, auditLogs));
}
final List<ChargebackJson> chargebacks = new ArrayList<ChargebackJson>();
for (final InvoicePayment chargeback : chargebacksByPayment.get(payment.getId())) {
- chargebacks.add(new ChargebackJson(chargeback));
+ final List<AuditLog> auditLogs = chargebacksAuditLogs.get(chargeback.getId());
+ chargebacks.add(new ChargebackJson(chargeback, auditLogs));
}
- final int nbOfPaymentAttemps = payment.getAttempts().size();
+ final int nbOfPaymentAttempts = payment.getAttempts().size();
final String status = payment.getPaymentStatus().toString();
final List<AuditLog> auditLogs = paymentsAuditLogs.get(payment.getId());
this.payments.add(new PaymentJsonWithBundleKeys(payment,
status,
- nbOfPaymentAttemps,
+ nbOfPaymentAttempts,
getBundleExternalKey(payment.getInvoiceId(), invoices, bundles),
account.getId(),
refunds,
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/ChargebackJson.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/ChargebackJson.java
index 9eba9a9..dec2fd6 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/ChargebackJson.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/ChargebackJson.java
@@ -17,15 +17,20 @@
package com.ning.billing.jaxrs.json;
import java.math.BigDecimal;
+import java.util.List;
+
+import javax.annotation.Nullable;
import org.joda.time.DateTime;
+import com.ning.billing.invoice.api.InvoicePayment;
+import com.ning.billing.util.audit.AuditLog;
+
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
-import com.ning.billing.invoice.api.InvoicePayment;
-// TODO: populate reason code, requested date from audit log
-public class ChargebackJson {
+public class ChargebackJson extends JsonBase {
+
private final DateTime requestedDate;
private final DateTime effectiveDate;
private final BigDecimal chargebackAmount;
@@ -37,7 +42,9 @@ public class ChargebackJson {
@JsonProperty("effectiveDate") final DateTime effectiveDate,
@JsonProperty("chargebackAmount") final BigDecimal chargebackAmount,
@JsonProperty("paymentId") final String paymentId,
- @JsonProperty("reason") final String reason) {
+ @JsonProperty("reason") final String reason,
+ @JsonProperty("auditLogs") @Nullable final List<AuditLogJson> auditLogs) {
+ super(auditLogs);
this.requestedDate = requestedDate;
this.effectiveDate = effectiveDate;
this.chargebackAmount = chargebackAmount;
@@ -46,11 +53,12 @@ public class ChargebackJson {
}
public ChargebackJson(final InvoicePayment chargeback) {
- this.requestedDate = null;
- this.effectiveDate = chargeback.getPaymentDate();
- this.chargebackAmount = chargeback.getAmount().negate();
- this.paymentId = chargeback.getPaymentId().toString();
- this.reason = null;
+ this(chargeback, null);
+ }
+
+ public ChargebackJson(final InvoicePayment chargeback, @Nullable final List<AuditLog> auditLogs) {
+ this(chargeback.getPaymentDate(), chargeback.getPaymentDate(), chargeback.getAmount().negate(),
+ chargeback.getPaymentId().toString(), reasonCodeFromAuditLogs(auditLogs), toAuditLogJson(auditLogs));
}
public DateTime getRequestedDate() {
@@ -85,11 +93,11 @@ public class ChargebackJson {
final ChargebackJson that = (ChargebackJson) o;
if (!((chargebackAmount == null && that.chargebackAmount == null) ||
- (chargebackAmount != null && that.chargebackAmount != null && chargebackAmount.compareTo(that.chargebackAmount) == 0))) {
+ (chargebackAmount != null && that.chargebackAmount != null && chargebackAmount.compareTo(that.chargebackAmount) == 0))) {
return false;
}
if (!((effectiveDate == null && that.effectiveDate == null) ||
- (effectiveDate != null && that.effectiveDate != null && effectiveDate.compareTo(that.effectiveDate) == 0))) {
+ (effectiveDate != null && that.effectiveDate != null && effectiveDate.compareTo(that.effectiveDate) == 0))) {
return false;
}
if (paymentId != null ? !paymentId.equals(that.paymentId) : that.paymentId != null) {
@@ -99,7 +107,7 @@ public class ChargebackJson {
return false;
}
if (!((requestedDate == null && that.requestedDate == null) ||
- (requestedDate != null && that.requestedDate != null && requestedDate.compareTo(that.requestedDate) == 0))) {
+ (requestedDate != null && that.requestedDate != null && requestedDate.compareTo(that.requestedDate) == 0))) {
return false;
}
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/JsonBase.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/JsonBase.java
index 26fd3f5..b3e078c 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/JsonBase.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/JsonBase.java
@@ -47,6 +47,14 @@ public abstract class JsonBase {
}));
}
+ protected static String reasonCodeFromAuditLogs(@Nullable final List<AuditLog> auditLogs) {
+ if (auditLogs == null || auditLogs.size() == 0) {
+ return null;
+ }
+
+ return auditLogs.get(0).getReasonCode();
+ }
+
public List<AuditLogJson> getAuditLogs() {
return auditLogs;
}
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/RefundJson.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/RefundJson.java
index ff1547a..390837b 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/json/RefundJson.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/json/RefundJson.java
@@ -17,15 +17,19 @@
package com.ning.billing.jaxrs.json;
import java.math.BigDecimal;
+import java.util.List;
+
+import javax.annotation.Nullable;
import org.joda.time.DateTime;
import com.ning.billing.payment.api.Refund;
+import com.ning.billing.util.audit.AuditLog;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
-public class RefundJson {
+public class RefundJson extends JsonBase {
private final String refundId;
private final String paymentId;
@@ -34,18 +38,15 @@ public class RefundJson {
private final DateTime requestedDate;
private final DateTime effectiveDate;
- public RefundJson(final Refund input) {
- this(input.getId().toString(), input.getPaymentId().toString(), input.getRefundAmount(), input.isAdjusted(),
- input.getEffectiveDate(), input.getEffectiveDate());
- }
-
@JsonCreator
public RefundJson(@JsonProperty("refund_id") final String refundId,
@JsonProperty("paymentId") final String paymentId,
@JsonProperty("refundAmount") final BigDecimal refundAmount,
@JsonProperty("adjusted") final Boolean isAdjusted,
@JsonProperty("requestedDate") final DateTime requestedDate,
- @JsonProperty("effectiveDate") final DateTime effectiveDate) {
+ @JsonProperty("effectiveDate") final DateTime effectiveDate,
+ @JsonProperty("auditLogs") @Nullable final List<AuditLogJson> auditLogs) {
+ super(auditLogs);
this.refundId = refundId;
this.paymentId = paymentId;
this.refundAmount = refundAmount;
@@ -54,6 +55,15 @@ public class RefundJson {
this.effectiveDate = effectiveDate;
}
+ public RefundJson(final Refund refund) {
+ this(refund, null);
+ }
+
+ public RefundJson(final Refund refund, final List<AuditLog> auditLogs) {
+ this(refund.getId().toString(), refund.getPaymentId().toString(), refund.getRefundAmount(), refund.isAdjusted(),
+ refund.getEffectiveDate(), refund.getEffectiveDate(), toAuditLogJson(auditLogs));
+ }
+
public String getRefundId() {
return refundId;
}
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/mappers/ExceptionMapperBase.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/mappers/ExceptionMapperBase.java
index d803d10..cf1e2d0 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/mappers/ExceptionMapperBase.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/mappers/ExceptionMapperBase.java
@@ -29,6 +29,8 @@ public abstract class ExceptionMapperBase {
private static final Logger log = LoggerFactory.getLogger(ExceptionMapperBase.class);
protected Response buildConflictingRequestResponse(final Exception e, final UriInfo uriInfo) {
+ // Log the full stacktrace
+ log.warn("Conflicting request", e);
return buildConflictingRequestResponse(e.toString(), uriInfo);
}
@@ -41,6 +43,8 @@ public abstract class ExceptionMapperBase {
}
protected Response buildNotFoundResponse(final Exception e, final UriInfo uriInfo) {
+ // Log the full stacktrace
+ log.warn("Not found", e);
return buildNotFoundResponse(e.toString(), uriInfo);
}
@@ -53,6 +57,8 @@ public abstract class ExceptionMapperBase {
}
protected Response buildBadRequestResponse(final Exception e, final UriInfo uriInfo) {
+ // Log the full stacktrace
+ log.warn("Bad request", e);
return buildBadRequestResponse(e.toString(), uriInfo);
}
@@ -65,6 +71,8 @@ public abstract class ExceptionMapperBase {
}
protected Response buildInternalErrorResponse(final Exception e, final UriInfo uriInfo) {
+ // Log the full stacktrace
+ log.warn("Internal error", e);
return buildInternalErrorResponse(e.toString(), uriInfo);
}
diff --git a/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/AccountResource.java b/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/AccountResource.java
index c2621ff..ff6a5fe 100644
--- a/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/AccountResource.java
+++ b/jaxrs/src/main/java/com/ning/billing/jaxrs/resources/AccountResource.java
@@ -259,7 +259,9 @@ public class AccountResource extends JaxRsResourceBase {
final Map<UUID, List<AuditLog>> chargebacksAuditLogs = new HashMap<UUID, List<AuditLog>>();
final Multimap<UUID, InvoicePayment> chargebacksByPayment = ArrayListMultimap.<UUID, InvoicePayment>create();
for (final InvoicePayment chargeback : chargebacks) {
- chargebacksAuditLogs.put(chargeback.getId(), auditUserApi.getAuditLogs(chargeback.getId(), ObjectType.INVOICE_PAYMENT));
+ if (withAudit) {
+ chargebacksAuditLogs.put(chargeback.getId(), auditUserApi.getAuditLogs(chargeback.getId(), ObjectType.INVOICE_PAYMENT));
+ }
chargebacksByPayment.put(chargeback.getPaymentId(), chargeback);
}
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestChargebackCollectionJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestChargebackCollectionJson.java
index af4c8c6..d58c565 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestChargebackCollectionJson.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestChargebackCollectionJson.java
@@ -17,6 +17,7 @@
package com.ning.billing.jaxrs.json;
import java.math.BigDecimal;
+import java.util.List;
import java.util.UUID;
import org.joda.time.DateTime;
@@ -24,13 +25,15 @@ import org.joda.time.DateTimeZone;
import org.testng.Assert;
import org.testng.annotations.Test;
+import com.ning.billing.jaxrs.JaxrsTestSuite;
+
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.google.common.collect.ImmutableList;
-import com.ning.billing.jaxrs.JaxrsTestSuite;
public class TestChargebackCollectionJson extends JaxrsTestSuite {
+
private static final ObjectMapper mapper = new ObjectMapper();
static {
@@ -45,22 +48,18 @@ public class TestChargebackCollectionJson extends JaxrsTestSuite {
final BigDecimal chargebackAmount = BigDecimal.TEN;
final String paymentId = UUID.randomUUID().toString();
final String reason = UUID.randomUUID().toString();
- final ChargebackJson chargebackJson = new ChargebackJson(requestedDate, effectiveDate, chargebackAmount, paymentId, reason);
+ final List<AuditLogJson> auditLogs = createAuditLogsJson();
+ final ChargebackJson chargebackJson = new ChargebackJson(requestedDate, effectiveDate, chargebackAmount, paymentId,
+ reason, auditLogs);
final String accountId = UUID.randomUUID().toString();
final ChargebackCollectionJson chargebackCollectionJson = new ChargebackCollectionJson(accountId, ImmutableList.<ChargebackJson>of(chargebackJson));
Assert.assertEquals(chargebackCollectionJson.getAccountId(), accountId);
Assert.assertEquals(chargebackCollectionJson.getChargebacks().size(), 1);
Assert.assertEquals(chargebackCollectionJson.getChargebacks().get(0), chargebackJson);
+ Assert.assertEquals(chargebackCollectionJson.getChargebacks().get(0).getAuditLogs(), auditLogs);
final String asJson = mapper.writeValueAsString(chargebackCollectionJson);
- Assert.assertEquals(asJson, "{\"accountId\":\"" + accountId + "\",\"chargebacks\":[" +
- "{\"requestedDate\":\"" + chargebackJson.getRequestedDate() + "\"," +
- "\"effectiveDate\":\"" + chargebackJson.getEffectiveDate() + "\"," +
- "\"chargebackAmount\":" + chargebackJson.getChargebackAmount() + "," +
- "\"paymentId\":\"" + chargebackJson.getPaymentId() + "\"," +
- "\"reason\":\"" + chargebackJson.getReason() + "\"}]}");
-
final ChargebackCollectionJson fromJson = mapper.readValue(asJson, ChargebackCollectionJson.class);
Assert.assertEquals(fromJson, chargebackCollectionJson);
}
diff --git a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestChargebackJson.java b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestChargebackJson.java
index 006582d..b6d0b5e 100644
--- a/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestChargebackJson.java
+++ b/jaxrs/src/test/java/com/ning/billing/jaxrs/json/TestChargebackJson.java
@@ -17,6 +17,7 @@
package com.ning.billing.jaxrs.json;
import java.math.BigDecimal;
+import java.util.List;
import java.util.UUID;
import org.joda.time.DateTime;
@@ -44,20 +45,17 @@ public class TestChargebackJson extends JaxrsTestSuite {
final BigDecimal chargebackAmount = BigDecimal.TEN;
final String paymentId = UUID.randomUUID().toString();
final String reason = UUID.randomUUID().toString();
- final ChargebackJson chargebackJson = new ChargebackJson(requestedDate, effectiveDate, chargebackAmount, paymentId, reason);
+ final List<AuditLogJson> auditLogs = createAuditLogsJson();
+ final ChargebackJson chargebackJson = new ChargebackJson(requestedDate, effectiveDate, chargebackAmount, paymentId,
+ reason, auditLogs);
Assert.assertEquals(chargebackJson.getRequestedDate(), requestedDate);
Assert.assertEquals(chargebackJson.getEffectiveDate(), effectiveDate);
Assert.assertEquals(chargebackJson.getChargebackAmount(), chargebackAmount);
Assert.assertEquals(chargebackJson.getPaymentId(), paymentId);
Assert.assertEquals(chargebackJson.getReason(), reason);
+ Assert.assertEquals(chargebackJson.getAuditLogs(), auditLogs);
final String asJson = mapper.writeValueAsString(chargebackJson);
- Assert.assertEquals(asJson, "{\"requestedDate\":\"" + chargebackJson.getRequestedDate() + "\"," +
- "\"effectiveDate\":\"" + chargebackJson.getEffectiveDate() + "\"," +
- "\"chargebackAmount\":" + chargebackJson.getChargebackAmount() + "," +
- "\"paymentId\":\"" + chargebackJson.getPaymentId() + "\"," +
- "\"reason\":\"" + chargebackJson.getReason() + "\"}");
-
final ChargebackJson fromJson = mapper.readValue(asJson, ChargebackJson.class);
Assert.assertEquals(fromJson, chargebackJson);
}
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestChargeback.java b/server/src/test/java/com/ning/billing/jaxrs/TestChargeback.java
index c20e0fe..c472456 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestChargeback.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestChargeback.java
@@ -52,7 +52,7 @@ public class TestChargeback extends TestJaxrsBase {
@Test(groups = "slow")
public void testAddChargeback() throws Exception {
final PaymentJsonSimple payment = createAccountWithInvoiceAndPayment();
- final ChargebackJson input = new ChargebackJson(null, null, BigDecimal.TEN, payment.getPaymentId(), null);
+ final ChargebackJson input = new ChargebackJson(null, null, BigDecimal.TEN, payment.getPaymentId(), null, null);
final String jsonInput = mapper.writeValueAsString(input);
// Create the chargeback
@@ -81,7 +81,7 @@ public class TestChargeback extends TestJaxrsBase {
final PaymentJsonSimple payment = createAccountWithInvoiceAndPayment();
// We get a 249.95 payment so we do 4 chargeback and then the fifth should fail
- final ChargebackJson input = new ChargebackJson(null, null, new BigDecimal("50.00"), payment.getPaymentId(), null);
+ final ChargebackJson input = new ChargebackJson(null, null, new BigDecimal("50.00"), payment.getPaymentId(), null, null);
final String jsonInput = mapper.writeValueAsString(input);
//
@@ -135,7 +135,8 @@ public class TestChargeback extends TestJaxrsBase {
@Test(groups = "slow")
public void testInvoicePaymentDoesNotExist() throws Exception {
final ChargebackJson input = new ChargebackJson(new DateTime(DateTimeZone.UTC), new DateTime(DateTimeZone.UTC),
- BigDecimal.TEN, UUID.randomUUID().toString(), UUID.randomUUID().toString());
+ BigDecimal.TEN, UUID.randomUUID().toString(), UUID.randomUUID().toString(),
+ null);
final String jsonInput = mapper.writeValueAsString(input);
// Try to create the chargeback
@@ -145,7 +146,7 @@ public class TestChargeback extends TestJaxrsBase {
@Test(groups = "slow")
public void testBadRequest() throws Exception {
- final ChargebackJson input = new ChargebackJson(null, null, null, null, null);
+ final ChargebackJson input = new ChargebackJson(null, null, null, null, null, null);
final String jsonInput = mapper.writeValueAsString(input);
// Try to create the chargeback
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestPayment.java b/server/src/test/java/com/ning/billing/jaxrs/TestPayment.java
index 0afc6b8..2b16d3f 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestPayment.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestPayment.java
@@ -92,7 +92,7 @@ public class TestPayment extends TestJaxrsBase {
// Issue the refund
- final RefundJson refundJson = new RefundJson(null, paymentId, paymentAmount, false, null, null);
+ final RefundJson refundJson = new RefundJson(null, paymentId, paymentAmount, false, null, null, null);
baseJson = mapper.writeValueAsString(refundJson);
response = doPost(uri, baseJson, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
assertEquals(response.getStatusCode(), Status.CREATED.getStatusCode());