use of org.killbill.billing.client.model.Account in project killbill by killbill.
the class TestInvoice method testInvoiceMigration.
@Test(groups = "slow", description = "Can create a migration invoice")
public void testInvoiceMigration() throws Exception {
final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
// Get the invoices
final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, true);
assertEquals(invoices.size(), 2);
// Migrate an invoice with one external charge
final BigDecimal chargeAmount = BigDecimal.TEN;
final InvoiceItem externalCharge = new InvoiceItem();
externalCharge.setStartDate(new LocalDate());
externalCharge.setAccountId(accountJson.getAccountId());
externalCharge.setAmount(chargeAmount);
externalCharge.setItemType(InvoiceItemType.EXTERNAL_CHARGE.toString());
externalCharge.setCurrency(accountJson.getCurrency());
final Account accountWithBalance = killBillClient.getAccount(accountJson.getAccountId(), true, true);
final Invoice migrationInvoice = killBillClient.createMigrationInvoice(accountJson.getAccountId(), null, ImmutableList.<InvoiceItem>of(externalCharge), requestOptions);
assertEquals(migrationInvoice.getBalance(), BigDecimal.ZERO);
assertEquals(migrationInvoice.getItems().size(), 1);
assertEquals(migrationInvoice.getItems().get(0).getAmount().compareTo(chargeAmount), 0);
assertEquals(migrationInvoice.getItems().get(0).getCurrency(), accountJson.getCurrency());
final List<Invoice> invoicesWithMigration = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, true);
assertEquals(invoicesWithMigration.size(), 3);
final Account accountWithBalanceAfterMigration = killBillClient.getAccount(accountJson.getAccountId(), true, true);
assertEquals(accountWithBalanceAfterMigration.getAccountBalance().compareTo(accountWithBalance.getAccountBalance()), 0);
}
use of org.killbill.billing.client.model.Account in project killbill by killbill.
the class TestInvoice method testInvoiceCreatePayment.
@Test(groups = "slow", description = "Can create an insta-payment")
public void testInvoiceCreatePayment() throws Exception {
clock.setTime(new DateTime(2012, 4, 25, 0, 3, 42, 0));
// STEPH MISSING SET ACCOUNT AUTO_PAY_OFF
final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
// Get the invoices
final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId());
assertEquals(invoices.size(), 2);
for (final Invoice cur : invoices) {
if (cur.getBalance().compareTo(BigDecimal.ZERO) <= 0) {
continue;
}
// CREATE PAYMENT
final InvoicePayment invoicePayment = new InvoicePayment();
invoicePayment.setPurchasedAmount(cur.getBalance());
invoicePayment.setAccountId(accountJson.getAccountId());
invoicePayment.setTargetInvoiceId(cur.getInvoiceId());
final InvoicePayment objFromJson = killBillClient.createInvoicePayment(invoicePayment, true, createdBy, reason, comment);
assertEquals(cur.getBalance().compareTo(objFromJson.getPurchasedAmount()), 0);
}
}
use of org.killbill.billing.client.model.Account in project killbill by killbill.
the class TestInvoice method testDryRunSubscriptionCreate.
@Test(groups = "slow", description = "Can create a subscription in dryRun mode and get an invoice back")
public void testDryRunSubscriptionCreate() throws Exception {
final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
// "Assault-Rifle", BillingPeriod.ANNUAL, "rescue", BillingActionPolicy.IMMEDIATE,
final Account accountJson = createAccountWithDefaultPaymentMethod();
final InvoiceDryRun dryRunArg = new InvoiceDryRun(DryRunType.TARGET_DATE, SubscriptionEventType.START_BILLING, null, "Assault-Rifle", ProductCategory.BASE, BillingPeriod.ANNUAL, null, null, null, null, null, null);
final Invoice dryRunInvoice = killBillClient.createDryRunInvoice(accountJson.getAccountId(), new LocalDate(initialDate, DateTimeZone.forID(accountJson.getTimeZone())), dryRunArg, createdBy, reason, comment);
assertEquals(dryRunInvoice.getItems().size(), 1);
}
use of org.killbill.billing.client.model.Account 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);
}
use of org.killbill.billing.client.model.Account in project killbill by killbill.
the class TestInvoice method testCreateCreditInvoiceAndMoveStatus.
@Test(groups = "slow", description = "Can add a credit to a new invoice")
public void testCreateCreditInvoiceAndMoveStatus() throws Exception {
final Account account = createAccountWithDefaultPaymentMethod();
final DateTime effectiveDate = clock.getUTCNow();
final BigDecimal creditAmount = BigDecimal.TEN;
final Credit credit = new Credit();
credit.setAccountId(account.getAccountId());
credit.setInvoiceId(null);
credit.setCreditAmount(creditAmount);
final Credit creditJson = killBillClient.createCredit(credit, false, createdBy, reason, comment);
Invoice invoice = killBillClient.getInvoice(creditJson.getInvoiceId());
Assert.assertEquals(invoice.getStatus(), InvoiceStatus.DRAFT.toString());
killBillClient.commitInvoice(invoice.getInvoiceId(), createdBy, reason, comment);
invoice = killBillClient.getInvoice(creditJson.getInvoiceId());
Assert.assertEquals(invoice.getStatus(), InvoiceStatus.COMMITTED.toString());
}
Aggregations