@VisibleForTesting void processFixedBillingEvents(final UUID invoiceId, final UUID accountId, final BillingEventSet events, final LocalDate targetDate, final Currency currency, final List<InvoiceItem> proposedItems, final InternalCallContext internalCallContext) throws InvoiceApiException { if (events.isEmpty()) { return; } InvoiceItem prevItem = null; // Pretty-print the generated invoice items from the junction events final InvoiceItemGeneratorLogger invoiceItemGeneratorLogger = new InvoiceItemGeneratorLogger(invoiceId, accountId, "fixed", log); final Iterator<BillingEvent> eventIt = events.iterator(); while (eventIt.hasNext()) { final BillingEvent thisEvent = eventIt.next(); final InvoiceItem currentFixedPriceItem = generateFixedPriceItem(invoiceId, accountId, thisEvent, targetDate, currency, invoiceItemGeneratorLogger, internalCallContext); if (!isSameDayAndSameSubscription(prevItem, thisEvent, internalCallContext) && prevItem != null) { proposedItems.add(prevItem); } prevItem = currentFixedPriceItem; } // The last one if not null can always be inserted as there is nothing after to cancel it off. if (prevItem != null) { proposedItems.add(prevItem); } invoiceItemGeneratorLogger.logItems(); }
private void processSubscriptionStartRequestedDateWithLock(final UUID accountId, final RequestedSubscriptionInternalEvent transition, final InternalCallContext context) { try { final BillingEventSet billingEvents = billingApi.getBillingEventsForAccountAndUpdateAccountBCD(accountId, null, context); if (billingEvents.isEmpty()) { return; } final FutureAccountNotificationsBuilder notificationsBuilder = new FutureAccountNotificationsBuilder(); populateNextFutureDryRunNotificationDate(billingEvents, notificationsBuilder, context); final ImmutableAccountData account = accountApi.getImmutableAccountDataById(accountId, context); commitInvoiceAndSetFutureNotifications(account, notificationsBuilder.build(), context); } catch (final SubscriptionBaseApiException e) { log.warn("Failed handling SubscriptionBase change.", new InvoiceApiException(ErrorCode.INVOICE_NO_ACCOUNT_ID_FOR_SUBSCRIPTION_ID, transition.getSubscriptionId().toString())); } catch (final AccountApiException e) { log.warn("Failed to retrieve BillingEvents for accountId='{}'", accountId, e); } catch (final CatalogApiException e) { log.warn("Failed to retrieve BillingEvents for accountId='{}'", accountId, e); } }
private void processRecurringBillingEvents(final UUID invoiceId, final UUID accountId, final BillingEventSet events, final LocalDate targetDate, final Currency currency, final List<InvoiceItem> proposedItems, final Map<UUID, SubscriptionFutureNotificationDates> perSubscriptionFutureNotificationDate, final InternalCallContext internalCallContext) throws InvoiceApiException { if (events.isEmpty()) { return; } // Pretty-print the generated invoice items from the junction events final InvoiceItemGeneratorLogger invoiceItemGeneratorLogger = new InvoiceItemGeneratorLogger(invoiceId, accountId, "recurring", log); final Iterator<BillingEvent> eventIt = events.iterator(); BillingEvent nextEvent = eventIt.next(); while (eventIt.hasNext()) { final BillingEvent thisEvent = nextEvent; nextEvent = eventIt.next(); if (!events.getSubscriptionIdsWithAutoInvoiceOff(). contains(thisEvent.getSubscription().getId())) { // don't consider events for subscriptions that have auto_invoice_off final BillingEvent adjustedNextEvent = (thisEvent.getSubscription().getId() == nextEvent.getSubscription().getId()) ? nextEvent : null; final List<InvoiceItem> newProposedItems = processRecurringEvent(invoiceId, accountId, thisEvent, adjustedNextEvent, targetDate, currency, invoiceItemGeneratorLogger, thisEvent.getPlan().getRecurringBillingMode(), perSubscriptionFutureNotificationDate, internalCallContext); proposedItems.addAll(newProposedItems); } } final List<InvoiceItem> newProposedItems = processRecurringEvent(invoiceId, accountId, nextEvent, null, targetDate, currency, invoiceItemGeneratorLogger, nextEvent.getPlan().getRecurringBillingMode(), perSubscriptionFutureNotificationDate, internalCallContext); proposedItems.addAll(newProposedItems); invoiceItemGeneratorLogger.logItems(); }
if (billingEvents.isEmpty()) { return null;