Search in sources :

Example 6 with BillingAlignment

use of org.killbill.billing.catalog.api.BillingAlignment in project killbill by killbill.

the class DefaultSubscriptionBaseApiService method cancelWithPolicyNoValidationAndCatalog.

@Override
public boolean cancelWithPolicyNoValidationAndCatalog(final Iterable<DefaultSubscriptionBase> subscriptions, final BillingActionPolicy policy, final SubscriptionCatalog catalog, final InternalCallContext context) throws SubscriptionBaseApiException {
    final Map<DefaultSubscriptionBase, DateTime> subscriptionsWithEffectiveDate = new HashMap<DefaultSubscriptionBase, DateTime>();
    try {
        for (final DefaultSubscriptionBase subscription : subscriptions) {
            final BillingAlignment billingAlignment = (subscription.getState() == EntitlementState.PENDING ? null : catalog.billingAlignment(new PlanPhaseSpecifier(subscription.getLastActivePlan().getName(), subscription.getLastActivePhase().getPhaseType()), clock.getUTCNow(), subscription.getLastTransitionForCurrentPlan().getEffectiveTransitionTime()));
            final Integer accountBillCycleDayLocal = accountInternalApi.getBCD(context);
            final DateTime effectiveDate = subscription.getEffectiveDateForPolicy(policy, billingAlignment, accountBillCycleDayLocal, context);
            subscriptionsWithEffectiveDate.put(subscription, effectiveDate);
        }
        return doCancelPlan(subscriptionsWithEffectiveDate, catalog, context);
    } catch (final CatalogApiException e) {
        throw new SubscriptionBaseApiException(e);
    } catch (final AccountApiException e) {
        throw new SubscriptionBaseApiException(e);
    }
}
Also used : PlanPhaseSpecifier(org.killbill.billing.catalog.api.PlanPhaseSpecifier) HashMap(java.util.HashMap) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) AccountApiException(org.killbill.billing.account.api.AccountApiException) BillingAlignment(org.killbill.billing.catalog.api.BillingAlignment) DateTime(org.joda.time.DateTime)

Aggregations

BillingAlignment (org.killbill.billing.catalog.api.BillingAlignment)6 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)4 HashMap (java.util.HashMap)3 PlanPhaseSpecifier (org.killbill.billing.catalog.api.PlanPhaseSpecifier)3 DateTime (org.joda.time.DateTime)2 PlanPhasePriceOverride (org.killbill.billing.catalog.api.PlanPhasePriceOverride)2 SubscriptionBaseApiException (org.killbill.billing.subscription.api.user.SubscriptionBaseApiException)2 UUID (java.util.UUID)1 AccountApiException (org.killbill.billing.account.api.AccountApiException)1 Catalog (org.killbill.billing.catalog.api.Catalog)1 EntitlementApiException (org.killbill.billing.entitlement.api.EntitlementApiException)1 BillingEvent (org.killbill.billing.junction.BillingEvent)1 SubscriptionBase (org.killbill.billing.subscription.api.SubscriptionBase)1 SubscriptionBillingEvent (org.killbill.billing.subscription.api.user.SubscriptionBillingEvent)1 SubscriptionCatalog (org.killbill.billing.subscription.catalog.SubscriptionCatalog)1