From 68b09c2bfa0cc9c5d085962e9c4ab233a09db67f Mon Sep 17 00:00:00 2001 From: Paulo Pinho Date: Fri, 26 Jul 2024 18:31:50 -0300 Subject: [PATCH] Refund changes Adds percentage to refund amount, also adds percentage and amount_in_cents to individual adjustments. --- .../recurly/model/AdjustmentRefund.java | 32 +++++++++++++++++++ .../billing/recurly/model/InvoiceRefund.java | 21 +++++++++++- .../billing/recurly/TestRecurlyClient.java | 26 +++++++++++++-- 3 files changed, 76 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ning/billing/recurly/model/AdjustmentRefund.java b/src/main/java/com/ning/billing/recurly/model/AdjustmentRefund.java index 12b4cc66f..7049f9248 100644 --- a/src/main/java/com/ning/billing/recurly/model/AdjustmentRefund.java +++ b/src/main/java/com/ning/billing/recurly/model/AdjustmentRefund.java @@ -35,6 +35,12 @@ public class AdjustmentRefund extends RecurlyObject { @XmlElement(name = "quantity_decimal") private BigDecimal quantityDecimal; + @XmlElement(name = "percentage") + private Integer percentage; + + @XmlElement(name = "amount_in_cents") + private Integer amountInCents; + @XmlElement(name = "prorate") private Boolean prorate; @@ -46,6 +52,22 @@ public void setUuid(final Object uuid) { this.uuid = stringOrNull(uuid); } + public void setAmountInCents(final Object amountInCents) { + this.amountInCents = integerOrNull(amountInCents); + } + + public Integer getAmountInCents() { + return this.amountInCents; + } + + public void setPercentage(final Object percentage) { + this.percentage = integerOrNull(percentage); + } + + public Integer getPercentage() { + return this.percentage; + } + public Integer getQuantity() { return quantity; } @@ -77,6 +99,8 @@ public String toString() { sb.append("{uuid='").append(uuid).append('\''); sb.append(", quantity=").append(quantity); sb.append(", quantity_decimal=").append(quantityDecimal); + sb.append(", percentage=").append(percentage); + sb.append(", amountInCents=").append(amountInCents); sb.append(", prorate=").append(prorate); sb.append('}'); return sb.toString(); @@ -98,6 +122,12 @@ public boolean equals(final Object o) { if (quantityDecimal != null ? !quantityDecimal.equals(that.quantityDecimal) : that.quantityDecimal != null) { return false; } + if (amountInCents != null ? !amountInCents.equals(that.amountInCents) : that.amountInCents != null) { + return false; + } + if (percentage != null ? !percentage.equals(that.percentage) : that.percentage != null) { + return false; + } if (uuid != null ? !uuid.equals(that.uuid) : that.uuid != null) { return false; } @@ -111,6 +141,8 @@ public int hashCode() { prorate, quantity, quantityDecimal, + amountInCents, + percentage, uuid ); } diff --git a/src/main/java/com/ning/billing/recurly/model/InvoiceRefund.java b/src/main/java/com/ning/billing/recurly/model/InvoiceRefund.java index 09900c120..5cecba324 100644 --- a/src/main/java/com/ning/billing/recurly/model/InvoiceRefund.java +++ b/src/main/java/com/ning/billing/recurly/model/InvoiceRefund.java @@ -33,6 +33,9 @@ public class InvoiceRefund extends RecurlyObject { @XmlElement(name = "amount_in_cents") private Integer amountInCents; + @XmlElement(name = "percentage") + private Integer percentage; + @XmlElementWrapper(name = "line_items") @XmlElement(name = "adjustment") private List lineItems; @@ -68,6 +71,14 @@ public Integer getAmountInCents() { return this.amountInCents; } + public void setPercentage(final Object percentage) { + this.percentage = integerOrNull(percentage); + } + + public Integer getPercentage() { + return this.percentage; + } + public void setLineItems(final List lineItems) { this.lineItems = lineItems; } @@ -118,7 +129,11 @@ public DateTime getRefundedAt() { @Override public int hashCode() { - return Objects.hashCode(refundMethod, amountInCents); + return Objects.hashCode( + refundMethod, + amountInCents, + percentage + ); } @Override @@ -131,6 +146,9 @@ public boolean equals(final Object o) { if (amountInCents != null ? !amountInCents.equals(refund.amountInCents) : refund.amountInCents != null) { return false; } + if (percentage != null ? !percentage.equals(refund.percentage) : refund.percentage != null) { + return false; + } if (externalRefund != null ? !externalRefund.equals(refund.externalRefund) : refund.externalRefund != null) { return false; } @@ -155,6 +173,7 @@ public boolean equals(final Object o) { @Override public String toString() { final StringBuilder sb = new StringBuilder("InvoiceRefund{"); + sb.append("percentage=").append(percentage); sb.append("amountInCents=").append(amountInCents); sb.append(", refundMethod='").append(refundMethod).append('\''); sb.append(", externalRefund='").append(externalRefund).append('\''); diff --git a/src/test/java/com/ning/billing/recurly/TestRecurlyClient.java b/src/test/java/com/ning/billing/recurly/TestRecurlyClient.java index 919ee1358..e5d485674 100644 --- a/src/test/java/com/ning/billing/recurly/TestRecurlyClient.java +++ b/src/test/java/com/ning/billing/recurly/TestRecurlyClient.java @@ -2036,10 +2036,23 @@ public void testInvoices() throws Exception { Assert.assertEquals(refundInvoice.getSubtotalInCents(), new Integer(-100)); Assert.assertEquals(refundInvoice.getTransactions().get(0).getAction(), "refund"); + final InvoiceRefund refundOptions2 = new InvoiceRefund(); + refundOptions2.setRefundMethod(RefundMethod.transaction_first); + refundOptions2.setPercentage(100); + refundOptions2.setCreditCustomerNotes("Credit Customer Notes"); + refundOptions2.setExternalRefund(true); + refundOptions2.setPaymentMethod("credit_card"); + final Invoice refundInvoice2 = recurlyClient.refundInvoice(invoice.getId(), refundOptions2); + + Assert.assertEquals(refundInvoice.getTotalInCents(), new Integer(-100)); + Assert.assertEquals(refundInvoice.getSubtotalInCents(), new Integer(-100)); + Assert.assertEquals(refundInvoice.getTransactions().get(0).getAction(), "refund"); + // The refundInvoice should have an original_invoices of the original invoice final Invoices originalInvoices = recurlyClient.getOriginalInvoices(refundInvoice.getId()); Assert.assertEquals(originalInvoices.get(0).getId(), invoice.getId()); } finally { + Thread.sleep(5000); recurlyClient.closeAccount(accountData.getAccountCode()); recurlyClient.deletePlan(planData.getPlanCode()); } @@ -2073,12 +2086,19 @@ public void testLineItemInvoiceRefund() throws Exception { recurlyClient.createAccountAdjustment(account.getAccountCode(), adjustmentData2); + final Adjustment adjustmentData3 = new Adjustment(); + adjustmentData3.setCurrency("USD"); + adjustmentData3.setUnitAmountInCents(50); + adjustmentData3.setDescription("A description of an account adjustment3"); + + recurlyClient.createAccountAdjustment(account.getAccountCode(), adjustmentData3); + final Invoice invoiceData = new Invoice(); invoiceData.setCollectionMethod("automatic"); Invoice invoice = recurlyClient.postAccountInvoice(account.getAccountCode(), invoiceData).getChargeInvoice(); - Assert.assertEquals(invoice.getTotalInCents(), new Integer(200)); + Assert.assertEquals(invoice.getTotalInCents(), new Integer(250)); // wait for the invoice to be marked paid // has to happen asynchronously on the server @@ -2092,10 +2112,12 @@ public void testLineItemInvoiceRefund() throws Exception { // let's just refund the first adjustment // we can use "toAdjustmentRefund" on the adjustment to turn it // into an AdjustmentRefund - final AdjustmentRefund adjustmentRefund = invoice.getLineItems().get(0).toAdjustmentRefund(); + final AdjustmentRefund adjustmentRefund = new AdjustmentRefund(); + adjustmentRefund.setUuid(invoice.getLineItems().get(0).getUuid()); // we could change the quantity here or the prorating settings if we want, defaults to full quantity // adjustmentRefund.setQuantity(1); + adjustmentRefund.setPercentage(100); lineItems.add(adjustmentRefund); final InvoiceRefund refundOptions = new InvoiceRefund();