use of org.killbill.billing.client.model.InvoiceDryRun 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 List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false, false, AuditLevel.FULL);
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);
// Check get with & without items
assertTrue(killBillClient.getInvoice(invoiceJson.getInvoiceId(), Boolean.FALSE).getItems().isEmpty());
assertTrue(killBillClient.getInvoice(invoiceJson.getInvoiceNumber(), Boolean.FALSE).getItems().isEmpty());
assertEquals(killBillClient.getInvoice(invoiceJson.getInvoiceId(), Boolean.TRUE).getItems().size(), invoiceJson.getItems().size());
assertEquals(killBillClient.getInvoice(invoiceJson.getInvoiceNumber(), Boolean.TRUE).getItems().size(), invoiceJson.getItems().size());
// Check we can retrieve an individual invoice
final Invoice firstInvoice = killBillClient.getInvoice(invoiceJson.getInvoiceId());
assertEquals(firstInvoice, invoiceJson);
// Check we can retrieve the invoice by number
final Invoice firstInvoiceByNumberJson = killBillClient.getInvoice(invoiceJson.getInvoiceNumber());
assertEquals(firstInvoiceByNumberJson, invoiceJson);
// Check we can retrieve the HTML version
final String htmlInvoice = killBillClient.getInvoiceAsHtml(invoiceJson.getInvoiceId());
assertEquals(htmlInvoice, "<html>\n" + " <head>\n" + " <style type=\"text/css\">\n" + " th {align=left; width=225px; border-bottom: solid 2px black;}\n" + " </style>\n" + " </head>\n" + " <body>\n" + " <h1>invoiceTitle</h1>\n" + " <table>\n" + " <tr>\n" + " <td rowspan=3 width=350px>Insert image here</td>\n" + " <td width=100px/>\n" + " <td width=225px/>\n" + " <td width=225px/>\n" + " </tr>\n" + " <tr>\n" + " <td />\n" + " <td align=right>invoiceDate</td>\n" + " <td>25 avr. 2012</td>\n" + " </tr>\n" + " <tr>\n" + " <td />\n" + " <td align=right>invoiceNumber</td>\n" + " <td>" + invoiceJson.getInvoiceNumber() + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td>companyName</td>\n" + " <td></td>\n" + " <td align=right>accountOwnerName</td>\n" + " <td>" + accountJson.getName() + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td>companyAddress</td>\n" + " <td />\n" + " <td />\n" + " <td>" + accountJson.getEmail() + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td>companyCityProvincePostalCode</td>\n" + " <td />\n" + " <td />\n" + " <td>" + accountJson.getPhone() + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td>companyCountry</td>\n" + " <td />\n" + " <td />\n" + " <td />\n" + " </tr>\n" + " <tr>\n" + " <td><companyUrl</td>\n" + " <td />\n" + " <td />\n" + " <td />\n" + " </tr>\n" + " </table>\n" + " <br />\n" + " <br />\n" + " <br />\n" + " <table>\n" + " <tr>\n" + " <th>invoiceItemBundleName</td>\n" + " <th>invoiceItemDescription</td>\n" + " <th>invoiceItemServicePeriod</td>\n" + " <th>invoiceItemAmount</td>\n" + " </tr>\n" + " \n" + " <tr>\n" + " <td>shotgun-monthly-trial</td>\n" + " <td>Monthly shotgun plan</td>\n" + " <td>25 avr. 2012</td>\n" + " <td>USD 0.00</td>\n" + " </tr>\n" + " \n" + " <tr>\n" + " <td colspan=4 />\n" + " </tr>\n" + " <tr>\n" + " <td colspan=2 />\n" + " <td align=right><strong>invoiceAmount</strong></td>\n" + " <td align=right><strong>0.00</strong></td>\n" + " </tr>\n" + " <tr>\n" + " <td colspan=2 />\n" + " <td align=right><strong>invoiceAmountPaid</strong></td>\n" + " <td align=right><strong>0.00</strong></td>\n" + " </tr>\n" + " <tr>\n" + " <td colspan=2 />\n" + " <td align=right><strong>invoiceBalance</strong></td>\n" + " <td align=right><strong>0.00</strong></td>\n" + " </tr>\n" + " </table>\n" + " </body>\n" + "</html>\n" + "\n");
// Then create a dryRun for next upcoming invoice
final InvoiceDryRun dryRunArg = new InvoiceDryRun(DryRunType.UPCOMING_INVOICE, null, null, null, null, null, null, null, null, null, null, null);
final Invoice dryRunInvoice = killBillClient.createDryRunInvoice(accountJson.getAccountId(), null, dryRunArg, createdBy, reason, comment);
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
killBillClient.createInvoice(accountJson.getAccountId(), futureDate, createdBy, reason, comment);
// Check again # invoices, should be 3 this time
final List<Invoice> newInvoiceList = killBillClient.getInvoicesForAccount(accountJson.getAccountId());
assertEquals(newInvoiceList.size(), 3);
}
use of org.killbill.billing.client.model.InvoiceDryRun in project killbill by killbill.
the class TestInvoice method testDryRunSubscriptionCreate.
@Test(groups = "slow", description = "Can create a subscription in dryRun mode and get an invoice back")
public void testDryRunSubscriptionCreate() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
// "Assault-Rifle", BillingPeriod.ANNUAL, "rescue", BillingActionPolicy.IMMEDIATE,
final Account accountJson = createAccountWithDefaultPaymentMethod();
final InvoiceDryRun dryRunArg = new InvoiceDryRun(DryRunType.TARGET_DATE, SubscriptionEventType.START_BILLING, null, "Assault-Rifle", ProductCategory.BASE, BillingPeriod.ANNUAL, null, null, null, null, null, null);
final Invoice dryRunInvoice = killBillClient.createDryRunInvoice(accountJson.getAccountId(), new LocalDate(initialDate, DateTimeZone.forID(accountJson.getTimeZone())), dryRunArg, createdBy, reason, comment);
assertEquals(dryRunInvoice.getItems().size(), 1);
}
Aggregations