use of org.killbill.billing.client.model.Invoices in project killbill by killbill.
the class TestInvoice method testGetInvoicesWithFilters.
@Test(groups = "slow")
public void testGetInvoicesWithFilters() throws Exception {
final DateTime initialDate = new DateTime(2021, 4, 18, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
Invoices invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.FULL, requestOptions);
assertEquals(invoices.size(), 2);
final String invoiceId1 = invoices.get(0).getInvoiceId().toString();
final String invoiceId2 = invoices.get(1).getInvoiceId().toString();
// Filter on dates only
invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), new LocalDate(2021, 4, 18), new LocalDate(2021, 5, 18), false, false, false, null, AuditLevel.FULL, requestOptions);
assertEquals(invoices.size(), 2);
invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), new LocalDate(2021, 4, 18), new LocalDate(2021, 5, 17), false, false, false, null, AuditLevel.FULL, requestOptions);
assertEquals(invoices.size(), 1);
invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), new LocalDate(2021, 4, 19), new LocalDate(2021, 5, 18), false, false, false, null, AuditLevel.FULL, requestOptions);
assertEquals(invoices.size(), 1);
invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), new LocalDate(2021, 4, 19), new LocalDate(2021, 5, 17), false, false, false, null, AuditLevel.FULL, requestOptions);
assertEquals(invoices.size(), 0);
invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), new LocalDate(2021, 4, 19), new LocalDate(2021, 5, 17), false, false, false, null, AuditLevel.FULL, requestOptions);
assertEquals(invoices.size(), 0);
// Filter on invoiceIds only
String idFilter = Strings.join(",", new String[] { invoiceId1, invoiceId2 });
invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, idFilter, AuditLevel.FULL, requestOptions);
assertEquals(invoices.size(), 2);
idFilter = invoiceId1;
invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, idFilter, AuditLevel.FULL, requestOptions);
assertEquals(invoices.size(), 1);
// Dates and id filter
idFilter = Strings.join(",", new String[] { invoiceId1, invoiceId2 });
invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), new LocalDate(2021, 4, 18), new LocalDate(2021, 5, 17), false, false, false, idFilter, AuditLevel.FULL, requestOptions);
assertEquals(invoices.size(), 1);
idFilter = invoiceId1;
invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), new LocalDate(2021, 4, 18), new LocalDate(2021, 5, 17), false, false, false, idFilter, AuditLevel.FULL, requestOptions);
assertEquals(invoices.size(), 1);
idFilter = invoiceId2;
invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), new LocalDate(2021, 4, 18), new LocalDate(2021, 5, 17), false, false, false, idFilter, AuditLevel.FULL, requestOptions);
assertEquals(invoices.size(), 0);
}
use of org.killbill.billing.client.model.Invoices in project killbill by killbill.
the class TestInvoice method testInvoiceOk.
@Test(groups = "slow", description = "Can search and retrieve invoices with and without items")
public void testInvoiceOk() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
final Invoices invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.FULL, requestOptions);
assertEquals(invoices.size(), 2);
for (final Invoice invoiceJson : invoices) {
Assert.assertEquals(invoiceJson.getAuditLogs().size(), 1);
final AuditLog auditLogJson = invoiceJson.getAuditLogs().get(0);
Assert.assertEquals(auditLogJson.getChangeType(), "INSERT");
Assert.assertEquals(auditLogJson.getChangedBy(), "SubscriptionBaseTransition");
Assert.assertFalse(auditLogJson.getChangeDate().isBefore(initialDate));
Assert.assertNotNull(auditLogJson.getUserToken());
Assert.assertNull(auditLogJson.getReasonCode());
Assert.assertNull(auditLogJson.getComments());
}
final Invoice invoiceJson = invoices.get(0);
assertEquals(invoiceJson.getItems().size(), 1);
final InvoiceItem invoiceItem = invoiceJson.getItems().get(0);
assertEquals(invoiceItem.getProductName(), "Shotgun");
assertEquals(invoiceItem.getPrettyProductName(), "Shotgun");
assertEquals(invoiceItem.getPlanName(), "shotgun-monthly");
assertEquals(invoiceItem.getPrettyPlanName(), "Shotgun Monthly");
assertEquals(invoiceItem.getPhaseName(), "shotgun-monthly-trial");
assertEquals(invoiceItem.getPrettyPhaseName(), "shotgun-monthly-trial");
// Check item is correctly returned with catalog effective date
assertEquals(invoiceItem.getCatalogEffectiveDate().compareTo(ISODateTimeFormat.dateTimeParser().parseDateTime("2011-01-01T00:00:00+00:00")), 0);
assertEquals(invoiceApi.getInvoice(invoiceJson.getInvoiceId(), Boolean.TRUE, AuditLevel.NONE, requestOptions).getItems().size(), invoiceJson.getItems().size());
assertEquals(invoiceApi.getInvoiceByNumber(Integer.valueOf(invoiceJson.getInvoiceNumber()), Boolean.FALSE, AuditLevel.NONE, requestOptions).getItems().size(), invoiceJson.getItems().size());
assertEquals(invoiceApi.getInvoiceByItemId(invoiceItem.getInvoiceItemId(), false, AuditLevel.NONE, requestOptions).getItems().size(), invoiceJson.getItems().size());
// Check we can retrieve an individual invoice
final Invoice firstInvoice = invoiceApi.getInvoice(invoiceJson.getInvoiceId(), false, AuditLevel.FULL, requestOptions);
assertEquals(firstInvoice, invoiceJson);
// Check we can retrieve the invoice by number
final Invoice firstInvoiceByNumberJson = invoiceApi.getInvoiceByNumber(Integer.valueOf(invoiceJson.getInvoiceNumber()), false, AuditLevel.FULL, requestOptions);
assertEquals(firstInvoiceByNumberJson, invoiceJson);
// Check we can retrieve the HTML version
final String htmlInvoice = invoiceApi.getInvoiceAsHTML(invoiceJson.getInvoiceId(), requestOptions);
// Disabled this test as different output is produced by Java 8 and Java 11.
// assertEquals(htmlInvoice,"<!doctype html>\r\n" +
// "<html>\r\n" +
// "<head>\r\n" +
// " <meta charset=\"utf-8\">\r\n" +
// " <title>invoiceTitle</title>\r\n" +
// " <style>\r\n" +
// " /*!\r\n" +
// " * https://www.sparksuite.com/open-source/invoice.html\r\n" +
// " * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)\r\n" +
// " */\r\n" +
// " .invoice-box{max-width:800px;margin:auto;padding:30px;border:1px solid #eee;box-shadow:0 0 10px rgba(0,0,0,.15);font-size:16px;line-height:24px;font-family:'Helvetica Neue',Helvetica,Helvetica,Arial,sans-serif;color:#555}.invoice-box table{width:100%;line-height:inherit;text-align:left}.invoice-box table td{padding:5px;vertical-align:top}.invoice-box table tr td:nth-child(3){text-align:right}.invoice-box table tr.top table td{padding-bottom:20px}.invoice-box table tr.top table td.title{font-size:45px;line-height:45px;color:#333}.invoice-box table tr.information table td{padding-bottom:40px}.invoice-box table tr.heading td{background:#eee;border-bottom:1px solid #ddd;font-weight:700}.invoice-box table tr.details td{padding-bottom:20px}.invoice-box table tr.item td{border-bottom:1px solid #eee}.invoice-box table tr.item.last td{border-bottom:none}.invoice-box table tr.total td:nth-child(3){border-top:2px solid #eee;font-weight:700}@media only screen and (max-width:600px){.invoice-box table tr.top table td{width:100%;display:block;text-align:center}.invoice-box table tr.information table td{width:100%;display:block;text-align:center}}.rtl{direction:rtl;font-family:Tahoma,'Helvetica Neue',Helvetica,Helvetica,Arial,sans-serif}.rtl table{text-align:right}.rtl table tr td:nth-child(3){text-align:left}\r\n" +
// " </style>\r\n" +
// "</head>\r\n" +
// "<body>\r\n" +
// "<div class=\"invoice-box\">\r\n" +
// " <table cellpadding=\"0\" cellspacing=\"0\">\r\n" +
// " <tr class=\"top\">\r\n" +
// " <td colspan=\"3\">\r\n" +
// " <table>\r\n" +
// " <tr>\r\n" +
// " <td class=\"title\">\r\n" +
// " <img src=\"https://raw.githubusercontent.com/killbill/killbill-docs/v3/userguide/assets/img/logo.png\" style=\"width:100%; max-width:300px;\">\r\n" +
// " </td>\r\n" +
// " <td></td>\r\n" +
// " <td>\r\n" +
// " invoiceTitle INV#"+invoiceJson.getInvoiceNumber()+"<br>\r\n" +
// " invoiceDate25 avr. 2012\r\n" +
// " </td>\r\n" +
// " </tr>\r\n" +
// " </table>\r\n" +
// " </td>\r\n" +
// " </tr>\r\n" +
// " <tr class=\"information\">\r\n" +
// " <td colspan=\"3\">\r\n" +
// " <table>\r\n" +
// " <tr>\r\n" +
// " <td>\r\n" +
// " companyName<br>\r\n" +
// " companyAddress<br>\r\n" +
// " companyCityProvincePostalCode<br>\r\n" +
// " companyCountry\r\n" +
// " </td>\r\n" +
// " <td></td>\r\n" +
// " <td>\r\n" +
// " "+accountJson.getName()+"<br>\r\n"+
// " Renault<br>\r\n" +
// " 12 rue des ecoles<br>\r\n" +
// " Quelque part, Poitou 44 567<br>\r\n" +
// " France\r\n" +
// " </td>\r\n" +
// " </tr>\r\n" +
// " </table>\r\n" +
// " </td>\r\n" +
// " </tr>\r\n" +
// " <tr class=\"heading\">\r\n" +
// " <td>invoiceItemServicePeriod</td>\r\n" +
// " <td>invoiceItemDescription</td>\r\n" +
// " <td>invoiceItemAmount</td>\r\n" +
// " </tr>\r\n" +
// " <tr class=\"item last\">\r\n" +
// " <td>25 avr. 2012</td>\r\n" +
// " <td>Shotgun Monthly</td>\r\n" +
// " <td>0,00 USD</td>\r\n" +
// " </tr>\r\n" +
// " <tr class=\"total\">\r\n" +
// " <td></td>\r\n" +
// " <td></td>\r\n" +
// " <td>invoiceAmount0,00 US$</td>\r\n" +
// " </tr>\r\n" +
// " <tr class=\"total\">\r\n" +
// " <td></td>\r\n" +
// " <td></td>\r\n" +
// " <td>invoiceAmountPaid0,00 US$</td>\r\n" +
// " </tr>\r\n" +
// " <tr class=\"total\">\r\n" +
// " <td></td>\r\n" +
// " <td></td>\r\n" +
// " <td>invoiceBalance0,00 US$</td>\r\n" +
// " </tr>\r\n" +
// " </table>\r\n" +
// "</div>\r\n" +
// "</body>\r\n" +
// "</html>"
// );
// Then create a dryRun for next upcoming invoice
final InvoiceDryRun dryRunArg = new InvoiceDryRun().setDryRunType(DryRunType.UPCOMING_INVOICE);
final Invoice dryRunInvoice = invoiceApi.generateDryRunInvoice(dryRunArg, accountJson.getAccountId(), null, requestOptions);
assertEquals(dryRunInvoice.getBalance(), new BigDecimal("249.95"));
assertEquals(dryRunInvoice.getTargetDate(), new LocalDate(2012, 6, 25));
assertEquals(dryRunInvoice.getItems().size(), 1);
assertEquals(dryRunInvoice.getItems().get(0).getStartDate(), new LocalDate(2012, 6, 25));
assertEquals(dryRunInvoice.getItems().get(0).getEndDate(), new LocalDate(2012, 7, 25));
assertEquals(dryRunInvoice.getItems().get(0).getAmount(), new BigDecimal("249.95"));
final LocalDate futureDate = dryRunInvoice.getTargetDate();
// The one more time with no DryRun
invoiceApi.createFutureInvoice(accountJson.getAccountId(), futureDate, requestOptions);
// Check again # invoices, should be 3 this time
final List<Invoice> newInvoiceList = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
assertEquals(newInvoiceList.size(), 3);
}
use of org.killbill.billing.client.model.Invoices in project killbill by killbill.
the class TestInvoice method testInvoiceTransferCreditToParentAccount.
@Test(groups = "slow", description = "Can transfer credit to parent account")
public void testInvoiceTransferCreditToParentAccount() throws Exception {
final Account parentAccount = createAccount();
final Account childAccount = createAccount(parentAccount.getAccountId());
final BigDecimal creditAmount = BigDecimal.TEN;
final InvoiceItem credit = new InvoiceItem();
credit.setAccountId(childAccount.getAccountId());
credit.setInvoiceId(null);
credit.setAmount(creditAmount);
// insert credit to child account
InvoiceItems credits = new InvoiceItems();
credits.add(credit);
final List<InvoiceItem> creditJsons = creditApi.createCredits(credits, true, NULL_PLUGIN_PROPERTIES, requestOptions);
Assert.assertEquals(creditJsons.size(), 1);
Invoices childInvoices = accountApi.getInvoicesForAccount(childAccount.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
Assert.assertEquals(childInvoices.size(), 1);
Assert.assertEquals(childInvoices.get(0).getCreditAdj().compareTo(BigDecimal.TEN), 0);
Invoices parentInvoices = accountApi.getInvoicesForAccount(parentAccount.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
Assert.assertEquals(parentInvoices.size(), 0);
// transfer credit to parent account
accountApi.transferChildCreditToParent(childAccount.getAccountId(), requestOptions);
childInvoices = accountApi.getInvoicesForAccount(childAccount.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
Assert.assertEquals(childInvoices.size(), 2);
Assert.assertEquals(childInvoices.get(1).getCreditAdj().compareTo(BigDecimal.TEN.negate()), 0);
parentInvoices = accountApi.getInvoicesForAccount(parentAccount.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
Assert.assertEquals(parentInvoices.size(), 1);
Assert.assertEquals(parentInvoices.get(0).getCreditAdj().compareTo(BigDecimal.TEN), 0);
}
use of org.killbill.billing.client.model.Invoices in project killbill by killbill.
the class TestInvoice method testGetTags.
@Test(groups = "slow", description = "Can get tags")
public void testGetTags() throws Exception {
final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
// Get the invoices
final Invoices originalInvoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
assertEquals(originalInvoices.size(), 2);
final UUID invoiceId = originalInvoices.get(0).getInvoiceId();
invoiceApi.createInvoiceTags(invoiceId, ImmutableList.<UUID>of(ControlTagType.WRITTEN_OFF.getId()), requestOptions);
final Tags tagsWithAudit = invoiceApi.getInvoiceTags(invoiceId, false, AuditLevel.FULL, requestOptions);
Assert.assertEquals(tagsWithAudit.size(), 1);
Assert.assertEquals(tagsWithAudit.get(0).getAuditLogs().size(), 1);
final Tags tagsNoAudit = invoiceApi.getInvoiceTags(invoiceId, false, AuditLevel.NONE, requestOptions);
Assert.assertEquals(tagsNoAudit.size(), 1);
Assert.assertEquals(tagsNoAudit.get(0).getTagId(), tagsWithAudit.get(0).getTagId());
Assert.assertEquals(tagsNoAudit.get(0).getAuditLogs().size(), 0);
}
use of org.killbill.billing.client.model.Invoices in project killbill by killbill.
the class TestEntitlement method testCreateChangeAndCancelSubscriptionWithAutoInvoicingDraft.
@Test(groups = "slow", description = "Can create an entitlement with an account with autoInvoicingDraft")
public void testCreateChangeAndCancelSubscriptionWithAutoInvoicingDraft() throws Exception {
final Account accountJson = createAccount();
assertNotNull(accountJson);
// assign AUTO_INVOICING_DRAFT tag to account
callbackServlet.pushExpectedEvents(ExtBusEventType.TAG_CREATION);
final Tags tags = accountApi.createAccountTags(accountJson.getAccountId(), ImmutableList.<UUID>of(new UUID(0L, 8L)), requestOptions);
assertEquals(tags.get(0).getTagDefinitionName(), "AUTO_INVOICING_DRAFT");
callbackServlet.assertListenerStatus();
// verify that number of invoices and payments for account is still 0
assertEquals(accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions).size(), 0);
assertEquals(accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions).size(), 0);
// create a subscription with no trial plan
final Subscription input = new Subscription();
input.setAccountId(accountJson.getAccountId());
input.setProductName("Blowdart");
input.setProductCategory(ProductCategory.BASE);
input.setBillingPeriod(BillingPeriod.MONTHLY);
input.setPriceList("notrial");
callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.SUBSCRIPTION_CREATION, ExtBusEventType.ENTITLEMENT_CREATION, // The BCD is updated in that case
ExtBusEventType.ACCOUNT_CHANGE);
final Subscription subscriptionJson = subscriptionApi.createSubscription(input, null, null, false, false, false, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, NULL_PLUGIN_PROPERTIES, requestOptions);
assertNotNull(subscriptionJson);
callbackServlet.assertListenerStatus();
// verify that number of invoices is 1 (DRAFT). Note that we have to poll because callCompletion will return
// before the DRAFT invoice is generated (there is no event to synchronize on)
Awaitility.await().atMost(10, TimeUnit.SECONDS).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
final Invoices invoicesForAccount = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
return invoicesForAccount.size() == 1 && invoicesForAccount.get(0).getStatus() == InvoiceStatus.DRAFT;
}
});
// verify that number of payments is still 0 (no attempts)
assertEquals(accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions).size(), 0);
// Avoid test timing issues
clock.addDays(1);
callbackServlet.assertListenerStatus();
// Change Plan
final Subscription newInput = new Subscription();
newInput.setSubscriptionId(subscriptionJson.getSubscriptionId());
newInput.setPlanName("pistol-monthly");
callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_CHANGE, ExtBusEventType.SUBSCRIPTION_CHANGE);
subscriptionApi.changeSubscriptionPlan(subscriptionJson.getSubscriptionId(), newInput, null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, BillingActionPolicy.IMMEDIATE, NULL_PLUGIN_PROPERTIES, requestOptions);
callbackServlet.assertListenerStatus();
// Avoid test timing issues
clock.addDays(1);
callbackServlet.assertListenerStatus();
// Cancel subscription (entitlement IMM, billing now() since the CTD is NULL)
callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.SUBSCRIPTION_CANCEL, ExtBusEventType.ENTITLEMENT_CANCEL);
subscriptionApi.cancelSubscriptionPlan(newInput.getSubscriptionId(), null, true, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, null, null, null, NULL_PLUGIN_PROPERTIES, requestOptions);
callbackServlet.assertListenerStatus();
}
Aggregations