Search in sources :

Example 6 with InvoicePayments

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

the class TestInvoice method testInvoicePayments.

@Test(groups = "slow", description = "Can retrieve invoice payments")
public void testInvoicePayments() throws Exception {
    clock.setTime(new DateTime(2012, 4, 25, 0, 3, 42, 0));
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId());
    assertEquals(invoices.size(), 2);
    final Invoice invoiceWithPositiveAmount = Iterables.tryFind(invoices, new Predicate<Invoice>() {

        @Override
        public boolean apply(final Invoice input) {
            return input.getAmount().compareTo(BigDecimal.ZERO) > 0;
        }
    }).orNull();
    Assert.assertNotNull(invoiceWithPositiveAmount);
    final InvoicePayments objFromJson = killBillClient.getInvoicePayment(invoiceWithPositiveAmount.getInvoiceId());
    assertEquals(objFromJson.size(), 1);
    assertEquals(invoiceWithPositiveAmount.getAmount().compareTo(objFromJson.get(0).getPurchasedAmount()), 0);
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) DateTime(org.joda.time.DateTime) Predicate(com.google.common.base.Predicate) Test(org.testng.annotations.Test)

Example 7 with InvoicePayments

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

the class TestInvoicePayment method testWithFailedInvoicePayment.

@Test(groups = "slow")
public void testWithFailedInvoicePayment() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    InvoicePayments invoicePayments = killBillClient.getInvoicePaymentsForAccount(accountJson.getAccountId(), requestOptions);
    assertEquals(invoicePayments.size(), 1);
    final InvoicePayment invoicePayment = invoicePayments.get(0);
    // Verify targetInvoiceId is not Null. See #593
    assertNotNull(invoicePayment.getTargetInvoiceId());
    final Invoices invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions);
    assertEquals(invoices.size(), 2);
    final Invoice invoice = invoices.get(1);
    // Verify this is the correct value
    assertEquals(invoicePayment.getTargetInvoiceId(), invoice.getInvoiceId());
    // Make a payment and verify both invoice payment point to the same targetInvoiceId
    killBillClient.payAllInvoices(accountJson.getAccountId(), false, null, requestOptions);
    invoicePayments = killBillClient.getInvoicePaymentsForAccount(accountJson.getAccountId(), requestOptions);
    assertEquals(invoicePayments.size(), 2);
    for (final InvoicePayment cur : invoicePayments) {
        assertEquals(cur.getTargetInvoiceId(), invoice.getInvoiceId());
    }
}
Also used : Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Invoice(org.killbill.billing.client.model.Invoice) Invoices(org.killbill.billing.client.model.Invoices) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Aggregations

InvoicePayments (org.killbill.billing.client.model.InvoicePayments)7 Test (org.testng.annotations.Test)5 Account (org.killbill.billing.client.model.Account)4 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)3 DateTime (org.joda.time.DateTime)2 Invoice (org.killbill.billing.client.model.Invoice)2 Predicate (com.google.common.base.Predicate)1 UUID (java.util.UUID)1 RequestOptions (org.killbill.billing.client.RequestOptions)1 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)1 Invoices (org.killbill.billing.client.model.Invoices)1 Payment (org.killbill.billing.client.model.Payment)1 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)1 Payments (org.killbill.billing.client.model.Payments)1