Search in sources :

Example 1 with DefaultEffectiveSubscriptionEvent

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

the class DefaultSubscriptionBaseService method processEventReady.

@Override
public void processEventReady(final SubscriptionBaseEvent event, final int seqId, final InternalCallContext context) {
    if (!event.isActive()) {
        return;
    }
    try {
        final DefaultSubscriptionBase subscription = (DefaultSubscriptionBase) dao.getSubscriptionFromId(event.getSubscriptionId(), context);
        if (subscription == null) {
            log.warn("Error retrieving subscriptionId='{}'", event.getSubscriptionId());
            return;
        }
        final SubscriptionBaseTransitionData transition = subscription.getTransitionFromEvent(event, seqId);
        if (transition == null) {
            log.warn("Skipping event ='{}', no matching transition was built", event.getType());
            return;
        }
        boolean eventSent = false;
        if (event.getType() == EventType.PHASE) {
            eventSent = onPhaseEvent(subscription, event, context);
        } else if (event.getType() == EventType.API_USER && subscription.getCategory() == ProductCategory.BASE) {
            final CallContext callContext = internalCallContextFactory.createCallContext(context);
            eventSent = onBasePlanEvent(subscription, event, callContext);
        } else if (event.getType() == EventType.BCD_UPDATE) {
            eventSent = false;
        }
        if (!eventSent) {
            // Methods above invoking the DAO will send this event directly from the transaction
            final BusEvent busEvent = new DefaultEffectiveSubscriptionEvent(transition, subscription.getAlignStartDate(), context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId());
            eventBus.post(busEvent);
        }
    } catch (final EventBusException e) {
        log.warn("Failed to post event {}", event, e);
    } catch (final CatalogApiException e) {
        log.warn("Failed to post event {}", event, e);
    }
}
Also used : SubscriptionBaseTransitionData(org.killbill.billing.subscription.api.user.SubscriptionBaseTransitionData) DefaultEffectiveSubscriptionEvent(org.killbill.billing.subscription.api.user.DefaultEffectiveSubscriptionEvent) CatalogApiException(org.killbill.billing.catalog.api.CatalogApiException) EventBusException(org.killbill.bus.api.PersistentBus.EventBusException) DefaultSubscriptionBase(org.killbill.billing.subscription.api.user.DefaultSubscriptionBase) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) CallContext(org.killbill.billing.util.callcontext.CallContext) BusEvent(org.killbill.bus.api.BusEvent)

Example 2 with DefaultEffectiveSubscriptionEvent

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

the class MockSubscriptionDaoMemory method notifyBusOfEffectiveImmediateChange.

private void notifyBusOfEffectiveImmediateChange(final DefaultSubscriptionBase subscription, final SubscriptionBaseEvent immediateEvent, final int seqId, final InternalCallContext context) {
    try {
        final SubscriptionBaseTransitionData transition = subscription.getTransitionFromEvent(immediateEvent, seqId);
        final BusEvent busEvent = new DefaultEffectiveSubscriptionEvent(transition, subscription.getAlignStartDate(), context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId());
        eventBus.post(busEvent);
    } catch (final EventBusException e) {
        log.warn("Failed to post effective event for subscription " + subscription.getId(), e);
    }
}
Also used : SubscriptionBaseTransitionData(org.killbill.billing.subscription.api.user.SubscriptionBaseTransitionData) DefaultEffectiveSubscriptionEvent(org.killbill.billing.subscription.api.user.DefaultEffectiveSubscriptionEvent) EventBusException(org.killbill.bus.api.PersistentBus.EventBusException) BusEvent(org.killbill.bus.api.BusEvent)

Example 3 with DefaultEffectiveSubscriptionEvent

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

the class DefaultSubscriptionDao method notifyBusOfEffectiveImmediateChange.

private void notifyBusOfEffectiveImmediateChange(final EntitySqlDaoWrapperFactory entitySqlDaoWrapperFactory, final DefaultSubscriptionBase subscription, final SubscriptionBaseEvent immediateEvent, final int seqId, final InternalCallContext context) {
    try {
        final SubscriptionBaseTransitionData transition = subscription.getTransitionFromEvent(immediateEvent, seqId);
        if (transition != null) {
            final BusEvent busEvent = new DefaultEffectiveSubscriptionEvent(transition, subscription.getAlignStartDate(), context.getUserToken(), context.getAccountRecordId(), context.getTenantRecordId());
            eventBus.postFromTransaction(busEvent, entitySqlDaoWrapperFactory.getHandle().getConnection());
        }
    } catch (final EventBusException e) {
        log.warn("Failed to post effective event for subscriptionId='{}'", subscription.getId(), e);
    }
}
Also used : SubscriptionBaseTransitionData(org.killbill.billing.subscription.api.user.SubscriptionBaseTransitionData) DefaultEffectiveSubscriptionEvent(org.killbill.billing.subscription.api.user.DefaultEffectiveSubscriptionEvent) EventBusException(org.killbill.bus.api.PersistentBus.EventBusException) BusEvent(org.killbill.bus.api.BusEvent)

Example 4 with DefaultEffectiveSubscriptionEvent

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

the class TestEventJson method testSubscriptionEvent.

@Test(groups = "fast")
public void testSubscriptionEvent() throws Exception {
    final EffectiveSubscriptionInternalEvent e = new DefaultEffectiveSubscriptionEvent(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), null, new DateTime(), EntitlementState.ACTIVE, "pro", "TRIAL", "DEFAULT", null, EntitlementState.CANCELLED, null, null, null, null, 3L, SubscriptionBaseTransitionType.CANCEL, 0, new DateTime(), 1L, 2L, null);
    final String json = mapper.writeValueAsString(e);
    final Class<?> claz = Class.forName(DefaultEffectiveSubscriptionEvent.class.getName());
    final Object obj = mapper.readValue(json, claz);
    Assert.assertTrue(obj.equals(e));
}
Also used : DefaultEffectiveSubscriptionEvent(org.killbill.billing.subscription.api.user.DefaultEffectiveSubscriptionEvent) EffectiveSubscriptionInternalEvent(org.killbill.billing.events.EffectiveSubscriptionInternalEvent) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 5 with DefaultEffectiveSubscriptionEvent

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

the class TestEventJson method testSubscriptionEventWithNoBillCycleDayLocal.

// Verify deserialization will work when we miss fields (previousBillCycleDayLocal, nextBillCycleDayLocal)
@Test(groups = "fast")
public void testSubscriptionEventWithNoBillCycleDayLocal() throws Exception {
    final String json = "{\"eventId\":\"9e901bbc-bbcb-4f0a-8511-e58029bbea91\",\"subscriptionId\":\"c373056c-bb0c-4562-ab06-f595176aa4ae\",\"bundleId\":\"f61536b1-fc76-4337-b1e8-e38383894352\",\"effectiveTransitionTime\":\"2016-05-26T23:02:20.322Z\",\"previousState\":\"ACTIVE\",\"previousPlan\":\"pro\",\"previousPhase\":\"TRIAL\",\"previousPriceList\":\"DEFAULT\",\"nextState\":\"CANCELLED\",\"nextPlan\":null,\"nextPhase\":null,\"nextPriceList\":null,\"totalOrdering\":3,\"transitionType\":\"CANCEL\",\"remainingEventsForUserOperation\":0,\"startDate\":\"2016-05-26T23:02:20.322Z\",\"searchKey1\":1,\"searchKey2\":2,\"userToken\":null,\"requestedTransitionTime\":\"2016-05-26T23:02:20.322Z\"}";
    final Class<?> claz = Class.forName(DefaultEffectiveSubscriptionEvent.class.getName());
    final DefaultEffectiveSubscriptionEvent obj = (DefaultEffectiveSubscriptionEvent) mapper.readValue(json, claz);
    Assert.assertEquals(obj.getId(), UUID.fromString("9e901bbc-bbcb-4f0a-8511-e58029bbea91"));
    Assert.assertNull(obj.getPreviousBillCycleDayLocal());
    Assert.assertNull(obj.getNextBillCycleDayLocal());
}
Also used : DefaultEffectiveSubscriptionEvent(org.killbill.billing.subscription.api.user.DefaultEffectiveSubscriptionEvent) Test(org.testng.annotations.Test)

Aggregations

DefaultEffectiveSubscriptionEvent (org.killbill.billing.subscription.api.user.DefaultEffectiveSubscriptionEvent)5 SubscriptionBaseTransitionData (org.killbill.billing.subscription.api.user.SubscriptionBaseTransitionData)3 BusEvent (org.killbill.bus.api.BusEvent)3 EventBusException (org.killbill.bus.api.PersistentBus.EventBusException)3 Test (org.testng.annotations.Test)2 DateTime (org.joda.time.DateTime)1 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)1 CatalogApiException (org.killbill.billing.catalog.api.CatalogApiException)1 EffectiveSubscriptionInternalEvent (org.killbill.billing.events.EffectiveSubscriptionInternalEvent)1 DefaultSubscriptionBase (org.killbill.billing.subscription.api.user.DefaultSubscriptionBase)1 CallContext (org.killbill.billing.util.callcontext.CallContext)1