public List<PaymentMethod> getPaymentMethods(final Account account, final boolean withPluginInfo, final InternalTenantContext context) throws PaymentApiException { final List<PaymentMethodModelDao> paymentMethodModels = paymentDao.getPaymentMethods(account.getId(), context); if (paymentMethodModels.size() == 0) { return Collections.emptyList(); } return getPaymentMethodInternal(paymentMethodModels, withPluginInfo, context); }
@Override public Account getAccountById(final UUID uid, final TenantContext context) { for (final Account account : accounts) { if (uid.equals(account.getId())) { return account; } } return null; }
@Override public Refund createRefund(final Account account, final UUID paymentId, final BigDecimal refundAmount, final CallContext context) throws PaymentApiException { if (refundAmount == null || refundAmount.compareTo(BigDecimal.ZERO) <= 0) { throw new PaymentApiException(ErrorCode.PAYMENT_REFUND_AMOUNT_NEGATIVE_OR_NULL); } return refundProcessor.createRefund(account, paymentId, refundAmount, false, ImmutableMap.<UUID, BigDecimal>of(), internalCallContextFactory.createInternalCallContext(account.getId(), context)); }
@Override public Refund createRefundWithItemsAdjustments(final Account account, final UUID paymentId, final Map<UUID, BigDecimal> invoiceItemIdsWithAmounts, final CallContext context) throws PaymentApiException { return refundProcessor.createRefund(account, paymentId, null, true, invoiceItemIdsWithAmounts, internalCallContextFactory.createInternalCallContext(account.getId(), context)); }
@Override public List<PaymentMethod> refreshPaymentMethods(final Account account, final CallContext context) throws PaymentApiException { final InternalCallContext callContext = internalCallContextFactory.createInternalCallContext(account.getId(), context); final List<PaymentMethod> paymentMethods = new LinkedList<PaymentMethod>(); for (final String pluginName : methodProcessor.getAvailablePlugins()) { paymentMethods.addAll(methodProcessor.refreshPaymentMethods(pluginName, account, callContext)); } return paymentMethods; } }
@Override public void notifyPendingRefundOfStateChanged(final Account account, final UUID refundId, final boolean isSuccess, final CallContext context) throws PaymentApiException { refundProcessor.notifyPendingRefundOfStateChanged(account, refundId, isSuccess, internalCallContextFactory.createInternalCallContext(account.getId(), context)); }
@Override public AccountJson apply(final Account account) { final AccountAuditLogs accountAuditLogs = auditUserApi.getAccountAuditLogs(account.getId(), auditMode.getLevel(), tenantContext); return getAccount(account, accountWithBalance, accountWithBalanceAndCBA, accountAuditLogs, tenantContext); } },
@SuppressWarnings("unchecked") @Override public OverdueState getOverdueStateFor(final Account overdueable, final TenantContext context) throws OverdueException { try { final String stateName = accessApi.getBlockingStateForService(overdueable.getId(), BlockingStateType.ACCOUNT, OverdueService.OVERDUE_SERVICE_NAME, internalCallContextFactory.createInternalTenantContext(context)).getStateName(); final OverdueStateSet states = overdueConfig.getStateSet(); return states.findState(stateName); } catch (OverdueApiException e) { throw new OverdueException(e, ErrorCode.OVERDUE_CAT_ERROR_ENCOUNTERED, overdueable.getId(), overdueable.getClass().getSimpleName()); } }
@Override public Collection<NotificationEventWithMetadata<OverdueCheckNotificationKey>> inTransaction(final EntitySqlDaoWrapperFactory<EntitySqlDao> entitySqlDaoWrapperFactory) throws Exception { return ((OverdueCheckPoster)checkPoster).getFutureNotificationsForAccountInTransaction(entitySqlDaoWrapperFactory, overdueQueue, account.getId(), OverdueCheckNotificationKey.class, internalCallContext); } });
@Override public UUID getIdFromKey(final String externalKey, final TenantContext context) { for (final Account account : accounts) { if (externalKey.equals(account.getExternalKey())) { return account.getId(); } } return null; }
public BusinessAccountModelDao(final Account account) { super(account.getId(), account.getCreatedDate(), account.getUpdatedDate()); this.accountId = account.getId(); this.name = account.getName(); this.key = account.getExternalKey(); if (account.getCurrency() != null) { this.currency = account.getCurrency().toString(); } }
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; }
private void insertOverdueCheckAndVerifyQueueContent(final Account account, final int nbDaysInFuture, final int expectedNbDaysInFuture) throws IOException { final DateTime futureNotificationTime = testReferenceTime.plusDays(nbDaysInFuture); final OverdueCheckNotificationKey notificationKey = new OverdueCheckNotificationKey(account.getId()); checkPoster.insertOverdueNotification(account.getId(), futureNotificationTime, OverdueCheckNotifier.OVERDUE_CHECK_NOTIFIER_QUEUE, notificationKey, internalCallContext); final Collection<NotificationEventWithMetadata<OverdueCheckNotificationKey>> notificationsForKey = getNotificationsForOverdueable(account); Assert.assertEquals(notificationsForKey.size(), 1); final NotificationEventWithMetadata nm = notificationsForKey.iterator().next(); Assert.assertEquals(nm.getEvent(), notificationKey); Assert.assertEquals(nm.getEffectiveDate(), testReferenceTime.plusDays(expectedNbDaysInFuture)); }
@BeforeMethod(groups = "slow") public void setUp() throws Exception { account = invoiceUtil.createAccount(callContext); context = internalCallContextFactory.createInternalCallContext(account.getId(), callContext); }
@Test(groups = "fast") public void testBillingEventsAutoInvoicingOffAccount() throws CatalogApiException, AccountApiException, TagApiException { final Plan nextPlan = catalog.findPlan("PickupTrialEvergreen10USD", clock.getUTCNow()); final PlanPhase nextPhase = nextPlan.getAllPhases()[1]; createSubscriptionCreationEvent(nextPlan, nextPhase); final Account account = createAccount(32); tagInternalApi.addTag(account.getId(), ObjectType.ACCOUNT, ControlTagType.AUTO_INVOICING_OFF.getId(), internalCallContext); final BillingEventSet events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), internalCallContext); assertEquals(events.isAccountAutoInvoiceOff(), true); assertEquals(events.size(), 0); }
@Test(groups = "fast") public void testBillingEventsAutoInvoicingOffBundle() throws CatalogApiException, AccountApiException, TagApiException { final Plan nextPlan = catalog.findPlan("PickupTrialEvergreen10USD", clock.getUTCNow()); final PlanPhase nextPhase = nextPlan.getAllPhases()[1]; createSubscriptionCreationEvent(nextPlan, nextPhase); final Account account = createAccount(32); tagInternalApi.addTag(bunId, ObjectType.BUNDLE, ControlTagType.AUTO_INVOICING_OFF.getId(), internalCallContext); final BillingEventSet events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), internalCallContext); assertEquals(events.getSubscriptionIdsWithAutoInvoiceOff().size(), 1); assertEquals(events.getSubscriptionIdsWithAutoInvoiceOff().get(0), subId); assertEquals(events.size(), 0); }
private Payment processRetryPaymentWithAccountLocked(final PaymentPluginApi plugin, final Account account, final Invoice invoice, final PaymentModelDao payment, final BigDecimal requestedAmount, final InternalCallContext context) throws PaymentApiException { final PaymentAttemptModelDao attempt = new PaymentAttemptModelDao(account.getId(), invoice.getId(), payment.getId(), account.getPaymentMethodId(), clock.getUTCNow(), requestedAmount, invoice.getCurrency()); paymentDao.updatePaymentWithNewAttempt(payment.getId(), attempt, context); return processPaymentWithAccountLocked(plugin, account, invoice, payment, attempt, false, context); }
@Override @BeforeMethod(groups = "slow") public void beforeMethod() throws Exception { super.beforeMethod(); date_migrated = clock.getUTCToday().minusYears(1); date_regular = clock.getUTCNow(); final Account account = invoiceUtil.createAccount(callContext); accountId = account.getId(); migrationInvoiceId = createAndCheckMigrationInvoice(accountId); regularInvoiceId = invoiceUtil.generateRegularInvoice(account, date_regular, callContext); }
@Test(groups = "fast") public void testBillingEventsNoBillingPeriod() throws CatalogApiException, AccountApiException { final Plan nextPlan = catalog.findPlan("PickupTrialEvergreen10USD", clock.getUTCNow()); // The trial has no billing period final PlanPhase nextPhase = nextPlan.getAllPhases()[0]; final DateTime now = createSubscriptionCreationEvent(nextPlan, nextPhase); final Account account = createAccount(10); final SortedSet<BillingEvent> events = billingInternalApi.getBillingEventsForAccountAndUpdateAccountBCD(account.getId(), internalCallContext); checkFirstEvent(events, nextPlan, account.getBillCycleDayLocal(), subId, now, nextPhase, SubscriptionBaseTransitionType.CREATE.toString()); }
@Test(groups = "slow") public void testSimple() throws Exception { final UUID accountId = account.getId(); final Invoice invoice = new DefaultInvoice(accountId, clock.getUTCToday(), clock.getUTCToday(), Currency.USD); invoiceUtil.createInvoice(invoice, true, context); final InvoiceModelDao retrievedInvoice = invoiceDao.getById(invoice.getId(), context); invoiceUtil.checkInvoicesEqual(retrievedInvoice, invoice); invoiceUtil.checkInvoicesEqual(invoiceDao.getByNumber(retrievedInvoice.getInvoiceNumber(), context), invoice); }