use of org.killbill.billing.client.model.gen.Invoice in project killbill by killbill.
the class TestInvoice method testInvoicesPagination.
@Test(groups = "slow", description = "Can paginate and search through all invoices")
public void testInvoicesPagination() throws Exception {
createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
for (int i = 0; i < 3; i++) {
callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
clock.addMonths(1);
callbackServlet.assertListenerStatus();
}
final Invoices allInvoices = invoiceApi.getInvoices(requestOptions);
Assert.assertEquals(allInvoices.size(), 5);
for (final Invoice invoice : allInvoices) {
Assert.assertEquals(invoiceApi.searchInvoices(invoice.getInvoiceId().toString(), requestOptions).size(), 1);
Assert.assertEquals(invoiceApi.searchInvoices(invoice.getAccountId().toString(), requestOptions).size(), 5);
Assert.assertEquals(invoiceApi.searchInvoices(invoice.getInvoiceNumber().toString(), requestOptions).size(), 1);
Assert.assertEquals(invoiceApi.searchInvoices(invoice.getCurrency().toString(), requestOptions).size(), 5);
}
Invoices page = invoiceApi.getInvoices(0L, 1L, AuditLevel.NONE, requestOptions);
for (int i = 0; i < 5; i++) {
Assert.assertNotNull(page);
Assert.assertEquals(page.size(), 1);
Assert.assertEquals(page.get(0), allInvoices.get(i));
page = page.getNext();
}
Assert.assertNull(page);
}
use of org.killbill.billing.client.model.gen.Invoice in project killbill by killbill.
the class TestExternalRefund method testManualPaymentAndExternalRefundWithAdjustments.
@Test(groups = "slow", description = "#255 - Scenario 1 - Can refund a manual payment though an external refund over item adjustments")
public void testManualPaymentAndExternalRefundWithAdjustments() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account accountJson = createAccountWithExternalPMBundleAndSubscriptionAndManualPayTagAndWaitForFirstInvoice();
final Invoices invoicesForAccount = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
final Invoice unpaidInvoice = invoicesForAccount.get(1);
assertEquals(unpaidInvoice.getBalance().compareTo(BigDecimal.valueOf(249.95)), 0);
final Payments paymentsForAccount = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(paymentsForAccount.size(), 0);
final InvoicePayment invoicePaymentRequest = new InvoicePayment();
invoicePaymentRequest.setTargetInvoiceId(unpaidInvoice.getInvoiceId());
invoicePaymentRequest.setAccountId(accountJson.getAccountId());
invoicePaymentRequest.setCurrency(unpaidInvoice.getCurrency());
invoicePaymentRequest.setPurchasedAmount(unpaidInvoice.getAmount());
final InvoicePayment invoicePayment = invoiceApi.createInstantPayment(unpaidInvoice.getInvoiceId(), invoicePaymentRequest, true, ImmutableList.of(), NULL_PLUGIN_PROPERTIES, requestOptions);
assertEquals(invoicePayment.getPurchasedAmount().compareTo(BigDecimal.valueOf(249.95)), 0);
assertEquals(invoicePayment.getRefundedAmount().compareTo(BigDecimal.ZERO), 0);
final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
invoicePaymentTransactionRequest.setPaymentId(invoicePayment.getPaymentId());
invoicePaymentTransactionRequest.setIsAdjusted(true);
invoicePaymentTransactionRequest.setAdjustments(unpaidInvoice.getItems());
final InvoicePayment invoicePaymentRefund = invoicePaymentApi.createRefundWithAdjustments(invoicePayment.getPaymentId(), invoicePaymentTransactionRequest, false, null, NULL_PLUGIN_PROPERTIES, requestOptions);
assertNotNull(invoicePaymentRefund);
assertSingleInvoicePaymentRefund(invoicePaymentRefund);
assertRefundInvoiceAdjustments(accountJson.getAccountId());
assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.ZERO, BigDecimal.ZERO);
}
use of org.killbill.billing.client.model.gen.Invoice in project killbill by killbill.
the class TestExternalRefund method assertRefundInvoiceAdjustments.
private void assertRefundInvoiceAdjustments(final UUID accountId) throws KillBillClientException {
final Invoices invoices;
invoices = accountApi.getInvoicesForAccount(accountId, null, null, true, false, false, null, AuditLevel.NONE, requestOptions);
final Invoice invoiceWithRefund = invoices.get(1);
assertEquals(invoiceWithRefund.getAmount().compareTo(BigDecimal.ZERO), 0);
assertEquals(invoiceWithRefund.getRefundAdj().compareTo(BigDecimal.valueOf(249.95).negate()), 0);
assertEquals(invoiceWithRefund.getItems().size(), 2);
assertEquals(invoiceWithRefund.getItems().get(0).getItemType(), InvoiceItemType.RECURRING);
assertEquals(invoiceWithRefund.getItems().get(0).getAmount().compareTo(BigDecimal.valueOf(249.95)), 0);
assertEquals(invoiceWithRefund.getItems().get(1).getItemType(), InvoiceItemType.ITEM_ADJ);
assertEquals(invoiceWithRefund.getItems().get(1).getAmount().compareTo(BigDecimal.valueOf(249.95).negate()), 0);
}
use of org.killbill.billing.client.model.gen.Invoice in project killbill by killbill.
the class TestExternalRefund method assertRefundInvoiceNoAdjustments.
private void assertRefundInvoiceNoAdjustments(final UUID accountId) throws KillBillClientException {
final Invoices invoices = accountApi.getInvoicesForAccount(accountId, null, null, true, false, false, null, AuditLevel.NONE, requestOptions);
final Invoice invoiceWithRefund = invoices.get(1);
assertEquals(invoiceWithRefund.getAmount().compareTo(BigDecimal.valueOf(249.95)), 0);
assertEquals(invoiceWithRefund.getRefundAdj().compareTo(BigDecimal.valueOf(249.95).negate()), 0);
assertEquals(invoiceWithRefund.getItems().size(), 1);
assertEquals(invoiceWithRefund.getItems().get(0).getItemType(), InvoiceItemType.RECURRING);
assertEquals(invoiceWithRefund.getItems().get(0).getAmount().compareTo(BigDecimal.valueOf(249.95)), 0);
}
use of org.killbill.billing.client.model.gen.Invoice in project killbill by killbill.
the class TestInvoiceVoid method testChildVoidInvoice.
@Test(groups = "slow", description = "Void a child invoice")
public void testChildVoidInvoice() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
final LocalDate triggeredDate = new LocalDate(2012, 5, 26);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account parentAccount = createAccount();
final Account childAccount1 = createAccount(parentAccount.getAccountId());
// Add a bundle and subscription
createSubscription(childAccount1.getAccountId(), UUID.randomUUID().toString(), "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
// trigger an invoice generation
callbackServlet.pushExpectedEvent(ExtBusEventType.INVOICE_CREATION);
invoiceApi.createFutureInvoice(childAccount1.getAccountId(), triggeredDate, requestOptions);
callbackServlet.assertListenerStatus();
List<Invoice> child1Invoices = accountApi.getInvoicesForAccount(childAccount1.getAccountId(), null, null, false, false, true, null, AuditLevel.NONE, requestOptions);
assertEquals(child1Invoices.size(), 2);
// move one day so that the parent invoice is committed
callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_FAILED);
clock.addDays(1);
callbackServlet.assertListenerStatus();
List<Invoice> parentInvoices = accountApi.getInvoicesForAccount(parentAccount.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
assertEquals(parentInvoices.size(), 1);
// try to void child invoice
callbackServlet.pushExpectedEvent(ExtBusEventType.INVOICE_ADJUSTMENT);
invoiceApi.voidInvoice(child1Invoices.get(1).getInvoiceId(), requestOptions);
callbackServlet.assertListenerStatus();
// move the clock 1 month to check if invoices change
callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION, // Overdue state is computed from the parent state
ExtBusEventType.OVERDUE_CHANGE, ExtBusEventType.BLOCKING_STATE, ExtBusEventType.OVERDUE_CHANGE, ExtBusEventType.BLOCKING_STATE);
clock.addDays(31);
callbackServlet.assertListenerStatus();
// The parent added another invoice, now it has two (duplicate)
parentInvoices = accountApi.getInvoicesForAccount(parentAccount.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
assertEquals(parentInvoices.size(), 2);
// the child added one invoice as expected
child1Invoices = accountApi.getInvoicesForAccount(childAccount1.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
assertEquals(child1Invoices.size(), 2);
}
Aggregations