Search in sources :

Example 11 with AuditLog

use of org.killbill.billing.client.model.gen.AuditLog 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);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) Invoices(org.killbill.billing.client.model.Invoices) InvoiceDryRun(org.killbill.billing.client.model.gen.InvoiceDryRun) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) AuditLog(org.killbill.billing.client.model.gen.AuditLog) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 12 with AuditLog

use of org.killbill.billing.client.model.gen.AuditLog in project killbill by killbill.

the class TestInvoice method testFullInvoiceItemAdjustment.

@Test(groups = "slow", description = "Can fully adjust an invoice item")
public void testFullInvoiceItemAdjustment() throws Exception {
    final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Get the invoices
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, false, false, false, null, AuditLevel.NONE, requestOptions);
    // 2 invoices but look for the non zero dollar one
    assertEquals(invoices.size(), 2);
    final Invoice invoice = invoices.get(1);
    // Verify the invoice we picked is non zero
    assertEquals(invoice.getAmount().compareTo(BigDecimal.ZERO), 1);
    final InvoiceItem invoiceItem = invoice.getItems().get(0);
    // Verify the item we picked is non zero
    assertEquals(invoiceItem.getAmount().compareTo(BigDecimal.ZERO), 1);
    // Adjust the full amount
    final InvoiceItem adjustmentInvoiceItem = new InvoiceItem();
    adjustmentInvoiceItem.setAccountId(accountJson.getAccountId());
    adjustmentInvoiceItem.setInvoiceId(invoice.getInvoiceId());
    adjustmentInvoiceItem.setInvoiceItemId(invoiceItem.getInvoiceItemId());
    final String itemDetails = "{\n" + "  \"user\": \"admin\",\n" + "  \"reason\": \"SLA not met\"\n" + "}";
    adjustmentInvoiceItem.setItemDetails(itemDetails);
    invoiceApi.adjustInvoiceItem(invoice.getInvoiceId(), adjustmentInvoiceItem, null, NULL_PLUGIN_PROPERTIES, requestOptions);
    // Verify the new invoice balance is zero
    final Invoice adjustedInvoice = invoiceApi.getInvoice(invoice.getInvoiceId(), false, AuditLevel.FULL, requestOptions);
    assertEquals(adjustedInvoice.getAmount().compareTo(BigDecimal.ZERO), 0);
    final InvoiceItem createdAdjustment = Iterables.find(adjustedInvoice.getItems(), new Predicate<InvoiceItem>() {

        @Override
        public boolean apply(final InvoiceItem input) {
            return InvoiceItemType.ITEM_ADJ.equals(input.getItemType());
        }
    });
    assertEquals(createdAdjustment.getItemDetails(), itemDetails);
    // Verify invoice audit logs
    Assert.assertEquals(adjustedInvoice.getAuditLogs().size(), 1);
    final AuditLog invoiceAuditLogJson = adjustedInvoice.getAuditLogs().get(0);
    Assert.assertEquals(invoiceAuditLogJson.getChangeType(), "INSERT");
    Assert.assertEquals(invoiceAuditLogJson.getChangedBy(), "SubscriptionBaseTransition");
    Assert.assertNotNull(invoiceAuditLogJson.getChangeDate());
    Assert.assertNotNull(invoiceAuditLogJson.getUserToken());
    Assert.assertNull(invoiceAuditLogJson.getReasonCode());
    Assert.assertNull(invoiceAuditLogJson.getComments());
    Assert.assertEquals(adjustedInvoice.getItems().size(), 2);
    // Verify invoice items audit logs
    // The first item is the original item
    Assert.assertEquals(adjustedInvoice.getItems().get(0).getAuditLogs().size(), 1);
    final AuditLog itemAuditLogJson = adjustedInvoice.getItems().get(0).getAuditLogs().get(0);
    Assert.assertEquals(itemAuditLogJson.getChangeType(), "INSERT");
    Assert.assertEquals(itemAuditLogJson.getChangedBy(), "SubscriptionBaseTransition");
    Assert.assertNotNull(itemAuditLogJson.getChangeDate());
    Assert.assertNotNull(itemAuditLogJson.getUserToken());
    Assert.assertNull(itemAuditLogJson.getReasonCode());
    Assert.assertNull(itemAuditLogJson.getComments());
    // The second one is the adjustment
    Assert.assertEquals(adjustedInvoice.getItems().get(1).getAuditLogs().size(), 1);
    final AuditLog adjustedItemAuditLogJson = adjustedInvoice.getItems().get(1).getAuditLogs().get(0);
    Assert.assertEquals(adjustedItemAuditLogJson.getChangeType(), "INSERT");
    Assert.assertEquals(adjustedItemAuditLogJson.getChangedBy(), createdBy);
    Assert.assertEquals(adjustedItemAuditLogJson.getReasonCode(), reason);
    Assert.assertEquals(adjustedItemAuditLogJson.getComments(), comment);
    Assert.assertNotNull(adjustedItemAuditLogJson.getChangeDate());
    Assert.assertNotNull(adjustedItemAuditLogJson.getUserToken());
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) AuditLog(org.killbill.billing.client.model.gen.AuditLog) Test(org.testng.annotations.Test)

Example 13 with AuditLog

use of org.killbill.billing.client.model.gen.AuditLog in project killbill by killbill.

the class TestPaymentMethod method testPaymentMethodAuditLogsWithHistory.

@Test(groups = "slow", description = "retrieve account logs")
public void testPaymentMethodAuditLogsWithHistory() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    assertNotNull(account);
    final UUID paymentMethodId = account.getPaymentMethodId();
    final List<AuditLog> paymentMethodAuditLogWithHistory = paymentMethodApi.getPaymentMethodAuditLogsWithHistory(paymentMethodId, requestOptions);
    assertEquals(paymentMethodAuditLogWithHistory.size(), 1);
    assertEquals(paymentMethodAuditLogWithHistory.get(0).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(paymentMethodAuditLogWithHistory.get(0).getObjectType(), ObjectType.PAYMENT_METHOD);
    assertEquals(paymentMethodAuditLogWithHistory.get(0).getObjectId(), paymentMethodId);
    final LinkedHashMap history1 = (LinkedHashMap) paymentMethodAuditLogWithHistory.get(0).getHistory();
    assertNotNull(history1);
    assertEquals(history1.get("accountId"), account.getAccountId().toString());
}
Also used : Account(org.killbill.billing.client.model.gen.Account) UUID(java.util.UUID) AuditLog(org.killbill.billing.client.model.gen.AuditLog) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 14 with AuditLog

use of org.killbill.billing.client.model.gen.AuditLog in project killbill by killbill.

the class TestPayment method testPaymentAuditLogsWithHistory.

@Test(groups = "slow", description = "retrieve account logs")
public void testPaymentAuditLogsWithHistory() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final String externalPaymentKey = UUID.randomUUID().toString();
    final UUID paymentId = testCreateRetrievePayment(account, null, externalPaymentKey, 1);
    final Payment payment = paymentApi.getPaymentByExternalKey(externalPaymentKey, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(payment.getPaymentId(), paymentId);
    final List<AuditLog> paymentAuditLogWithHistory = paymentApi.getPaymentAuditLogsWithHistory(paymentId, requestOptions);
    assertEquals(paymentAuditLogWithHistory.size(), 8);
    assertEquals(paymentAuditLogWithHistory.get(0).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(paymentAuditLogWithHistory.get(0).getObjectType(), ObjectType.PAYMENT);
    assertEquals(paymentAuditLogWithHistory.get(0).getObjectId(), paymentId);
    final LinkedHashMap history1 = (LinkedHashMap) paymentAuditLogWithHistory.get(0).getHistory();
    assertNotNull(history1);
    assertEquals(history1.get("stateName"), null);
    final LinkedHashMap history2 = (LinkedHashMap) paymentAuditLogWithHistory.get(1).getHistory();
    assertNotNull(history2);
    assertEquals(history2.get("stateName"), "AUTH_SUCCESS");
    final LinkedHashMap history3 = (LinkedHashMap) paymentAuditLogWithHistory.get(2).getHistory();
    assertNotNull(history3);
    assertEquals(history3.get("stateName"), "AUTH_SUCCESS");
    final LinkedHashMap history4 = (LinkedHashMap) paymentAuditLogWithHistory.get(3).getHistory();
    assertNotNull(history4);
    assertEquals(history4.get("stateName"), "CAPTURE_SUCCESS");
    final LinkedHashMap history5 = (LinkedHashMap) paymentAuditLogWithHistory.get(4).getHistory();
    assertNotNull(history5);
    assertEquals(history5.get("stateName"), "CAPTURE_SUCCESS");
    final LinkedHashMap history6 = (LinkedHashMap) paymentAuditLogWithHistory.get(5).getHistory();
    assertNotNull(history6);
    assertEquals(history6.get("stateName"), "CAPTURE_SUCCESS");
    final LinkedHashMap history7 = (LinkedHashMap) paymentAuditLogWithHistory.get(6).getHistory();
    assertNotNull(history7);
    assertEquals(history7.get("stateName"), "CAPTURE_SUCCESS");
    final LinkedHashMap history8 = (LinkedHashMap) paymentAuditLogWithHistory.get(7).getHistory();
    assertNotNull(history8);
    assertEquals(history8.get("stateName"), "REFUND_SUCCESS");
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) UUID(java.util.UUID) AuditLog(org.killbill.billing.client.model.gen.AuditLog) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Aggregations

AuditLog (org.killbill.billing.client.model.gen.AuditLog)14 Account (org.killbill.billing.client.model.gen.Account)10 Test (org.testng.annotations.Test)10 LinkedHashMap (java.util.LinkedHashMap)6 UUID (java.util.UUID)5 AccountTimeline (org.killbill.billing.client.model.gen.AccountTimeline)4 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)4 AuditLevel (org.killbill.billing.util.api.AuditLevel)4 Invoices (org.killbill.billing.client.model.Invoices)2 Invoice (org.killbill.billing.client.model.gen.Invoice)2 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)2 Tag (org.killbill.billing.client.model.gen.Tag)2 TagDefinition (org.killbill.billing.client.model.gen.TagDefinition)2 BigDecimal (java.math.BigDecimal)1 DateTime (org.joda.time.DateTime)1 LocalDate (org.joda.time.LocalDate)1 RequestOptions (org.killbill.billing.client.RequestOptions)1 CustomFields (org.killbill.billing.client.model.CustomFields)1 AccountEmail (org.killbill.billing.client.model.gen.AccountEmail)1 CustomField (org.killbill.billing.client.model.gen.CustomField)1