public OverdueWrapper createOverdueWrapperFor(final UUID id, final InternalTenantContext context) throws OverdueException { try { final Account account = accountApi.getAccountById(id, context); return new OverdueWrapper(account, api, getOverdueStateSet(context), locker, clock, billingStateCalculator, overdueStateApplicator, internalCallContextFactory); } catch (final 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); }
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.getStatus()).thenReturn(InvoiceStatus.COMMITTED); 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); final Tag tag = Mockito.mock(Tag.class); Mockito.when(tag.getObjectId()).thenReturn(accountId); Mockito.when(tag.getObjectType()).thenReturn(ObjectType.ACCOUNT); Mockito.when(tag.getTagDefinitionId()).thenReturn(ControlTagType.TEST.getId()); final List<Tag> tags = new ArrayList<Tag>(); tags.add(tag); Mockito.when(tagInternalApi.getTags(Mockito.eq(account.getId()), Mockito.eq(ObjectType.ACCOUNT), Mockito.<InternalTenantContext>any())) .thenReturn(tags); return account; }
public static Account createMockAccount(final AccountData accountData, final AccountUserApi accountUserApi, final AccountInternalApi accountInternalApi, final ImmutableAccountInternalApi immutableAccountInternalApi, final NonEntityDao nonEntityDao, final Clock clock, final InternalCallContextFactory internalCallContextFactory, final MutableCallContext callContext, final MutableInternalCallContext internalCallContext) throws AccountApiException { final Account account = accountUserApi.createAccount(accountData, callContext); Mockito.when(accountInternalApi.getAccountById(Mockito.<UUID>eq(account.getId()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(accountInternalApi.getAccountByRecordId(Mockito.<Long>eq(internalCallContext.getAccountRecordId()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(accountInternalApi.getAccountByKey(Mockito.<String>eq(account.getExternalKey()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(immutableAccountInternalApi.getImmutableAccountDataByRecordId(Mockito.<Long>eq(internalCallContext.getAccountRecordId()), Mockito.<InternalTenantContext>any())).thenReturn(account); ((MockNonEntityDao) nonEntityDao).addTenantRecordIdMapping(account.getId(), internalCallContext); ((MockNonEntityDao) nonEntityDao).addAccountRecordIdMapping(account.getId(), internalCallContext); refreshCallContext(account.getId(), clock, internalCallContextFactory, callContext, internalCallContext); return account; } }
final Account account = accountApi.getAccountById(accountId, callContext); if (account.getParentAccountId() != null && account.isPaymentDelegatedToParent()) { final InternalTenantContext parentAccountInternalTenantContext = internalCallContextFactory.createInternalTenantContext(account.getParentAccountId(), callContext);
public OverdueWrapper createOverdueWrapperFor(final UUID id, final InternalTenantContext context) throws OverdueException { try { final Account account = accountApi.getAccountById(id, context); return new OverdueWrapper(account, api, getOverdueStateSet(context), locker, clock, billingStateCalculator, overdueStateApplicator, internalCallContextFactory); } catch (final AccountApiException e) { throw new OverdueException(e); } }
@Override public void run(final InvoiceCreationInternalEvent event) { try { final InternalCallContext context = internalCallContextFactory.createInternalCallContext(event.getSearchKey2(), event.getSearchKey1(), "CreateParentInvoice", CallOrigin.INTERNAL, UserType.SYSTEM, event.getUserToken()); final Account account = accountApi.getAccountById(event.getAccountId(), context); // catch children invoices and populate the parent summary invoice if (isChildrenAccountAndPaymentDelegated(account)) { dispatcher.processParentInvoiceForInvoiceGeneration(account, event.getInvoiceId(), context); } } catch (final InvoiceApiException e) { log.warn("Unable to process event {}", event, e); } catch (final AccountApiException e) { log.warn("Unable to process event {}", event, e); } } });
@Override public void run(final DefaultInvoiceAdjustmentEvent event) { try { final InternalCallContext context = internalCallContextFactory.createInternalCallContext(event.getSearchKey2(), event.getSearchKey1(), "AdjustParentInvoice", CallOrigin.INTERNAL, UserType.SYSTEM, event.getUserToken()); final Account account = accountApi.getAccountById(event.getAccountId(), context); // catch children invoices and populate the parent summary invoice if (isChildrenAccountAndPaymentDelegated(account)) { dispatcher.processParentInvoiceForAdjustments(account, event.getInvoiceId(), context); } } catch (final InvoiceApiException e) { log.warn("Unable to process event {}", event, e); } catch (final AccountApiException e) { log.warn("Unable to process event {}", event, e); } } });
private Account addTestExternalPaymentMethod(final Account account, final PaymentMethodPlugin paymentMethodInfo) throws Exception { final UUID paymentMethodId = paymentApi.addPaymentMethod(account, paymentMethodInfo.getExternalPaymentMethodId(), ExternalPaymentProviderPlugin.PLUGIN_NAME, true, paymentMethodInfo, ImmutableList.<PluginProperty>of(), callContext); return accountApi.getAccountById(account.getId(), internalCallContext); }
@Override public void transferChildCreditToParent(final UUID childAccountId, final CallContext context) throws InvoiceApiException { final Account childAccount; final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(childAccountId, ObjectType.ACCOUNT, context); try { childAccount = accountUserApi.getAccountById(childAccountId, internalCallContext); } catch (AccountApiException e) { throw new InvoiceApiException(e); } if (childAccount.getParentAccountId() == null) { throw new InvoiceApiException(ErrorCode.ACCOUNT_DOES_NOT_HAVE_PARENT_ACCOUNT, childAccountId); } final BigDecimal accountCBA = getAccountCBA(childAccountId, context); if (accountCBA.compareTo(BigDecimal.ZERO) <= 0) { throw new InvoiceApiException(ErrorCode.CHILD_ACCOUNT_MISSING_CREDIT, childAccountId); } dao.transferChildCreditToParent(childAccount, internalCallContext); }
@Test(groups = "slow") public void testSetDefaultPaymentMethodSameAccount() throws Exception { final Account account = testHelper.createTestAccount("foo@bar.com", true); // Add new payment method final UUID newPaymentMethod = paymentMethodProcessor.createOrGetExternalPaymentMethod("pmExternalKey", account, PLUGIN_PROPERTIES, callContext, internalCallContext); paymentMethodProcessor.setDefaultPaymentMethod(account, newPaymentMethod, PLUGIN_PROPERTIES, callContext, internalCallContext); final Account accountById = accountApi.getAccountById(account.getId(), internalCallContext); Assert.assertEquals(accountById.getPaymentMethodId(), newPaymentMethod); }
@BeforeClass(groups = "fast") public void beforeClass() throws Exception { if (hasFailed()) { return; } super.beforeClass(); account = testHelper.createTestAccount("lolo@gmail.com", false); Mockito.when(accountInternalApi.getAccountById(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(account); //Mockito.when(nonEntityDao.retrieveIdFromObject(Mockito.<Long>any(), Mockito.<ObjectType>any())).thenReturn(uuid); retryPluginRegistry.registerService(new OSGIServiceDescriptor() { @Override public String getPluginSymbolicName() { return null; } @Override public String getPluginName() { return MockPaymentControlProviderPlugin.PLUGIN_NAME; } @Override public String getRegistrationName() { return MockPaymentControlProviderPlugin.PLUGIN_NAME; } }, mockRetryProviderPlugin); EMPTY_PROPERTIES = PluginPropertySerializer.serialize(ImmutableList.<PluginProperty>of()); }
public static Account createMockAccount(final AccountData accountData, final AccountUserApi accountUserApi, final AccountInternalApi accountInternalApi, final ImmutableAccountInternalApi immutableAccountInternalApi, final NonEntityDao nonEntityDao, final Clock clock, final InternalCallContextFactory internalCallContextFactory, final MutableCallContext callContext, final MutableInternalCallContext internalCallContext) throws AccountApiException { final Account account = accountUserApi.createAccount(accountData, callContext); Mockito.when(accountInternalApi.getAccountById(Mockito.<UUID>eq(account.getId()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(accountInternalApi.getAccountByRecordId(Mockito.<Long>eq(internalCallContext.getAccountRecordId()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(accountInternalApi.getAccountByKey(Mockito.<String>eq(account.getExternalKey()), Mockito.<InternalTenantContext>any())).thenReturn(account); Mockito.when(immutableAccountInternalApi.getImmutableAccountDataByRecordId(Mockito.<Long>eq(internalCallContext.getAccountRecordId()), Mockito.<InternalTenantContext>any())).thenReturn(account); ((MockNonEntityDao) nonEntityDao).addTenantRecordIdMapping(account.getId(), internalCallContext); ((MockNonEntityDao) nonEntityDao).addAccountRecordIdMapping(account.getId(), internalCallContext); refreshCallContext(account.getId(), clock, internalCallContextFactory, callContext, internalCallContext); return account; } }
@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; } } final HtmlInvoice htmlInvoice = generator.generateInvoice(account, invoice, manualPay, internalContext); return htmlInvoice.getBody(); }
final Account account = accountApi.getAccountById(accountId, callContext); if (account.getParentAccountId() != null && account.isPaymentDelegatedToParent()) { final InternalTenantContext parentAccountInternalTenantContext = internalCallContextFactory.createInternalTenantContext(account.getParentAccountId(), callContext);