Search in sources :

Example 26 with ExpectedInvoiceItemCheck

use of org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck in project killbill by killbill.

the class TestIntegrationWithDifferentBillingPeriods method testChangeMonthlyToAnnualWithDifferentBCD.

@Test(groups = "slow")
public void testChangeMonthlyToAnnualWithDifferentBCD() throws Exception {
    // We take april as it has 30 days
    final LocalDate today = new LocalDate(2016, 6, 1);
    final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(10));
    // Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
    clock.setDeltaFromReality(today.toDateTimeAtCurrentTime(DateTimeZone.UTC).getMillis() - clock.getUTCNow().getMillis());
    final String productName = "Shotgun";
    //
    // CREATE SUBSCRIPTION AND EXPECT BOTH EVENTS: NextEvent.CREATE, NextEvent.BLOCK NextEvent.INVOICE
    //
    final DefaultEntitlement bpEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", productName, ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
    assertNotNull(bpEntitlement);
    assertEquals(invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext).size(), 1);
    assertEquals(bpEntitlement.getSubscriptionBase().getCurrentPlan().getRecurringBillingPeriod(), BillingPeriod.MONTHLY);
    // Move out of trials for interesting invoices adjustments
    busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    clock.addDays(30);
    assertListenerStatus();
    List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
    assertEquals(invoices.size(), 2);
    ImmutableList<ExpectedInvoiceItemCheck> toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(new ExpectedInvoiceItemCheck(new LocalDate(2016, 7, 1), new LocalDate(2016, 7, 10), InvoiceItemType.RECURRING, new BigDecimal("74.99")));
    invoiceChecker.checkInvoice(invoices.get(1).getId(), callContext, toBeChecked);
    // Invoice for a full month
    busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    clock.addMonths(1);
    assertListenerStatus();
    invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
    assertEquals(invoices.size(), 3);
    toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(new ExpectedInvoiceItemCheck(new LocalDate(2016, 7, 10), new LocalDate(2016, 8, 10), InvoiceItemType.RECURRING, new BigDecimal("249.95")));
    invoiceChecker.checkInvoice(invoices.get(2).getId(), callContext, toBeChecked);
    //
    // MOVE MONTHLY TO ANNUAL: Because of different Billing Alignment the BCD now becomes the 1 (first non null recurring phase)
    //
    changeEntitlementAndCheckForCompletion(bpEntitlement, productName, BillingPeriod.ANNUAL, BillingActionPolicy.IMMEDIATE, NextEvent.CHANGE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
    assertEquals(invoices.size(), 4);
    toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(new ExpectedInvoiceItemCheck(new LocalDate(2016, 8, 1), new LocalDate(2017, 8, 1), InvoiceItemType.RECURRING, new BigDecimal("2399.95")), new ExpectedInvoiceItemCheck(new LocalDate(2016, 8, 1), new LocalDate(2016, 8, 10), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-72.57")));
    invoiceChecker.checkInvoice(invoices.get(3).getId(), callContext, toBeChecked);
    checkNoMoreInvoiceToGenerate(account);
}
Also used : Account(org.killbill.billing.account.api.Account) Invoice(org.killbill.billing.invoice.api.Invoice) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) LocalDate(org.joda.time.LocalDate) ExpectedInvoiceItemCheck(org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 27 with ExpectedInvoiceItemCheck

use of org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck in project killbill by killbill.

the class TestIntegrationWithDifferentBillingPeriods method testPauseResumeAnnual.

@Test(groups = "slow")
public void testPauseResumeAnnual() throws Exception {
    // We take april as it has 30 days (easier to play with BCD)
    final LocalDate today = new LocalDate(2012, 4, 1);
    final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(1));
    // Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
    clock.setDeltaFromReality(today.toDateTimeAtCurrentTime(DateTimeZone.UTC).getMillis() - clock.getUTCNow().getMillis());
    final String productName = "Shotgun";
    //
    // CREATE SUBSCRIPTION AND EXPECT BOTH EVENTS: NextEvent.CREATE, NextEvent.BLOCK NextEvent.INVOICE
    //
    final DefaultEntitlement bpEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", productName, ProductCategory.BASE, BillingPeriod.ANNUAL, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
    assertNotNull(bpEntitlement);
    assertEquals(invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext).size(), 1);
    assertEquals(bpEntitlement.getSubscriptionBase().getCurrentPlan().getRecurringBillingPeriod(), BillingPeriod.ANNUAL);
    // Move out of trials for interesting invoices adjustments
    busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    clock.addDays(31);
    assertListenerStatus();
    // 2012-5-12
    clock.addDays(10);
    busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE);
    entitlementApi.pause(bpEntitlement.getBundleId(), clock.getUTCNow().toLocalDate(), ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
    assertEquals(invoices.size(), 3);
    ImmutableList<ExpectedInvoiceItemCheck> toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 1), new LocalDate(2013, 5, 1), InvoiceItemType.RECURRING, new BigDecimal("2399.95")));
    invoiceChecker.checkInvoice(invoices.get(1).getId(), callContext, toBeChecked);
    toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 12), new LocalDate(2012, 5, 12), InvoiceItemType.CBA_ADJ, new BigDecimal("2327.62")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 5, 12), new LocalDate(2013, 5, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-2327.62")));
    invoiceChecker.checkInvoice(invoices.get(2).getId(), callContext, toBeChecked);
    // 2012-6-4
    clock.addDays(23);
    busHandler.pushExpectedEvents(NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    entitlementApi.resume(bpEntitlement.getBundleId(), clock.getUTCNow().toLocalDate(), ImmutableList.<PluginProperty>of(), callContext);
    assertListenerStatus();
    invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
    assertEquals(invoices.size(), 4);
    toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(new ExpectedInvoiceItemCheck(new LocalDate(2012, 6, 4), new LocalDate(2013, 6, 1), InvoiceItemType.RECURRING, new BigDecimal("2380.22")), new ExpectedInvoiceItemCheck(new LocalDate(2012, 6, 4), new LocalDate(2012, 6, 4), InvoiceItemType.CBA_ADJ, new BigDecimal("-2327.62")));
    invoiceChecker.checkInvoice(invoices.get(3).getId(), callContext, toBeChecked);
    busHandler.pushExpectedEvents(NextEvent.NULL_INVOICE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    clock.addYears(1);
    assertListenerStatus();
    invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
    assertEquals(invoices.size(), 5);
    toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(new ExpectedInvoiceItemCheck(new LocalDate(2013, 6, 1), new LocalDate(2014, 6, 1), InvoiceItemType.RECURRING, new BigDecimal("2399.95")));
    invoiceChecker.checkInvoice(invoices.get(4).getId(), callContext, toBeChecked);
    checkNoMoreInvoiceToGenerate(account);
}
Also used : Account(org.killbill.billing.account.api.Account) Invoice(org.killbill.billing.invoice.api.Invoice) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) LocalDate(org.joda.time.LocalDate) ExpectedInvoiceItemCheck(org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 28 with ExpectedInvoiceItemCheck

use of org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck in project killbill by killbill.

the class TestIntegrationWithDifferentBillingPeriods method testChangeAnnualToAnnual.

@Test(groups = "slow")
public void testChangeAnnualToAnnual() throws Exception {
    //
    // Initialize test 'startDate' with 2014-12-2 with an account BCD  set to the 1st (in such a way that at the end of the 30 days TRIAL,
    // recurring phase starts on 2015-01-01 and we invoice for a full year from 2015-01-01 to 2016-01-01
    //
    final LocalDate startDate = new LocalDate(2014, 12, 2);
    final int accountBCD = 1;
    final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(accountBCD));
    // Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
    clock.setDeltaFromReality(startDate.toDateTimeAtCurrentTime(DateTimeZone.UTC).getMillis() - clock.getUTCNow().getMillis());
    // Create subscription and check we get the initial invoice for the 30 days TRIAL
    final DefaultEntitlement bpEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey", "Shotgun", ProductCategory.BASE, BillingPeriod.ANNUAL, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
    assertNotNull(bpEntitlement);
    assertEquals(invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext).size(), 1);
    assertEquals(bpEntitlement.getSubscriptionBase().getCurrentPlan().getRecurringBillingPeriod(), BillingPeriod.ANNUAL);
    // Move out of TRIAL and verify we invioice for a full year
    busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    clock.addDays(30);
    assertListenerStatus();
    List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
    assertEquals(invoices.size(), 2);
    ImmutableList<ExpectedInvoiceItemCheck> toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(new ExpectedInvoiceItemCheck(new LocalDate(2015, 1, 1), new LocalDate(2016, 1, 1), InvoiceItemType.RECURRING, new BigDecimal("2399.95")));
    invoiceChecker.checkInvoice(invoices.get(1).getId(), callContext, toBeChecked);
    //
    // Move to 2015-3-15 (somehow arbitrary date) and upgrade to another ANNUAL plan
    // We verify that we will invoice for the longest possible period in such a way that:
    // - We keep the same billing cycle day (1st)
    // - We invoice for *up to* a full year (but no more)
    //
    clock.addDays(73);
    changeEntitlementAndCheckForCompletion(bpEntitlement, "Assault-Rifle", BillingPeriod.ANNUAL, BillingActionPolicy.IMMEDIATE, NextEvent.CHANGE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
    assertEquals(invoices.size(), 3);
    toBeChecked = ImmutableList.<ExpectedInvoiceItemCheck>of(new ExpectedInvoiceItemCheck(new LocalDate(2015, 3, 15), new LocalDate(2016, 3, 1), InvoiceItemType.RECURRING, new BigDecimal("5770.44")), new ExpectedInvoiceItemCheck(new LocalDate(2015, 3, 15), new LocalDate(2016, 1, 1), InvoiceItemType.REPAIR_ADJ, new BigDecimal("-1919.96")));
    invoiceChecker.checkInvoice(invoices.get(2).getId(), callContext, toBeChecked);
    checkNoMoreInvoiceToGenerate(account);
}
Also used : Account(org.killbill.billing.account.api.Account) Invoice(org.killbill.billing.invoice.api.Invoice) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) LocalDate(org.joda.time.LocalDate) ExpectedInvoiceItemCheck(org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 29 with ExpectedInvoiceItemCheck

use of org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck in project killbill by killbill.

the class TestWithCatalogPlugin method testCreateSubscriptionWithCatalogPlugin.

@Test(groups = "slow")
public void testCreateSubscriptionWithCatalogPlugin() throws Exception {
    // We take april as it has 30 days (easier to play with BCD)
    // Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
    clock.setDay(new LocalDate(2012, 4, 1));
    final AccountData accountData = getAccountData(1);
    final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
    accountChecker.checkAccount(account.getId(), accountData, callContext);
    // Create original subscription (Trial PHASE) -> $0 invoice.
    final DefaultEntitlement bpSubscription = createBaseEntitlementAndCheckForCompletion(account.getId(), "bundleKey", "Pistol", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
    invoiceChecker.checkInvoice(account.getId(), 1, callContext, new ExpectedInvoiceItemCheck(new LocalDate(2012, 4, 1), null, InvoiceItemType.FIXED, new BigDecimal("0")));
    subscriptionChecker.checkSubscriptionCreated(bpSubscription.getId(), internalCallContext);
}
Also used : Account(org.killbill.billing.account.api.Account) AccountData(org.killbill.billing.account.api.AccountData) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) LocalDate(org.joda.time.LocalDate) ExpectedInvoiceItemCheck(org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 30 with ExpectedInvoiceItemCheck

use of org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck in project killbill by killbill.

the class TestWithPriceOverride method testCreatWithFixedPriceOverride.

@Test(groups = "slow")
public void testCreatWithFixedPriceOverride() throws Exception {
    // We take april as it has 30 days (easier to play with BCD)
    // Set clock to the initial start date - we implicitly assume here that the account timezone is UTC
    clock.setDay(new LocalDate(2012, 4, 1));
    final AccountData accountData = getAccountData(1);
    final Account account = createAccountWithNonOsgiPaymentMethod(accountData);
    accountChecker.checkAccount(account.getId(), accountData, callContext);
    final List<PlanPhasePriceOverride> overrides = new ArrayList<PlanPhasePriceOverride>();
    overrides.add(new DefaultPlanPhasePriceOverride("shotgun-monthly-trial", account.getCurrency(), BigDecimal.ONE, null));
    final DefaultEntitlement bpSubscription = createBaseEntitlementWithPriceOverrideAndCheckForCompletion(account.getId(), "bundleKey", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, overrides, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    // Check bundle after BP got created otherwise we get an error from auditApi.
    subscriptionChecker.checkSubscriptionCreated(bpSubscription.getId(), internalCallContext);
    invoiceChecker.checkInvoice(account.getId(), 1, callContext, new ExpectedInvoiceItemCheck(clock.getUTCToday(), null, InvoiceItemType.FIXED, new BigDecimal("1")));
}
Also used : Account(org.killbill.billing.account.api.Account) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) AccountData(org.killbill.billing.account.api.AccountData) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) ArrayList(java.util.ArrayList) LocalDate(org.joda.time.LocalDate) ExpectedInvoiceItemCheck(org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck) BigDecimal(java.math.BigDecimal) DefaultPlanPhasePriceOverride(org.killbill.billing.catalog.DefaultPlanPhasePriceOverride) PlanPhasePriceOverride(org.killbill.billing.catalog.api.PlanPhasePriceOverride) Test(org.testng.annotations.Test)

Aggregations

LocalDate (org.joda.time.LocalDate)85 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)85 BigDecimal (java.math.BigDecimal)84 Test (org.testng.annotations.Test)84 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)78 Account (org.killbill.billing.account.api.Account)63 DateTime (org.joda.time.DateTime)48 Invoice (org.killbill.billing.invoice.api.Invoice)45 ArrayList (java.util.ArrayList)30 AccountData (org.killbill.billing.account.api.AccountData)26 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)20 ExpectedPaymentCheck (org.killbill.billing.beatrix.util.PaymentChecker.ExpectedPaymentCheck)11 Payment (org.killbill.billing.payment.api.Payment)11 UUID (java.util.UUID)8 Entitlement (org.killbill.billing.entitlement.api.Entitlement)8 DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)8 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)6 HashMap (java.util.HashMap)5 DefaultPlanPhasePriceOverride (org.killbill.billing.catalog.DefaultPlanPhasePriceOverride)5 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)5