Search in sources :

Example 1 with Invoices

use of org.killbill.billing.client.model.Invoices in project killbill by killbill.

the class TestInvoice method testExternalChargeOnNewInvoice.

@Test(groups = "slow", description = "Can create an external charge")
public void testExternalChargeOnNewInvoice() 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 firstInvoiceItemId = originalInvoices.get(0).getItems().get(0).getInvoiceItemId();
    // Post an external charge
    final BigDecimal chargeAmount = BigDecimal.TEN;
    final InvoiceItem externalCharge = new InvoiceItem();
    externalCharge.setAccountId(accountJson.getAccountId());
    externalCharge.setAmount(chargeAmount);
    externalCharge.setCurrency(accountJson.getCurrency());
    externalCharge.setPlanName("SomePlan");
    externalCharge.setProductName("SomeProduct");
    externalCharge.setDescription(UUID.randomUUID().toString());
    externalCharge.setItemDetails("Item Details");
    externalCharge.setLinkedInvoiceItemId(firstInvoiceItemId);
    final LocalDate startDate = clock.getUTCToday();
    externalCharge.setStartDate(startDate);
    final LocalDate endDate = startDate.plusDays(10);
    externalCharge.setEndDate(endDate);
    final InvoiceItems itemsForCharge = new InvoiceItems();
    itemsForCharge.add(externalCharge);
    final List<InvoiceItem> createdExternalCharges = invoiceApi.createExternalCharges(accountJson.getAccountId(), itemsForCharge, clock.getUTCToday(), true, NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(createdExternalCharges.size(), 1);
    final Invoice invoiceWithItems = invoiceApi.getInvoice(createdExternalCharges.get(0).getInvoiceId(), false, AuditLevel.NONE, requestOptions);
    assertEquals(invoiceWithItems.getBalance().compareTo(chargeAmount), 0);
    assertEquals(invoiceWithItems.getItems().size(), 1);
    assertEquals(invoiceWithItems.getItems().get(0).getDescription(), externalCharge.getDescription());
    assertNull(invoiceWithItems.getItems().get(0).getBundleId());
    assertEquals(invoiceWithItems.getItems().get(0).getStartDate().compareTo(startDate), 0);
    assertEquals(invoiceWithItems.getItems().get(0).getEndDate().compareTo(endDate), 0);
    assertEquals(invoiceWithItems.getItems().get(0).getItemDetails(), "Item Details");
    assertEquals(invoiceWithItems.getItems().get(0).getLinkedInvoiceItemId(), firstInvoiceItemId);
    assertEquals(invoiceWithItems.getItems().get(0).getPlanName().compareTo("SomePlan"), 0);
    assertEquals(invoiceWithItems.getItems().get(0).getProductName().compareTo("SomeProduct"), 0);
    // Verify the total number of invoices
    assertEquals(accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions).size(), 3);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoiceItems(org.killbill.billing.client.model.InvoiceItems) Invoices(org.killbill.billing.client.model.Invoices) UUID(java.util.UUID) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 2 with Invoices

use of org.killbill.billing.client.model.Invoices 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);
}
Also used : Invoice(org.killbill.billing.client.model.gen.Invoice) Invoices(org.killbill.billing.client.model.Invoices) Test(org.testng.annotations.Test)

Example 3 with Invoices

use of org.killbill.billing.client.model.Invoices in project killbill by killbill.

the class TestExternalRefund method testAutomaticPaymentAndRefundWithAdjustments.

@Test(groups = "slow", description = "#255 - Scenario 0 - Can refund an automatic payment over item adjustments. This is a test to validate the correct behaviour.")
public void testAutomaticPaymentAndRefundWithAdjustments() 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 Payments paymentsForAccount = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
    Invoices invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, true, false, false, null, AuditLevel.NONE, requestOptions);
    final List<InvoiceItem> itemsToBeAdjusted = invoices.get(1).getItems();
    // regular refund
    final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
    invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
    invoicePaymentTransactionRequest.setCurrency(accountJson.getCurrency());
    invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
    invoicePaymentTransactionRequest.setIsAdjusted(true);
    invoicePaymentTransactionRequest.setAdjustments(itemsToBeAdjusted);
    invoicePaymentApi.createRefundWithAdjustments(payment.getPaymentId(), invoicePaymentTransactionRequest, payment.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final InvoicePayment invoicePaymentRefund = invoicePaymentApi.getInvoicePayment(payment.getPaymentId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNotNull(invoicePaymentRefund);
    assertSingleInvoicePaymentRefund(invoicePaymentRefund);
    assertRefundInvoiceAdjustments(accountJson.getAccountId());
    assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.ZERO, BigDecimal.ZERO);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Invoices(org.killbill.billing.client.model.Invoices) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 4 with Invoices

use of org.killbill.billing.client.model.Invoices in project killbill by killbill.

the class TestExternalRefund method testAutomaticPaymentAndExternalRefundWithDifferentPM.

@Test(groups = "slow", description = "#255 - Scenario 2b - Can refund an automatic payment though another existing payment method")
public void testAutomaticPaymentAndExternalRefundWithDifferentPM() 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();
    // delete PM
    paymentMethodApi.deletePaymentMethod(accountJson.getPaymentMethodId(), true, true, NULL_PLUGIN_PROPERTIES, requestOptions);
    // create another PM
    final PaymentMethodPluginDetail info = new PaymentMethodPluginDetail();
    final PaymentMethod paymentMethodJson = new PaymentMethod(null, UUID.randomUUID().toString(), accountJson.getAccountId(), false, PLUGIN_NAME, info, null);
    final PaymentMethod otherPaymentMethod = accountApi.createPaymentMethod(accountJson.getAccountId(), paymentMethodJson, NULL_PLUGIN_NAMES, NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payments paymentsForAccount = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
    final Invoices invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, true, false, false, null, AuditLevel.NONE, requestOptions);
    final List<InvoiceItem> itemsToBeAdjusted = invoices.get(1).getItems();
    // external refund
    final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
    invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
    invoicePaymentTransactionRequest.setCurrency(accountJson.getCurrency());
    invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
    invoicePaymentTransactionRequest.setIsAdjusted(true);
    invoicePaymentTransactionRequest.setAdjustments(itemsToBeAdjusted);
    final InvoicePayment invoicePaymentExternalRefund = invoicePaymentApi.createRefundWithAdjustments(payment.getPaymentId(), invoicePaymentTransactionRequest, true, otherPaymentMethod.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertNotNull(invoicePaymentExternalRefund);
    assertEquals(invoicePaymentExternalRefund.getPaymentMethodId(), otherPaymentMethod.getPaymentMethodId());
    assertInvoicePaymentsExternalRefund(accountJson.getAccountId(), invoicePaymentExternalRefund);
    assertRefundInvoiceAdjustments(accountJson.getAccountId());
    assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.ZERO, BigDecimal.ZERO);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Payment(org.killbill.billing.client.model.gen.Payment) InvoiceItem(org.killbill.billing.client.model.gen.InvoiceItem) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) PaymentMethodPluginDetail(org.killbill.billing.client.model.gen.PaymentMethodPluginDetail) PaymentMethod(org.killbill.billing.client.model.gen.PaymentMethod) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Invoices(org.killbill.billing.client.model.Invoices) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 5 with Invoices

use of org.killbill.billing.client.model.Invoices 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);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Invoices(org.killbill.billing.client.model.Invoices) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

Invoices (org.killbill.billing.client.model.Invoices)22 Test (org.testng.annotations.Test)20 Account (org.killbill.billing.client.model.gen.Account)19 DateTime (org.joda.time.DateTime)11 Invoice (org.killbill.billing.client.model.gen.Invoice)10 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)9 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)8 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)7 Payments (org.killbill.billing.client.model.Payments)6 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)6 UUID (java.util.UUID)4 Payment (org.killbill.billing.client.model.gen.Payment)4 BigDecimal (java.math.BigDecimal)3 LocalDate (org.joda.time.LocalDate)3 InvoiceItems (org.killbill.billing.client.model.InvoiceItems)2 Tags (org.killbill.billing.client.model.Tags)2 AuditLog (org.killbill.billing.client.model.gen.AuditLog)2 Subscription (org.killbill.billing.client.model.gen.Subscription)2 Predicate (com.google.common.base.Predicate)1 KillBillClientException (org.killbill.billing.client.KillBillClientException)1