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); } }
public UUID generateRegularInvoice(final Account account, final BigDecimal fixedPrice, final BigDecimal recurringPrice, final LocalDate targetDate, final CallContext callContext) throws Exception { final SubscriptionBase subscription = Mockito.mock(SubscriptionBase.class); Mockito.when(subscription.getId()).thenReturn(UUID.randomUUID()); Mockito.when(subscription.getBundleId()).thenReturn(new UUID(0L, 0L)); final BillingEventSet events = new MockBillingEventSet(); final Plan plan = MockPlan.createBicycleNoTrialEvergreen1USD(); final PlanPhase planPhase = MockPlanPhase.create1USDMonthlyEvergreen(); final DateTime effectiveDate = new DateTime().minusDays(1); final Currency currency = Currency.USD; events.add(createMockBillingEvent(account, subscription, effectiveDate, plan, planPhase, fixedPrice, recurringPrice, currency, BillingPeriod.MONTHLY, 1, BillingMode.IN_ADVANCE, "", 1L, SubscriptionBaseTransitionType.CREATE)); Mockito.when(billingApi.getBillingEventsForAccountAndUpdateAccountBCD(Mockito.<UUID>any(), Mockito.<DryRunArguments>any(), Mockito.<InternalCallContext>any())).thenReturn(events); final InternalCallContext context = internalCallContextFactory.createInternalCallContext(account.getId(), callContext); Invoice invoice = generateInvoice(account.getId(), targetDate, new DryRunFutureDateArguments(), context); Assert.assertNotNull(invoice); List<InvoiceModelDao> invoices = invoiceDao.getInvoicesByAccount(false, context); Assert.assertEquals(invoices.size(), 0); invoice = generateInvoice(account.getId(), targetDate, null, context); Assert.assertNotNull(invoice); invoices = invoiceDao.getInvoicesByAccount(false, context); Assert.assertEquals(invoices.size(), 1); return invoice.getId(); }
final BillingEventSet billingEvents = billingApi.getBillingEventsForAccountAndUpdateAccountBCD(accountId, dryRunArguments, context); if (billingEvents.isEmpty()) { return null;
BillingMode.IN_ADVANCE, "", 1L, SubscriptionBaseTransitionType.CREATE)); Mockito.when(billingApi.getBillingEventsForAccountAndUpdateAccountBCD(Mockito.<UUID>any(), Mockito.<DryRunArguments>any(), Mockito.<InternalCallContext>any())).thenReturn(events);
31, BillingMode.IN_ADVANCE, "CHANGE", 3L, SubscriptionBaseTransitionType.CHANGE)); Mockito.when(billingApi.getBillingEventsForAccountAndUpdateAccountBCD(Mockito.<UUID>any(), Mockito.<DryRunArguments>any(), Mockito.<InternalCallContext>any())).thenReturn(events); final InvoiceDispatcher dispatcher = new InvoiceDispatcher(generator, accountApi, billingApi, subscriptionApi, invoiceDao, internalCallContextFactory, invoicePluginDispatcher, locker, busService.getBus(),
BillingMode.IN_ADVANCE, "", 1L, SubscriptionBaseTransitionType.CREATE)); Mockito.when(billingApi.getBillingEventsForAccountAndUpdateAccountBCD(Mockito.<UUID>any(), Mockito.<DryRunArguments>any(), Mockito.<InternalCallContext>any())).thenReturn(events);