Search in sources :

Example 61 with SubscriptionBaseApiException

use of org.killbill.billing.subscription.api.user.SubscriptionBaseApiException in project killbill by killbill.

the class EventsStreamBuilder method buildForEntitlement.

private EventsStream buildForEntitlement(final ImmutableAccountData account, final SubscriptionBaseBundle bundle, @Nullable final SubscriptionBase baseSubscription, final SubscriptionBase subscription, final Collection<SubscriptionBase> allSubscriptionsForBundle, final Collection<BlockingState> blockingStates, final int accountBCD, final Map<UUID, Integer> bcdCache, final VersionedCatalog catalog, final InternalTenantContext internalTenantContext) throws EntitlementApiException {
    try {
        Integer defaultAlignmentDay = null;
        final BillingAlignment alignment = subscription.getBillingAlignment(createPlanPhaseSpecifier(subscription), clock.getUTCNow(), catalog);
        if (alignment != BillingAlignment.ACCOUNT || accountBCD != 0) {
            defaultAlignmentDay = BillCycleDayCalculator.calculateBcdForAlignment(bcdCache, subscription, baseSubscription, alignment, internalTenantContext, accountBCD);
        }
        return new DefaultEventsStream(account, bundle, blockingStates, checker, baseSubscription, subscription, allSubscriptionsForBundle, defaultAlignmentDay, internalTenantContext, clock.getUTCNow());
    } catch (final SubscriptionBaseApiException e) {
        throw new EntitlementApiException(e);
    }
}
Also used : BillingAlignment(org.killbill.billing.catalog.api.BillingAlignment) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) SubscriptionBaseApiException(org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)

Example 62 with SubscriptionBaseApiException

use of org.killbill.billing.subscription.api.user.SubscriptionBaseApiException in project killbill by killbill.

the class EventsStreamBuilder method buildForAccount.

public AccountEventsStreams buildForAccount(final InternalTenantContext internalTenantContext) throws EntitlementApiException {
    // Retrieve the subscriptions (map bundle id -> subscriptions)
    final Map<UUID, List<SubscriptionBase>> subscriptions;
    try {
        final VersionedCatalog catalog = getCatalog(internalTenantContext);
        subscriptions = subscriptionInternalApi.getSubscriptionsForAccount(catalog, null, internalTenantContext);
        return buildForAccount(subscriptions, catalog, internalTenantContext);
    } catch (final SubscriptionBaseApiException e) {
        throw new EntitlementApiException(e);
    }
}
Also used : VersionedCatalog(org.killbill.billing.catalog.api.VersionedCatalog) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) UUID(java.util.UUID) SubscriptionBaseApiException(org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)

Example 63 with SubscriptionBaseApiException

use of org.killbill.billing.subscription.api.user.SubscriptionBaseApiException in project killbill by killbill.

the class InvoiceDispatcher method processSubscriptionStartRequestedDate.

public void processSubscriptionStartRequestedDate(final RequestedSubscriptionInternalEvent transition, final InternalCallContext context) {
    final long dryRunNotificationTime = invoiceConfig.getDryRunNotificationSchedule(context).getMillis();
    final boolean isInvoiceNotificationEnabled = dryRunNotificationTime > 0;
    if (!isInvoiceNotificationEnabled) {
        return;
    }
    final UUID accountId;
    try {
        accountId = subscriptionApi.getAccountIdFromSubscriptionId(transition.getSubscriptionId(), context);
    } catch (final SubscriptionBaseApiException e) {
        log.warn("Failed handling SubscriptionBase change.", new InvoiceApiException(ErrorCode.INVOICE_NO_ACCOUNT_ID_FOR_SUBSCRIPTION_ID, transition.getSubscriptionId().toString()));
        return;
    }
    GlobalLock lock = null;
    try {
        lock = locker.lockWithNumberOfTries(LockerType.ACCNT_INV_PAY.toString(), accountId.toString(), invoiceConfig.getMaxGlobalLockRetries());
        processSubscriptionStartRequestedDateWithLock(accountId, transition, context);
    } catch (final LockFailedException e) {
        log.warn("Failed to process RequestedSubscriptionInternalEvent for accountId='{}'", accountId.toString(), e);
    } finally {
        if (lock != null) {
            lock.release();
        }
    }
}
Also used : GlobalLock(org.killbill.commons.locker.GlobalLock) InvoiceApiException(org.killbill.billing.invoice.api.InvoiceApiException) LockFailedException(org.killbill.commons.locker.LockFailedException) UUID(java.util.UUID) SubscriptionBaseApiException(org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)

Example 64 with SubscriptionBaseApiException

use of org.killbill.billing.subscription.api.user.SubscriptionBaseApiException in project killbill by killbill.

the class DefaultSubscriptionInternalApi method createBaseSubscriptionsWithAddOns.

@Override
public List<SubscriptionBaseWithAddOns> createBaseSubscriptionsWithAddOns(final VersionedCatalog publicCatalog, final Iterable<SubscriptionBaseWithAddOnsSpecifier> subscriptionWithAddOnsSpecifiers, final boolean renameCancelledBundleIfExist, final InternalCallContext context) throws SubscriptionBaseApiException {
    try {
        final SubscriptionCatalog catalog = DefaultSubscriptionCatalogApi.wrapCatalog(publicCatalog, clock);
        final CallContext callContext = internalCallContextFactory.createCallContext(context);
        return super.createBaseSubscriptionsWithAddOns(subscriptionWithAddOnsSpecifiers, renameCancelledBundleIfExist, catalog, addonUtils, accountIdCacheController, bundleIdCacheController, callContext, context);
    } catch (final CatalogApiException e) {
        throw new SubscriptionBaseApiException(e);
    }
}
Also used : CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) SubscriptionCatalog(org.killbill.billing.subscription.catalog.SubscriptionCatalog) PlanPhasePriceOverridesWithCallContext(org.killbill.billing.catalog.api.PlanPhasePriceOverridesWithCallContext) CallContext(org.killbill.billing.util.callcontext.CallContext) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) SubscriptionBaseApiException(org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)

Example 65 with SubscriptionBaseApiException

use of org.killbill.billing.subscription.api.user.SubscriptionBaseApiException in project killbill by killbill.

the class DefaultSubscriptionInternalApi method cancelBaseSubscriptions.

@Override
public void cancelBaseSubscriptions(final Iterable<SubscriptionBase> subscriptions, final BillingActionPolicy policy, final InternalCallContext context) throws SubscriptionBaseApiException {
    try {
        final SubscriptionCatalog catalog = subscriptionCatalogApi.getFullCatalog(context);
        apiService.cancelWithPolicyNoValidationAndCatalog(Iterables.<SubscriptionBase, DefaultSubscriptionBase>transform(subscriptions, new Function<SubscriptionBase, DefaultSubscriptionBase>() {

            @Override
            public DefaultSubscriptionBase apply(final SubscriptionBase subscriptionBase) {
                try {
                    return getDefaultSubscriptionBase(subscriptionBase, catalog, context);
                } catch (final CatalogApiException e) {
                    throw new RuntimeException(e);
                }
            }
        }), policy, catalog, context);
    } catch (CatalogApiException e) {
        throw new SubscriptionBaseApiException(e);
    }
}
Also used : SubscriptionBase(org.killbill.billing.subscription.api.SubscriptionBase) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) Function(com.google.common.base.Function) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) SubscriptionCatalog(org.killbill.billing.subscription.catalog.SubscriptionCatalog) SubscriptionBaseApiException(org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)

Aggregations

SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)72 ArrayList (java.util.ArrayList)29 DateTime (org.joda.time.DateTime)29 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)28 UUID (java.util.UUID)27 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)24 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)24 WithEntitlementPlugin (org.killbill.billing.entitlement.api.EntitlementPluginExecution.WithEntitlementPlugin)19 EntitlementContext (org.killbill.billing.entitlement.plugin.api.EntitlementContext)19 DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)17 SubscriptionBaseBundle (org.killbill.billing.subscription.api.user.SubscriptionBaseBundle)16 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)14 DefaultBlockingState (org.killbill.billing.junction.DefaultBlockingState)14 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)11 Plan (org.killbill.billing.catalog.api.Plan)11 LinkedList (java.util.LinkedList)10 SubscriptionCatalog (org.killbill.billing.subscription.catalog.SubscriptionCatalog)10 AccountApiException (org.killbill.billing.account.api.AccountApiException)8 PlanPhasePriceOverridesWithCallContext (org.killbill.billing.catalog.api.PlanPhasePriceOverridesWithCallContext)8 EntitlementApiException (org.killbill.billing.entitlement.api.EntitlementApiException)8