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);
}
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);
}
Aggregations