protected void clearFutureNotification(final ImmutableAccountData account, final InternalCallContext context) { // Need to clear the override table here too (when we add it) checkPoster.clearOverdueCheckNotifications(account.getId(), OverdueCheckNotifier.OVERDUE_CHECK_NOTIFIER_QUEUE, OverdueCheckNotificationKey.class, context); }
/** * Create an internal tenant callcontext * * @param tenantRecordId tenant_record_id (cannot be null) * @param accountRecordId account_record_id (cannot be null for INSERT operations) * @return internal tenant callcontext */ public InternalTenantContext createInternalTenantContext(final Long tenantRecordId, @Nullable final Long accountRecordId) { populateMDCContext(null, accountRecordId, tenantRecordId); if (accountRecordId == null) { return new InternalTenantContext(tenantRecordId); } else { final ImmutableAccountData immutableAccountData = getImmutableAccountData(accountRecordId, tenantRecordId); final DateTimeZone fixedOffsetTimeZone = immutableAccountData.getFixedOffsetTimeZone(); final DateTime referenceTime = immutableAccountData.getReferenceTime(); return new InternalTenantContext(tenantRecordId, accountRecordId, fixedOffsetTimeZone, referenceTime); } }
@Override public void installInternalApi() { final ImmutableAccountData immutableAccountData = Mockito.mock(ImmutableAccountData.class); Mockito.when(immutableAccountData.getTimeZone()).thenReturn(DateTimeZone.UTC); Mockito.when(immutableAccountData.getFixedOffsetTimeZone()).thenReturn(DateTimeZone.UTC); final AccountInternalApi accountInternalApi = Mockito.mock(AccountInternalApi.class); final ImmutableAccountInternalApi immutableAccountInternalApi = Mockito.mock(ImmutableAccountInternalApi.class); bind(AccountInternalApi.class).toInstance(accountInternalApi); bind(ImmutableAccountInternalApi.class).toInstance(immutableAccountInternalApi); } }
log.info("Setting account BCD='{}', accountId='{}'", accountBCDCandidate, account.getId()); accountApi.updateBCD(account.getExternalKey(), accountBCDCandidate, context);
private InvoiceWithMetadata generateKillBillInvoice(final ImmutableAccountData account, final LocalDate targetDate, final BillingEventSet billingEvents, final List<Invoice> existingInvoices, final InternalCallContext context) throws InvoiceApiException { final UUID targetInvoiceId; // Filter out DRAFT invoices for computation of existing items unless Account is in AUTO_INVOICING_REUSE_DRAFT if (billingEvents.isAccountAutoInvoiceReuseDraft()) { final Invoice existingDraft = Iterables.tryFind(existingInvoices, new Predicate<Invoice>() { @Override public boolean apply(final Invoice input) { return input.getStatus() == InvoiceStatus.DRAFT; } }).orNull(); targetInvoiceId = existingDraft != null ? existingDraft.getId() : null; } else { targetInvoiceId = null; } return generator.generateInvoice(account, billingEvents, existingInvoices, targetInvoiceId, targetDate, account.getCurrency(), context); }
private void verifyBCDCalculation(final DateTimeZone accountTimeZone, final DateTime startDateUTC, final int bcdLocal) throws AccountApiException, CatalogApiException { final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class); Mockito.when(subscription.getStartDate()).thenReturn(startDateUTC); Mockito.when(subscription.getDateOfFirstRecurringNonZeroCharge()).thenReturn(startDateUTC); final ImmutableAccountData account = Mockito.mock(ImmutableAccountData.class); Mockito.when(account.getTimeZone()).thenReturn(accountTimeZone); final Integer bcd = BillCycleDayCalculator.calculateBcdForAlignment(new HashMap<UUID, Integer>(), subscription, subscription, BillingAlignment.SUBSCRIPTION, internalCallContext, 0); Assert.assertEquals(bcd, (Integer) bcdLocal); }
calculateBcdForTransition(alignment, bcdCache, baseSubscription, subscription, currentAccountBCD, context); final BillingEvent event = new DefaultBillingEvent(transition, subscription, bcdLocal, alignment, account.getCurrency(), catalog); result.add(event);
@Test(groups = "fast") public void testCalculateBCDForAOWithBPCancelledBundleAligned() throws Exception { final DateTimeZone accountTimeZone = DateTimeZone.UTC; final DateTime bpStartDateUTC = new DateTime(2012, 7, 16, 21, 0, 0, DateTimeZone.UTC); final int expectedBCDUTC = 16; // Create a Bundle associated with a subscription final SubscriptionBaseBundle bundle = Mockito.mock(SubscriptionBaseBundle.class); final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class); Mockito.when(subscription.getStartDate()).thenReturn(bpStartDateUTC); // Create a the base plan associated with that subscription final Plan plan = Mockito.mock(Plan.class); final Catalog catalog = Mockito.mock(Catalog.class); Mockito.when(catalog.findPlan(Mockito.anyString(), Mockito.<DateTime>any(), Mockito.<DateTime>any())).thenReturn(plan); Mockito.when(subscription.getLastActivePlan()).thenReturn(plan); Mockito.when(subscription.getDateOfFirstRecurringNonZeroCharge()).thenReturn(bpStartDateUTC); final ImmutableAccountData account = Mockito.mock(ImmutableAccountData.class); Mockito.when(account.getTimeZone()).thenReturn(accountTimeZone); final Integer billCycleDayLocal = BillCycleDayCalculator.calculateBcdForAlignment(new HashMap<UUID, Integer>(), subscription, subscription, BillingAlignment.BUNDLE, internalCallContext, 0); Assert.assertEquals(billCycleDayLocal, (Integer) expectedBCDUTC); }
private void computeEntitlementsToCancel(final ImmutableAccountData account, final List<Entitlement> result, final CallContext context) throws EntitlementApiException { final List<Entitlement> allEntitlementsForAccountId = entitlementApi.getAllEntitlementsForAccountId(account.getId(), context); // Entitlement is smart enough and will cancel the associated add-ons. See also discussion in https://github.com/killbill/killbill/issues/94 final Collection<Entitlement> allEntitlementsButAddonsForAccountId = Collections2.<Entitlement>filter(allEntitlementsForAccountId, new Predicate<Entitlement>() { @Override public boolean apply(final Entitlement entitlement) { // Note: this would miss add-ons created in the future. We should expose a new API to do something similar to EventsStreamBuilder#findBaseSubscription return !ProductCategory.ADD_ON.equals(entitlement.getLastActiveProductCategory()); } }); result.addAll(allEntitlementsButAddonsForAccountId); }
public InternalCallContext createInternalCallContext(final Long accountRecordId, final InternalCallContext context) { final ImmutableAccountData immutableAccountData = getImmutableAccountData(accountRecordId, context.getTenantRecordId()); final DateTimeZone fixedOffsetTimeZone = immutableAccountData.getFixedOffsetTimeZone(); final DateTime referenceTime = immutableAccountData.getReferenceTime(); populateMDCContext(context.getUserToken(), accountRecordId, context.getTenantRecordId()); return new InternalCallContext(context, accountRecordId, fixedOffsetTimeZone, referenceTime, context.getCreatedDate()); }
@Override public void installInternalApi() { final ImmutableAccountData immutableAccountData = Mockito.mock(ImmutableAccountData.class); Mockito.when(immutableAccountData.getTimeZone()).thenReturn(DateTimeZone.UTC); Mockito.when(immutableAccountData.getFixedOffsetTimeZone()).thenReturn(DateTimeZone.UTC); final AccountInternalApi accountInternalApi = Mockito.mock(AccountInternalApi.class); final ImmutableAccountInternalApi immutableAccountInternalApi = Mockito.mock(ImmutableAccountInternalApi.class); bind(AccountInternalApi.class).toInstance(accountInternalApi); bind(ImmutableAccountInternalApi.class).toInstance(immutableAccountInternalApi); } }
final Currency accountCurrency = accountData.getCurrency();
private void verifyBCDCalculation(final DateTimeZone accountTimeZone, final DateTime startDateUTC, final int bcdLocal) throws AccountApiException, CatalogApiException { final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class); Mockito.when(subscription.getStartDate()).thenReturn(startDateUTC); Mockito.when(subscription.getDateOfFirstRecurringNonZeroCharge()).thenReturn(startDateUTC); final ImmutableAccountData account = Mockito.mock(ImmutableAccountData.class); Mockito.when(account.getTimeZone()).thenReturn(accountTimeZone); final Integer bcd = BillCycleDayCalculator.calculateBcdForAlignment(new HashMap<UUID, Integer>(), subscription, subscription, BillingAlignment.SUBSCRIPTION, internalCallContext, 0); Assert.assertEquals(bcd, (Integer) bcdLocal); }
protected void createFutureNotification(final ImmutableAccountData account, final DateTime timeOfNextCheck, final InternalCallContext context) { final OverdueCheckNotificationKey notificationKey = new OverdueCheckNotificationKey(account.getId()); checkPoster.insertOverdueNotification(account.getId(), timeOfNextCheck, OverdueCheckNotifier.OVERDUE_CHECK_NOTIFIER_QUEUE, notificationKey, context); }
} else { final ImmutableAccountData immutableAccountData = getImmutableAccountData(accountRecordId, nonNulTenantRecordId); fixedOffsetTimeZone = immutableAccountData.getFixedOffsetTimeZone(); referenceTime = immutableAccountData.getReferenceTime();
@Test(groups = "fast") public void testCalculateBCDForAOWithBPCancelledBundleAligned() throws Exception { final DateTimeZone accountTimeZone = DateTimeZone.UTC; final DateTime bpStartDateUTC = new DateTime(2012, 7, 16, 21, 0, 0, DateTimeZone.UTC); final int expectedBCDUTC = 16; // Create a Bundle associated with a subscription final SubscriptionBaseBundle bundle = Mockito.mock(SubscriptionBaseBundle.class); final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class); Mockito.when(subscription.getStartDate()).thenReturn(bpStartDateUTC); // Create a the base plan associated with that subscription final Plan plan = Mockito.mock(Plan.class); final Catalog catalog = Mockito.mock(Catalog.class); Mockito.when(catalog.findPlan(Mockito.anyString(), Mockito.<DateTime>any(), Mockito.<DateTime>any())).thenReturn(plan); Mockito.when(subscription.getLastActivePlan()).thenReturn(plan); Mockito.when(subscription.getDateOfFirstRecurringNonZeroCharge()).thenReturn(bpStartDateUTC); final ImmutableAccountData account = Mockito.mock(ImmutableAccountData.class); Mockito.when(account.getTimeZone()).thenReturn(accountTimeZone); final Integer billCycleDayLocal = BillCycleDayCalculator.calculateBcdForAlignment(new HashMap<UUID, Integer>(), subscription, subscription, BillingAlignment.BUNDLE, internalCallContext, 0); Assert.assertEquals(billCycleDayLocal, (Integer) expectedBCDUTC); }
private void avoid_extra_credit_by_toggling_AUTO_INVOICE_OFF(final ImmutableAccountData account, final OverdueState previousOverdueState, final OverdueState nextOverdueState, final InternalCallContext context) throws OverdueApiException { if (isBlockBillingTransition(previousOverdueState, nextOverdueState)) { set_AUTO_INVOICE_OFF_on_blockedBilling(account.getId(), context); } else if (isUnblockBillingTransition(previousOverdueState, nextOverdueState)) { remove_AUTO_INVOICE_OFF_on_clear(account.getId(), context); } }
/** * Create an internal tenant callcontext * * @param tenantRecordId tenant_record_id (cannot be null) * @param accountRecordId account_record_id (cannot be null for INSERT operations) * @return internal tenant callcontext */ public InternalTenantContext createInternalTenantContext(final Long tenantRecordId, @Nullable final Long accountRecordId) { populateMDCContext(null, accountRecordId, tenantRecordId); if (accountRecordId == null) { return new InternalTenantContext(tenantRecordId); } else { final ImmutableAccountData immutableAccountData = getImmutableAccountData(accountRecordId, tenantRecordId); final DateTimeZone fixedOffsetTimeZone = immutableAccountData.getFixedOffsetTimeZone(); final DateTime referenceTime = immutableAccountData.getReferenceTime(); return new InternalTenantContext(tenantRecordId, accountRecordId, fixedOffsetTimeZone, referenceTime); } }
public BillingState calculateBillingState(final ImmutableAccountData account, final InternalCallContext context) throws OverdueException { final SortedSet<Invoice> unpaidInvoices = unpaidInvoicesForAccount(account.getId(), context); final int numberOfUnpaidInvoices = unpaidInvoices.size(); final BigDecimal unpaidInvoiceBalance = sumBalance(unpaidInvoices); LocalDate dateOfEarliestUnpaidInvoice = null; UUID idOfEarliestUnpaidInvoice = null; final Invoice invoice = earliest(unpaidInvoices); if (invoice != null) { dateOfEarliestUnpaidInvoice = invoice.getInvoiceDate(); idOfEarliestUnpaidInvoice = invoice.getId(); } final PaymentResponse responseForLastFailedPayment = PaymentResponse.INSUFFICIENT_FUNDS; //TODO MDW final List<Tag> accountTags = tagApi.getTags(account.getId(), ObjectType.ACCOUNT, context); final Tag[] tags = accountTags.toArray(new Tag[accountTags.size()]); return new BillingState(account.getId(), numberOfUnpaidInvoices, unpaidInvoiceBalance, dateOfEarliestUnpaidInvoice, idOfEarliestUnpaidInvoice, responseForLastFailedPayment, tags); }
public InternalCallContext createInternalCallContext(final Long accountRecordId, final InternalCallContext context) { final ImmutableAccountData immutableAccountData = getImmutableAccountData(accountRecordId, context.getTenantRecordId()); final DateTimeZone fixedOffsetTimeZone = immutableAccountData.getFixedOffsetTimeZone(); final DateTime referenceTime = immutableAccountData.getReferenceTime(); populateMDCContext(context.getUserToken(), accountRecordId, context.getTenantRecordId()); return new InternalCallContext(context, accountRecordId, fixedOffsetTimeZone, referenceTime, context.getCreatedDate()); }