Search in sources :

Example 76 with Account

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);
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) LocalDate(org.joda.time.LocalDate) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 77 with Account

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

Example 78 with Account

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);
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) InvoiceDryRun(org.killbill.billing.client.model.InvoiceDryRun) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 79 with Account

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);
}
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 80 with Account

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());
}
Also used : Account(org.killbill.billing.client.model.Account) Credit(org.killbill.billing.client.model.Credit) Invoice(org.killbill.billing.client.model.Invoice) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Aggregations

Account (org.killbill.billing.client.model.Account)123 Test (org.testng.annotations.Test)109 UUID (java.util.UUID)32 DateTime (org.joda.time.DateTime)32 Invoice (org.killbill.billing.client.model.Invoice)30 BigDecimal (java.math.BigDecimal)27 Payment (org.killbill.billing.client.model.Payment)24 Subscription (org.killbill.billing.client.model.Subscription)24 ComboPaymentTransaction (org.killbill.billing.client.model.ComboPaymentTransaction)17 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)16 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)16 KillBillClientException (org.killbill.billing.client.KillBillClientException)14 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)14 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)13 PaymentMethod (org.killbill.billing.client.model.PaymentMethod)13 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)10 Payments (org.killbill.billing.client.model.Payments)10 Tags (org.killbill.billing.client.model.Tags)10 Invoices (org.killbill.billing.client.model.Invoices)9 PaymentMethodPluginDetail (org.killbill.billing.client.model.PaymentMethodPluginDetail)9