@Override public void handleReadyNotification(final NotificationEvent inputKey, final DateTime eventDateTime, final UUID fromNotificationQueueUserToken, final Long accountRecordId, final Long tenantRecordId) { final InternalCallContext internalCallContext = internalCallContextFactory.createInternalCallContext(tenantRecordId, accountRecordId, "EntitlementQueue", CallOrigin.INTERNAL, UserType.SYSTEM, fromNotificationQueueUserToken); if (inputKey instanceof EntitlementNotificationKey) { final UUID tenantId = nonEntityDao.retrieveIdFromObject(tenantRecordId, ObjectType.TENANT); processEntitlementNotification((EntitlementNotificationKey) inputKey, tenantId, internalCallContext); } else if (inputKey instanceof BlockingTransitionNotificationKey) { processBlockingNotification((BlockingTransitionNotificationKey) inputKey, internalCallContext); } else if (inputKey != null) { log.error("Entitlement service received an unexpected event type {}" + inputKey.getClass()); } else { log.error("Entitlement service received an unexpected null event"); } } };
protected TenantContext buildTenantContext(final InternalTenantContext context) { return context.toTenantContext(nonEntityDao.retrieveIdFromObject(context.getTenantRecordId(), ObjectType.TENANT)); }
private TenantContext buildTenantContext(final InternalTenantContext context) { return context.toTenantContext(nonEntityDao.retrieveIdFromObject(context.getTenantRecordId(), ObjectType.TENANT)); }
private void computeEntitlementsToCancel(final Account account, final List<Entitlement> result, final InternalTenantContext context) throws EntitlementApiException { final UUID tenantId = nonEntityDao.retrieveIdFromObject(context.getTenantRecordId(), ObjectType.TENANT); final List<Entitlement> allEntitlementsForAccountId = entitlementApi.getAllEntitlementsForAccountId(account.getId(), context.toTenantContext(tenantId)); // Entitlement is smart enough and will cancel the associated add-ons. See also discussion in https://github.com/killbill/killbill/issues/94 final Collection<Entitlement> allEntitlementsButAddonsForAccountId = Collections2.<Entitlement>filter(allEntitlementsForAccountId, new Predicate<Entitlement>() { @Override public boolean apply(final Entitlement entitlement) { return !ProductCategory.ADD_ON.equals(entitlement.getLastActiveProductCategory()); } }); result.addAll(allEntitlementsButAddonsForAccountId); }
@Override public SubscriptionBundle getSubscriptionBundle(final UUID bundleId, final TenantContext context) throws SubscriptionApiException { final Long accountRecordId = nonEntityDao.retrieveAccountRecordIdFromObject(bundleId, ObjectType.BUNDLE, cacheControllerDispatcher.getCacheController(CacheType.ACCOUNT_RECORD_ID)); final UUID accountId = nonEntityDao.retrieveIdFromObject(accountRecordId, ObjectType.ACCOUNT); final Optional<SubscriptionBundle> bundleOptional = Iterables.<SubscriptionBundle>tryFind(getSubscriptionBundlesForAccount(accountId, context), new Predicate<SubscriptionBundle>() { @Override public boolean apply(final SubscriptionBundle bundle) { return bundle.getId().equals(bundleId); } }); if (!bundleOptional.isPresent()) { throw new SubscriptionApiException(ErrorCode.SUB_GET_INVALID_BUNDLE_ID, bundleId); } else { return bundleOptional.get(); } }
@Override public Subscription getSubscriptionForEntitlementId(final UUID entitlementId, final TenantContext context) throws SubscriptionApiException { final Long accountRecordId = nonEntityDao.retrieveAccountRecordIdFromObject(entitlementId, ObjectType.SUBSCRIPTION, cacheControllerDispatcher.getCacheController(CacheType.ACCOUNT_RECORD_ID)); final UUID accountId = nonEntityDao.retrieveIdFromObject(accountRecordId, ObjectType.ACCOUNT); // Retrieve entitlements final AccountEntitlements accountEntitlements; try { accountEntitlements = entitlementInternalApi.getAllEntitlementsForAccountId(accountId, context); } catch (EntitlementApiException e) { throw new SubscriptionApiException(e); } // Build subscriptions final Iterable<Subscription> accountSubscriptions = Iterables.<Subscription>concat(buildSubscriptionsFromEntitlements(accountEntitlements).values()); return Iterables.<Subscription>find(accountSubscriptions, new Predicate<Subscription>() { @Override public boolean apply(final Subscription subscription) { return subscription.getId().equals(entitlementId); } }); }
public void setDefaultPaymentMethod(final Account account, final UUID paymentMethodId, final InternalCallContext context) throws PaymentApiException { final UUID tenantId = nonEntityDao.retrieveIdFromObject(context.getTenantRecordId(), ObjectType.TENANT); new WithAccountLock<Void>().processAccountWithLock(locker, account.getExternalKey(), new WithAccountLockCallback<Void>() { @Override public Void doOperation() throws PaymentApiException { final PaymentMethodModelDao paymentMethodModel = paymentDao.getPaymentMethod(paymentMethodId, context); if (paymentMethodModel == null) { throw new PaymentApiException(ErrorCode.PAYMENT_NO_SUCH_PAYMENT_METHOD, paymentMethodId); } try { final PaymentPluginApi pluginApi = getPluginApi(paymentMethodId, context); pluginApi.setDefaultPaymentMethod(account.getId(), paymentMethodId, context.toCallContext(tenantId)); accountInternalApi.updatePaymentMethod(account.getId(), paymentMethodId, context); return null; } catch (PaymentPluginApiException e) { throw new PaymentApiException(ErrorCode.PAYMENT_UPD_PAYMENT_METHOD, account.getId(), e.getErrorMessage()); } catch (AccountApiException e) { throw new PaymentApiException(e); } } }); }
public void deletedPaymentMethod(final Account account, final UUID paymentMethodId, final boolean deleteDefaultPaymentMethodWithAutoPayOff, final InternalCallContext context) throws PaymentApiException { final UUID tenantId = nonEntityDao.retrieveIdFromObject(context.getTenantRecordId(), ObjectType.TENANT);
public UUID addPaymentMethod(final String paymentPluginServiceName, final Account account, final boolean setDefault, final PaymentMethodPlugin paymentMethodProps, final InternalCallContext context) throws PaymentApiException { final UUID tenantId = nonEntityDao.retrieveIdFromObject(context.getTenantRecordId(), ObjectType.TENANT); return new WithAccountLock<UUID>().processAccountWithLock(locker, account.getExternalKey(), new WithAccountLockCallback<UUID>() { @Override public UUID doOperation() throws PaymentApiException { PaymentMethod pm = null; PaymentPluginApi pluginApi = null; try { pluginApi = getPaymentPluginApi(paymentPluginServiceName); pm = new DefaultPaymentMethod(account.getId(), paymentPluginServiceName, paymentMethodProps); pluginApi.addPaymentMethod(account.getId(), pm.getId(), paymentMethodProps, setDefault, context.toCallContext(tenantId)); final PaymentMethodModelDao pmModel = new PaymentMethodModelDao(pm.getId(), pm.getCreatedDate(), pm.getUpdatedDate(), pm.getAccountId(), pm.getPluginName(), pm.isActive()); paymentDao.insertPaymentMethod(pmModel, context); if (setDefault) { accountInternalApi.updatePaymentMethod(account.getId(), pm.getId(), context); } } catch (PaymentPluginApiException e) { log.warn("Error adding payment method " + pm.getId() + " for plugin " + paymentPluginServiceName, e); // STEPH all errors should also take a pluginName throw new PaymentApiException(ErrorCode.PAYMENT_ADD_PAYMENT_METHOD, account.getId(), e.getErrorMessage()); } catch (AccountApiException e) { throw new PaymentApiException(e); } return pm.getId(); } }); }
final boolean isAdjusted, final Map<UUID, BigDecimal> invoiceItemIdsWithAmounts, final InternalCallContext context) throws PaymentApiException { final UUID tenantId = nonEntityDao.retrieveIdFromObject(context.getTenantRecordId(), ObjectType.TENANT);
computeEntitlementsToCancel(account, toBeCancelled, context); final UUID tenantId = nonEntityDao.retrieveIdFromObject(context.getTenantRecordId(), ObjectType.TENANT); for (final Entitlement cur : toBeCancelled) { try {
final UUID tenantId = nonEntityDao.retrieveIdFromObject(context.getTenantRecordId(), ObjectType.TENANT);
private Payment processPaymentWithAccountLocked(final PaymentPluginApi plugin, final Account account, final Invoice invoice, final PaymentModelDao paymentInput, final PaymentAttemptModelDao attemptInput, final boolean isInstantPayment, final InternalCallContext context) throws PaymentApiException { final UUID tenantId = nonEntityDao.retrieveIdFromObject(context.getTenantRecordId(), ObjectType.TENANT);
final UUID tenantId = nonEntityDao.retrieveIdFromObject(context.getTenantRecordId(), ObjectType.TENANT);