use of org.killbill.billing.client.model.gen.InvoiceItem in project killbill by killbill.
the class TestInvoicePayment method testPartialRefundWithFullInvoiceItemAdjustment.
@Test(groups = "slow", description = "Cannot create invoice item adjustments for more than the refund amount")
public void testPartialRefundWithFullInvoiceItemAdjustment() throws Exception {
final InvoicePayment paymentJson = setupScenarioWithPayment(true);
// Get the individual items for the invoice
final Invoice invoice = invoiceApi.getInvoice(paymentJson.getTargetInvoiceId(), false, AuditLevel.NONE, requestOptions);
final InvoiceItem itemToAdjust = invoice.getItems().get(0);
// Issue a refund for a fraction of the amount
final BigDecimal refundAmount = getFractionOfAmount(itemToAdjust.getAmount());
final BigDecimal expectedInvoiceBalance = invoice.getBalance();
// Post and verify the refund
final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
refund.setPaymentId(paymentJson.getPaymentId());
refund.setAmount(refundAmount);
refund.setIsAdjusted(true);
final InvoiceItem adjustment = new InvoiceItem();
adjustment.setInvoiceItemId(itemToAdjust.getInvoiceItemId());
// Ask for an adjustment for the full amount (bigger than the refund amount)
adjustment.setAmount(itemToAdjust.getAmount());
refund.setAdjustments(ImmutableList.<InvoiceItem>of(adjustment));
invoicePaymentApi.createRefundWithAdjustments(paymentJson.getPaymentId(), refund, paymentJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
final Payment paymentAfterRefundJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
// The refund did go through
verifyRefund(paymentJson, paymentAfterRefundJson, refundAmount);
// But not the adjustments
verifyInvoice(paymentJson, expectedInvoiceBalance);
}
use of org.killbill.billing.client.model.gen.InvoiceItem in project killbill by killbill.
the class TestInvoicePayment method testRefundWithFullInvoiceItemAdjustment.
@Test(groups = "slow", description = "Can create a full refund with invoice item adjustment")
public void testRefundWithFullInvoiceItemAdjustment() throws Exception {
final InvoicePayment paymentJson = setupScenarioWithPayment(true);
// Get the individual items for the invoice
final Invoice invoice = invoiceApi.getInvoice(paymentJson.getTargetInvoiceId(), false, AuditLevel.NONE, requestOptions);
final InvoiceItem itemToAdjust = invoice.getItems().get(0);
// Issue a refund for the full amount
final BigDecimal refundAmount = itemToAdjust.getAmount();
final BigDecimal expectedInvoiceBalance = BigDecimal.ZERO;
// Post and verify the refund
final InvoicePaymentTransaction refund = new InvoicePaymentTransaction();
refund.setPaymentId(paymentJson.getPaymentId());
refund.setAmount(refundAmount);
refund.setIsAdjusted(true);
final InvoiceItem adjustment = new InvoiceItem();
adjustment.setInvoiceItemId(itemToAdjust.getInvoiceItemId());
// null amount means full adjustment for that item
refund.setAdjustments(ImmutableList.<InvoiceItem>of(adjustment));
invoicePaymentApi.createRefundWithAdjustments(paymentJson.getPaymentId(), refund, paymentJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
final Payment paymentAfterRefundJson = paymentApi.getPayment(paymentJson.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
verifyRefund(paymentJson, paymentAfterRefundJson, refundAmount);
// Verify the invoice balance
verifyInvoice(paymentJson, expectedInvoiceBalance);
}
Aggregations