Search in sources :

Example 41 with Invoice

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

the class TestChargeback method createAndVerifyChargeback.

private void createAndVerifyChargeback(final InvoicePayment payment) throws KillBillClientException {
    List<Invoice> invoices = accountApi.getInvoicesForAccount(payment.getAccountId(), null, null, null, requestOptions);
    // We should have two invoices, one for the trial (zero dollar amount) and one for the first month
    Assert.assertEquals(invoices.size(), 2);
    Assert.assertEquals(invoices.get(1).getBalance().compareTo(BigDecimal.ZERO), 0);
    // Create the chargeback
    final InvoicePaymentTransaction chargeback = new InvoicePaymentTransaction();
    chargeback.setPaymentId(payment.getPaymentId());
    chargeback.setAmount(BigDecimal.TEN);
    final InvoicePayment chargebackJson = invoicePaymentApi.createChargeback(payment.getPaymentId(), chargeback, NULL_PLUGIN_PROPERTIES, requestOptions);
    final List<PaymentTransaction> chargebackTransactions = getInvoicePaymentTransactions(ImmutableList.of(chargebackJson), TransactionType.CHARGEBACK);
    assertEquals(chargebackTransactions.size(), 1);
    assertEquals(chargebackTransactions.get(0).getAmount().compareTo(chargeback.getAmount()), 0);
    assertEquals(chargebackTransactions.get(0).getPaymentId(), chargeback.getPaymentId());
    // Find the chargeback by account
    final List<InvoicePayment> payments = accountApi.getInvoicePayments(payment.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    final List<PaymentTransaction> transactions = getInvoicePaymentTransactions(payments, TransactionType.CHARGEBACK);
    Assert.assertEquals(transactions.size(), 1);
    assertEquals(transactions.get(0).getAmount().compareTo(chargeback.getAmount()), 0);
    assertEquals(transactions.get(0).getPaymentId(), chargeback.getPaymentId());
    // Verify invoice balance
    invoices = accountApi.getInvoicesForAccount(payment.getAccountId(), null, null, null, requestOptions);
    Assert.assertEquals(invoices.size(), 2);
    Assert.assertEquals(invoices.get(1).getBalance().compareTo(BigDecimal.ZERO), 1);
}
Also used : InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction) PaymentTransaction(org.killbill.billing.client.model.gen.PaymentTransaction) InvoicePayment(org.killbill.billing.client.model.gen.InvoicePayment) Invoice(org.killbill.billing.client.model.gen.Invoice) InvoicePaymentTransaction(org.killbill.billing.client.model.gen.InvoicePaymentTransaction)

Example 42 with Invoice

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

the class TestChargeback method createAccountWithInvoice.

private Invoice createAccountWithInvoice() throws Exception {
    // Create account
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    // Create subscription
    final Subscription subscriptionJson = createSubscription(accountJson.getAccountId(), "6253283", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY);
    assertNotNull(subscriptionJson);
    // Move after the trial period to trigger an invoice with a non-zero invoice item
    callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE, ExtBusEventType.INVOICE_CREATION, ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
    clock.addDays(32);
    callbackServlet.assertListenerStatus();
    // Retrieve the invoice
    final List<Invoice> invoices = accountApi.getInvoicesForAccount(accountJson.getAccountId(), null, null, null, requestOptions);
    // We should have two invoices, one for the trial (zero dollar amount) and one for the first month
    assertEquals(invoices.size(), 2);
    assertTrue(invoices.get(1).getAmount().doubleValue() > 0);
    return invoices.get(1);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Invoice(org.killbill.billing.client.model.gen.Invoice) Subscription(org.killbill.billing.client.model.gen.Subscription)

Aggregations

Invoice (org.killbill.billing.client.model.gen.Invoice)42 Test (org.testng.annotations.Test)37 Account (org.killbill.billing.client.model.gen.Account)33 DateTime (org.joda.time.DateTime)17 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)15 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)14 BigDecimal (java.math.BigDecimal)12 Invoices (org.killbill.billing.client.model.Invoices)10 InvoiceItems (org.killbill.billing.client.model.InvoiceItems)7 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)7 LocalDate (org.joda.time.LocalDate)6 Subscription (org.killbill.billing.client.model.gen.Subscription)6 UUID (java.util.UUID)5 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)5 Payment (org.killbill.billing.client.model.gen.Payment)4 ArrayList (java.util.ArrayList)3 KillBillClientException (org.killbill.billing.client.KillBillClientException)3 BulkSubscriptionsBundles (org.killbill.billing.client.model.BulkSubscriptionsBundles)3 Bundles (org.killbill.billing.client.model.Bundles)3 Payments (org.killbill.billing.client.model.Payments)3