Search in sources :

Example 1 with EntitlementNotificationKeyAction

use of org.killbill.billing.entitlement.engine.core.EntitlementNotificationKeyAction in project killbill by killbill.

the class DefaultEntitlementService method processEntitlementNotification.

private void processEntitlementNotification(final EntitlementNotificationKey key, final InternalCallContext internalCallContext, final CallContext callContext) {
    final Entitlement entitlement;
    try {
        entitlement = entitlementInternalApi.getEntitlementForId(key.getEntitlementId(), internalCallContext);
    } catch (final EntitlementApiException e) {
        log.error("Error retrieving entitlementId='{}'", key.getEntitlementId(), e);
        return;
    }
    if (!(entitlement instanceof DefaultEntitlement)) {
        log.error("Error retrieving entitlementId='{}', unexpected entitlement className='{}'", key.getEntitlementId(), entitlement.getClass().getName());
        return;
    }
    final EntitlementNotificationKeyAction entitlementNotificationKeyAction = key.getEntitlementNotificationKeyAction();
    try {
        if (EntitlementNotificationKeyAction.CHANGE.equals(entitlementNotificationKeyAction) || EntitlementNotificationKeyAction.CANCEL.equals(entitlementNotificationKeyAction)) {
            blockAddOnsIfRequired(key, (DefaultEntitlement) entitlement, callContext, internalCallContext);
        } else if (EntitlementNotificationKeyAction.PAUSE.equals(entitlementNotificationKeyAction)) {
            entitlementInternalApi.pause(key.getBundleId(), internalCallContext.toLocalDate(key.getEffectiveDate()), ImmutableList.<PluginProperty>of(), internalCallContext);
        } else if (EntitlementNotificationKeyAction.RESUME.equals(entitlementNotificationKeyAction)) {
            entitlementInternalApi.resume(key.getBundleId(), internalCallContext.toLocalDate(key.getEffectiveDate()), ImmutableList.<PluginProperty>of(), internalCallContext);
        }
    } catch (final EntitlementApiException e) {
        log.error("Error processing event for entitlementId='{}'", entitlement.getId(), e);
    }
}
Also used : EntitlementNotificationKeyAction(org.killbill.billing.entitlement.engine.core.EntitlementNotificationKeyAction) PluginProperty(org.killbill.billing.payment.api.PluginProperty) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) EntitlementApiException(org.killbill.billing.entitlement.api.EntitlementApiException) DefaultEntitlement(org.killbill.billing.entitlement.api.DefaultEntitlement) Entitlement(org.killbill.billing.entitlement.api.Entitlement)

Aggregations

DefaultEntitlement (org.killbill.billing.entitlement.api.DefaultEntitlement)1 Entitlement (org.killbill.billing.entitlement.api.Entitlement)1 EntitlementApiException (org.killbill.billing.entitlement.api.EntitlementApiException)1 EntitlementNotificationKeyAction (org.killbill.billing.entitlement.engine.core.EntitlementNotificationKeyAction)1 PluginProperty (org.killbill.billing.payment.api.PluginProperty)1