private void processUnpaid_AUTO_PAY_OFF_payments(final UUID accountId, final Long accountRecordId, final Long tenantRecordId, final UUID userToken) { try { final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(tenantRecordId, accountRecordId, "PaymentRequestProcessor", CallOrigin.INTERNAL, UserType.SYSTEM, userToken); final Account account = accountApi.getAccountById(accountId, internalCallContext); paymentProcessor.process_AUTO_PAY_OFF_removal(account, internalCallContext); } catch (AccountApiException e) { log.warn(String.format("Failed to process process removal AUTO_PAY_OFF for account %s", accountId), e); } catch (PaymentApiException e) { log.warn(String.format("Failed to process process removal AUTO_PAY_OFF for account %s", accountId), e); } } }
@SuppressWarnings("unchecked") public OverdueWrapper createOverdueWrapperFor(final UUID id, final InternalTenantContext context) throws OverdueException { try { Account account = accountApi.getAccountById(id, context); return new OverdueWrapper(account, api, getOverdueStateSet(), clock, billingStateCalculator, overdueStateApplicator); } catch (AccountApiException e) { throw new OverdueException(e); } }
@Override @BeforeMethod(groups = "fast") public void beforeMethod() throws Exception { super.beforeMethod(); final Account account = Mockito.mock(Account.class); Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC); Mockito.when(accountApi.getAccountById(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(account); }
private Account createAccount(final int billCycleDay) throws AccountApiException { final Account account = Mockito.mock(Account.class); Mockito.when(account.getBillCycleDayLocal()).thenReturn(billCycleDay); Mockito.when(account.getCurrency()).thenReturn(Currency.USD); Mockito.when(account.getId()).thenReturn(UUID.randomUUID()); Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC); Mockito.when(accountInternalApi.getAccountById(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(account); return account; }
@Override public UUID createMigrationInvoice(final UUID accountId, final LocalDate targetDate, final BigDecimal balance, final Currency currency, final CallContext context) { try { accountUserApi.getAccountById(accountId, internalCallContextFactory.createInternalTenantContext(accountId, context)); } catch (AccountApiException e) { log.warn("Unable to find account for id {}", accountId); return null; } final InvoiceModelDao migrationInvoice = new InvoiceModelDao(accountId, clock.getUTCToday(), targetDate, currency, true); final InvoiceItemModelDao migrationInvoiceItem = new InvoiceItemModelDao(context.getCreatedDate(), InvoiceItemType.FIXED, migrationInvoice.getId(), accountId, null, null, MigrationPlan.MIGRATION_PLAN_NAME, MigrationPlan.MIGRATION_PLAN_PHASE_NAME, targetDate, null, balance, null, currency, null); dao.createInvoice(migrationInvoice, ImmutableList.<InvoiceItemModelDao>of(migrationInvoiceItem), ImmutableList.<InvoicePaymentModelDao>of(), true, ImmutableMap.<UUID, DateTime>of(), internalCallContextFactory.createInternalCallContext(accountId, context)); return migrationInvoice.getId(); } }
CallOrigin.INTERNAL, UserType.SYSTEM, null); final Account account = accountInternalApi.getAccountById(refundsToBeFixed.iterator().next().getAccountId(), context); new WithAccountLock<Void>().processAccountWithLock(locker, account.getExternalKey(), new WithAccountLockCallback<Void>() {
@Override @BeforeMethod(groups = "slow") public void beforeMethod() throws Exception { //super.beforeMethod(); // We override the parent method on purpose, because we want to register a different OverdueCheckNotifier final Account account = Mockito.mock(Account.class); Mockito.when(accountApi.getAccountById(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(account); mockDispatcher = new OverdueDispatcherMock(internalCallContextFactory); notifierForMock = new OverdueCheckNotifier(notificationQueueService, overdueProperties, internalCallContextFactory, mockDispatcher); notifierForMock.initialize(); notifierForMock.start(); }
@Override public BillingEventSet getBillingEventsForAccountAndUpdateAccountBCD(final UUID accountId, final InternalCallContext context) { final List<SubscriptionBaseBundle> bundles = subscriptionApi.getBundlesForAccount(accountId, context); final DefaultBillingEventSet result = new DefaultBillingEventSet(); try { final Account account = accountApi.getAccountById(accountId, context); // Check to see if billing is off for the account final List<Tag> accountTags = tagApi.getTags(accountId, ObjectType.ACCOUNT, context); final boolean found_AUTO_INVOICING_OFF = is_AUTO_INVOICING_OFF(accountTags); if (found_AUTO_INVOICING_OFF) { result.setAccountAutoInvoiceIsOff(true); return result; // billing is off, we are done } addBillingEventsForBundles(bundles, account, context, result); } catch (AccountApiException e) { log.warn("Failed while getting BillingEvent", e); } // Pretty-print the events, before and after the blocking calculator does its magic final StringBuilder logStringBuilder = new StringBuilder("Computed billing events for accountId ").append(accountId); eventsToString(logStringBuilder, result, "\nBilling Events Raw"); blockCalculator.insertBlockingEvents(result, context); eventsToString(logStringBuilder, result, "\nBilling Events After Blocking"); log.info(logStringBuilder.toString()); return result; }
public Account createAccount(final LocalDate dateOfLastUnPaidInvoice) throws SubscriptionBaseApiException, AccountApiException { final UUID accountId = UUID.randomUUID(); final Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(accountId); Mockito.when(account.getTimeZone()).thenReturn(DateTimeZone.UTC); Mockito.when(accountInternalApi.getAccountById(Mockito.eq(account.getId()), Mockito.<InternalTenantContext>any())).thenReturn(account); final Invoice invoice = Mockito.mock(Invoice.class); Mockito.when(invoice.getInvoiceDate()).thenReturn(dateOfLastUnPaidInvoice); Mockito.when(invoice.getBalance()).thenReturn(BigDecimal.TEN); Mockito.when(invoice.getId()).thenReturn(UUID.randomUUID()); final InvoiceItem item = Mockito.mock(InvoiceItem.class); final List<InvoiceItem> items = new ArrayList<InvoiceItem>(); items.add(item); Mockito.when(invoice.getInvoiceItems()).thenReturn(items); final List<Invoice> invoices = new ArrayList<Invoice>(); invoices.add(invoice); Mockito.when(invoiceInternalApi.getUnpaidInvoicesByAccountId(Mockito.<UUID>any(), Mockito.<LocalDate>any(), Mockito.<InternalTenantContext>any())).thenReturn(invoices); return account; }
final Account account = accountInternalApi.getAccountById(payment.getAccountId(), context); final PaymentPluginApi plugin = getPaymentProviderPlugin(account, context);
public Account createTestAccount(final String email, final boolean addPaymentMethod) throws Exception { final String name = "First" + UUID.randomUUID().toString() + " " + "Last" + UUID.randomUUID().toString(); final String externalKey = UUID.randomUUID().toString(); final Account account = Mockito.mock(Account.class); Mockito.when(account.getId()).thenReturn(UUID.randomUUID()); Mockito.when(account.getExternalKey()).thenReturn(externalKey); Mockito.when(account.getName()).thenReturn(name); Mockito.when(account.getFirstNameLength()).thenReturn(10); Mockito.when(account.getPhone()).thenReturn("123-456-7890"); Mockito.when(account.getEmail()).thenReturn(email); Mockito.when(account.getCurrency()).thenReturn(Currency.USD); Mockito.when(account.getBillCycleDayLocal()).thenReturn(1); Mockito.when(account.isMigrated()).thenReturn(false); Mockito.when(account.isNotifiedForInvoices()).thenReturn(false); Mockito.when(AccountApi.getAccountById(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(AccountApi.getAccountByKey(Mockito.anyString(), Mockito.<InternalTenantContext>any())).thenReturn(account); if (addPaymentMethod) { final PaymentMethodPlugin pm = new DefaultNoOpPaymentMethodPlugin(UUID.randomUUID().toString(), true, null); addTestPaymentMethod(account, pm); } return account; }
@Subscribe public void processInvoiceEvent(final InvoiceCreationInternalEvent event) { log.info("Received invoice creation notification for account {} and invoice {}", event.getAccountId(), event.getInvoiceId()); final Account account; try { final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContext(event.getSearchKey2(), event.getSearchKey1(), "PaymentRequestProcessor", CallOrigin.INTERNAL, UserType.SYSTEM, event.getUserToken()); account = accountApi.getAccountById(event.getAccountId(), internalContext); paymentProcessor.createPayment(account, event.getInvoiceId(), null, internalContext, false, false); } catch (AccountApiException e) { log.error("Failed to process invoice payment", e); } catch (PaymentApiException e) { // Log as error unless: if (e.getCode() != ErrorCode.PAYMENT_NULL_INVOICE.getCode() /* Nothing left to be paid */ && e.getCode() != ErrorCode.PAYMENT_CREATE_PAYMENT.getCode() /* User payment error */) { log.error("Failed to process invoice payment {}", e.toString()); } } } }
@Override public String getInvoiceAsHTML(final UUID invoiceId, final TenantContext context) throws AccountApiException, IOException, InvoiceApiException { final Invoice invoice = getInvoice(invoiceId, context); if (invoice == null) { throw new InvoiceApiException(ErrorCode.INVOICE_NOT_FOUND, invoiceId); } final InternalTenantContext internalContext = internalCallContextFactory.createInternalTenantContext(invoiceId, ObjectType.INVOICE, context); final Account account = accountUserApi.getAccountById(invoice.getAccountId(), internalContext); // Check if this account has the MANUAL_PAY system tag boolean manualPay = false; final List<Tag> accountTags = tagApi.getTags(account.getId(), ObjectType.ACCOUNT, internalContext); for (final Tag tag : accountTags) { if (ControlTagType.MANUAL_PAY.getId().equals(tag.getTagDefinitionId())) { manualPay = true; break; } } return generator.generateInvoice(account, invoice, manualPay); }
public EventsStream buildForEntitlement(final UUID entitlementId, final InternalTenantContext internalTenantContext) throws EntitlementApiException { final SubscriptionBaseBundle bundle; final SubscriptionBase subscription; final List<SubscriptionBase> allSubscriptionsForBundle; final SubscriptionBase baseSubscription; try { subscription = subscriptionInternalApi.getSubscriptionFromId(entitlementId, internalTenantContext); bundle = subscriptionInternalApi.getBundleFromId(subscription.getBundleId(), internalTenantContext); allSubscriptionsForBundle = subscriptionInternalApi.getSubscriptionsForBundle(subscription.getBundleId(), internalTenantContext); baseSubscription = Iterables.<SubscriptionBase>tryFind(allSubscriptionsForBundle, new Predicate<SubscriptionBase>() { @Override public boolean apply(final SubscriptionBase input) { return ProductCategory.BASE.equals(input.getLastActiveProduct().getCategory()); } }).orNull(); // null for standalone subscriptions } catch (SubscriptionBaseApiException e) { throw new EntitlementApiException(e); } final Account account; try { account = accountInternalApi.getAccountById(bundle.getAccountId(), internalTenantContext); } catch (AccountApiException e) { throw new EntitlementApiException(e); } // Retrieve the blocking states final List<BlockingState> blockingStatesForAccount = defaultBlockingStateDao.getBlockingAllForAccountRecordId(internalTenantContext); return buildForEntitlement(blockingStatesForAccount, account, bundle, baseSubscription, subscription, allSubscriptionsForBundle, internalTenantContext); }
@Override public Invoice triggerInvoiceGeneration(final UUID accountId, final LocalDate targetDate, final boolean dryRun, final CallContext context) throws InvoiceApiException { final InternalCallContext internalContext = internalCallContextFactory.createInternalCallContext(accountId, context); final Account account; try { account = accountUserApi.getAccountById(accountId, internalContext); } catch (AccountApiException e) { throw new InvoiceApiException(e, ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID, e.toString()); } final DateTime processingDateTime = targetDate.toDateTimeAtCurrentTime(account.getTimeZone()); final Invoice result = dispatcher.processAccount(accountId, processingDateTime, dryRun, internalContext); if (result == null) { throw new InvoiceApiException(ErrorCode.INVOICE_NOTHING_TO_DO, accountId, targetDate); } else { return result; } }
final Account account = accountApi.getAccountById(accountId, context); final DateAndTimeZoneContext dateAndTimeZoneContext = billingEvents.iterator().hasNext() ? new DateAndTimeZoneContext(billingEvents.iterator().next().getEffectiveDate(), account.getTimeZone(), clock) :
final InternalCallContext contextWithValidAccountRecordId = internalCallContextFactory.createInternalCallContext(bundleId, ObjectType.BUNDLE, context); final SubscriptionBaseBundle bundle = subscriptionBaseInternalApi.getBundleFromId(bundleId, contextWithValidAccountRecordId); final Account account = accountApi.getAccountById(bundle.getAccountId(), contextWithValidAccountRecordId); final SubscriptionBase baseSubscription = subscriptionBaseInternalApi.getBaseSubscription(bundleId, contextWithValidAccountRecordId);
final Account account = accountApi.getAccountById(bundle.getAccountId(), contextWithValidAccountRecordId); final SubscriptionBase baseSubscription = subscriptionBaseInternalApi.getBaseSubscription(bundleId, contextWithValidAccountRecordId); final DateTime effectiveDate = dateHelper.fromLocalDateAndReferenceTime(localEffectiveDate, baseSubscription.getStartDate(), contextWithValidAccountRecordId);