Search in sources :

Example 1 with DefaultSubscriptionBase

use of org.killbill.billing.subscription.api.user.DefaultSubscriptionBase in project killbill by killbill.

the class DefaultSubscriptionDao method createSubscriptionForInternalUse.

private SubscriptionBase createSubscriptionForInternalUse(final SubscriptionBase shellSubscription, final List<SubscriptionBaseEvent> events, final InternalTenantContext context) throws CatalogApiException {
    final DefaultSubscriptionBase result = new DefaultSubscriptionBase(new SubscriptionBuilder(((DefaultSubscriptionBase) shellSubscription)), null, clock);
    if (!events.isEmpty()) {
        final Catalog fullCatalog = catalogService.getFullCatalog(true, true, context);
        result.rebuildTransitions(events, fullCatalog);
    }
    return result;
}
Also used : DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) SubscriptionBuilder(org.killbill.billing.subscription.api.user.SubscriptionBuilder) Catalog(org.killbill.billing.catalog.api.Catalog)

Example 2 with DefaultSubscriptionBase

use of org.killbill.billing.subscription.api.user.DefaultSubscriptionBase in project killbill by killbill.

the class DefaultSubscriptionDao method createSubscriptionWithNewEvent.

//
// Creates a copy of the existing subscriptions whose 'transitions' will reflect the new event
//
private DefaultSubscriptionBase createSubscriptionWithNewEvent(final DefaultSubscriptionBase subscription, final SubscriptionBaseEvent newEvent, final InternalTenantContext context) throws CatalogApiException {
    final DefaultSubscriptionBase subscriptionWithNewEvent = new DefaultSubscriptionBase(subscription, null, clock);
    final List<SubscriptionBaseEvent> allEvents = new LinkedList<SubscriptionBaseEvent>();
    if (subscriptionWithNewEvent.getEvents() != null) {
        allEvents.addAll(subscriptionWithNewEvent.getEvents());
    }
    allEvents.add(newEvent);
    subscriptionWithNewEvent.rebuildTransitions(allEvents, catalogService.getFullCatalog(true, true, context));
    return subscriptionWithNewEvent;
}
Also used : DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) SubscriptionBaseEvent(org.killbill.billing.subscription.events.SubscriptionBaseEvent) LinkedList(java.util.LinkedList)

Example 3 with DefaultSubscriptionBase

use of org.killbill.billing.subscription.api.user.DefaultSubscriptionBase in project killbill by killbill.

the class TestIntegrationInvoice method testDryRunWithNoTargetDate.

//
// Basic test with one subscription that verifies the behavior of using invoice dryRun api with no date
//
@Test(groups = "slow")
public void testDryRunWithNoTargetDate() throws Exception {
    final int billingDay = 14;
    final DateTime initialCreationDate = new DateTime(2015, 5, 15, 0, 0, 0, 0, testTimeZone);
    // set clock to the initial start date
    clock.setTime(initialCreationDate);
    log.info("Beginning test with BCD of " + billingDay);
    final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(billingDay));
    int invoiceItemCount = 1;
    //
    // CREATE SUBSCRIPTION AND EXPECT BOTH EVENTS: NextEvent.CREATE, NextEvent.BLOCK NextEvent.INVOICE
    //
    DefaultEntitlement baseEntitlement = createBaseEntitlementAndCheckForCompletion(account.getId(), "bundleKey", "Shotgun", ProductCategory.BASE, BillingPeriod.MONTHLY, NextEvent.CREATE, NextEvent.BLOCK, NextEvent.INVOICE);
    DefaultSubscriptionBase subscription = subscriptionDataFromSubscription(baseEntitlement.getSubscriptionBase());
    invoiceChecker.checkInvoice(account.getId(), invoiceItemCount++, callContext, new ExpectedInvoiceItemCheck(initialCreationDate.toLocalDate(), null, InvoiceItemType.FIXED, new BigDecimal("0")));
    // No end date for the trial item (fixed price of zero), and CTD should be today (i.e. when the trial started)
    invoiceChecker.checkChargedThroughDate(subscription.getId(), clock.getUTCToday(), callContext);
    final List<ExpectedInvoiceItemCheck> expectedInvoices = new ArrayList<ExpectedInvoiceItemCheck>();
    expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2015, 6, 14), new LocalDate(2015, 7, 14), InvoiceItemType.RECURRING, new BigDecimal("249.95")));
    // This will verify that the upcoming Phase is found and the invoice is generated at the right date, with correct items
    DryRunArguments dryRun = new TestDryRunArguments(DryRunType.UPCOMING_INVOICE);
    Invoice dryRunInvoice = invoiceUserApi.triggerInvoiceGeneration(account.getId(), null, dryRun, callContext);
    invoiceChecker.checkInvoiceNoAudits(dryRunInvoice, callContext, expectedInvoices);
    // Move through time and verify we get the same invoice
    busHandler.pushExpectedEvents(NextEvent.PHASE, NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    clock.addDays(30);
    assertListenerStatus();
    List<Invoice> invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
    invoiceChecker.checkInvoice(invoices.get(1).getId(), callContext, expectedInvoices);
    expectedInvoices.clear();
    // This will verify that the upcoming invoice notification is found and the invoice is generated at the right date, with correct items
    expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2015, 7, 14), new LocalDate(2015, 8, 14), InvoiceItemType.RECURRING, new BigDecimal("249.95")));
    dryRunInvoice = invoiceUserApi.triggerInvoiceGeneration(account.getId(), null, dryRun, callContext);
    invoiceChecker.checkInvoiceNoAudits(dryRunInvoice, callContext, expectedInvoices);
    // Move through time and verify we get the same invoice
    busHandler.pushExpectedEvents(NextEvent.INVOICE, NextEvent.PAYMENT, NextEvent.INVOICE_PAYMENT);
    clock.addMonths(1);
    assertListenerStatus();
    invoices = invoiceUserApi.getInvoicesByAccount(account.getId(), false, callContext);
    invoiceChecker.checkInvoice(invoices.get(2).getId(), callContext, expectedInvoices);
    expectedInvoices.clear();
    // One more time, this will verify that the upcoming invoice notification is found and the invoice is generated at the right date, with correct items
    expectedInvoices.add(new ExpectedInvoiceItemCheck(new LocalDate(2015, 8, 14), new LocalDate(2015, 9, 14), InvoiceItemType.RECURRING, new BigDecimal("249.95")));
    dryRunInvoice = invoiceUserApi.triggerInvoiceGeneration(account.getId(), null, dryRun, callContext);
    invoiceChecker.checkInvoiceNoAudits(dryRunInvoice, callContext, expectedInvoices);
}
Also used : Account(org.killbill.billing.account.api.Account) Invoice(org.killbill.billing.invoice.api.Invoice) DryRunArguments(org.killbill.billing.invoice.api.DryRunArguments) ArrayList(java.util.ArrayList) ExpectedInvoiceItemCheck(org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck) LocalDate(org.joda.time.LocalDate) DateTime(org.joda.time.DateTime) BigDecimal(java.math.BigDecimal) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) Test(org.testng.annotations.Test)

Example 4 with DefaultSubscriptionBase

use of org.killbill.billing.subscription.api.user.DefaultSubscriptionBase in project killbill by killbill.

the class DefaultSubscriptionBaseTimelineApi method createGetSubscriptionRepairList.

private List<SubscriptionBaseTimeline> createGetSubscriptionRepairList(final List<SubscriptionBase> subscriptions, final List<SubscriptionBaseTimeline> inRepair, final InternalTenantContext tenantContext) throws CatalogApiException {
    final List<SubscriptionBaseTimeline> result = new LinkedList<SubscriptionBaseTimeline>();
    final Set<UUID> repairIds = new TreeSet<UUID>();
    for (final SubscriptionBaseTimeline cur : inRepair) {
        repairIds.add(cur.getId());
        result.add(cur);
    }
    for (final SubscriptionBase cur : subscriptions) {
        if (!repairIds.contains(cur.getId())) {
            result.add(new DefaultSubscriptionBaseTimeline((DefaultSubscriptionBase) cur, catalogService.getFullCatalog(true, true, tenantContext)));
        }
    }
    return result;
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) TreeSet(java.util.TreeSet) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) UUID(java.util.UUID) LinkedList(java.util.LinkedList)

Example 5 with DefaultSubscriptionBase

use of org.killbill.billing.subscription.api.user.DefaultSubscriptionBase in project killbill by killbill.

the class DefaultSubscriptionBaseTimelineApi method getViewId.

private String getViewId(final DateTime lastUpdateBundleDate, final List<SubscriptionBase> subscriptions) {
    final StringBuilder tmp = new StringBuilder();
    long lastOrderedId = -1;
    for (final SubscriptionBase cur : subscriptions) {
        lastOrderedId = lastOrderedId < ((DefaultSubscriptionBase) cur).getLastEventOrderedId() ? ((DefaultSubscriptionBase) cur).getLastEventOrderedId() : lastOrderedId;
    }
    tmp.append(lastOrderedId);
    tmp.append("-");
    tmp.append(lastUpdateBundleDate.toDate().getTime());
    return tmp.toString();
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)

Aggregations

DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)63 DateTime (org.joda.time.DateTime)38 Test (org.testng.annotations.Test)30 SubscriptionBaseEvent (org.killbill.billing.subscription.events.SubscriptionBaseEvent)18 Plan (org.killbill.billing.catalog.api.Plan)17 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)17 ArrayList (java.util.ArrayList)16 LocalDate (org.joda.time.LocalDate)13 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)13 SubscriptionBuilder (org.killbill.billing.subscription.api.user.SubscriptionBuilder)13 BigDecimal (java.math.BigDecimal)12 Account (org.killbill.billing.account.api.Account)12 ExpectedInvoiceItemCheck (org.killbill.billing.beatrix.util.InvoiceChecker.ExpectedInvoiceItemCheck)12 DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)12 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)11 LinkedList (java.util.LinkedList)10 SubscriptionBaseBundle (org.killbill.billing.subscription.api.user.SubscriptionBaseBundle)10 UUID (java.util.UUID)9 Invoice (org.killbill.billing.invoice.api.Invoice)9 BillingPeriod (org.killbill.billing.catalog.api.BillingPeriod)8