public PaymentApiException(final AccountApiException e) { super(e, e.getCode(), e.getMessage()); }
@Subscribe public void handleBlockingStateTransition(final BlockingTransitionInternalEvent event) { // We are only interested in blockBilling or unblockBilling transitions. if (!event.isTransitionedToUnblockedBilling() && !event.isTransitionedToBlockedBilling()) { return; } try { final InternalCallContext context = internalCallContextFactory.createInternalCallContext(event.getSearchKey2(), event.getSearchKey1(), "SubscriptionBaseTransition", CallOrigin.INTERNAL, UserType.SYSTEM, event.getUserToken()); final UUID accountId = accountApi.getByRecordId(event.getSearchKey1(), context); dispatcher.processAccount(accountId, clock.getUTCNow(), false, context); } catch (InvoiceApiException e) { log.error(e.getMessage()); } catch (AccountApiException e) { log.error(e.getMessage()); } }
@Override public Response toResponse(final AccountApiException exception) { if (exception.getCode() == ErrorCode.ACCOUNT_ALREADY_EXISTS.getCode()) { return buildConflictingRequestResponse(exception, uriInfo); } else if (exception.getCode() == ErrorCode.ACCOUNT_CANNOT_CHANGE_EXTERNAL_KEY.getCode()) { return buildBadRequestResponse(exception, uriInfo); } else if (exception.getCode() == ErrorCode.ACCOUNT_CANNOT_MAP_NULL_KEY.getCode()) { return buildBadRequestResponse(exception, uriInfo); } else if (exception.getCode() == ErrorCode.ACCOUNT_CREATION_FAILED.getCode()) { return buildInternalErrorResponse(exception, uriInfo); } else if (exception.getCode() == ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_ID.getCode()) { return buildNotFoundResponse(exception, uriInfo); } else if (exception.getCode() == ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_KEY.getCode()) { return buildNotFoundResponse(exception, uriInfo); } else if (exception.getCode() == ErrorCode.ACCOUNT_INVALID_NAME.getCode()) { return buildBadRequestResponse(exception, uriInfo); } else if (exception.getCode() == ErrorCode.ACCOUNT_UPDATE_FAILED.getCode()) { return buildInternalErrorResponse(exception, uriInfo); } else if (exception.getCode() == ErrorCode.ACCOUNT_DOES_NOT_EXIST_FOR_RECORD_ID.getCode()) { return buildNotFoundResponse(exception, uriInfo); } else { return fallback(exception, uriInfo); } } }
@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; } }
@Override public void handleKillbillEvent(final ExtBusEvent killbillEvent) { logService.log(LogService.LOG_INFO, "Received external event " + killbillEvent.toString()); // Only looking at account creation if (killbillEvent.getEventType() != ExtBusEventType.ACCOUNT_CREATION) { return; } final TenantContext tenantContext = new TenantContext() { @Override public UUID getTenantId() { return null; } }; try { Account account = killbillAPI.getAccountUserApi().getAccountById(killbillEvent.getAccountId(), tenantContext); testDao.insertAccountExternalKey(account.getExternalKey()); } catch (AccountApiException e) { logService.log(LogService.LOG_ERROR, e.getMessage()); } } }
@Override public void handleKillbillEvent(final ExtBusEvent killbillEvent) { logService.log(LogService.LOG_INFO, "Received external event " + killbillEvent.toString()); // Only looking at account creation if (killbillEvent.getEventType() != ExtBusEventType.ACCOUNT_CREATION) { return; } final TenantContext tenantContext = new TenantContext() { @Override public UUID getTenantId() { return null; } }; try { Account account = killbillAPI.getAccountUserApi().getAccountById(killbillEvent.getAccountId(), tenantContext); testDao.insertAccountExternalKey(account.getExternalKey()); } catch (AccountApiException e) { logService.log(LogService.LOG_ERROR, e.getMessage()); } } }