Search in sources :

Example 16 with BusEvent

use of org.killbill.bus.api.BusEvent 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 17 with BusEvent

use of org.killbill.bus.api.BusEvent 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 SubscriptionCatalog catalog = subscriptionCatalogApi.getFullCatalog(context);
        final DefaultSubscriptionBase subscription = (DefaultSubscriptionBase) dao.getSubscriptionFromId(event.getSubscriptionId(), catalog, 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, catalog, context);
        } else if (event.getType() == EventType.API_USER && subscription.getCategory() == ProductCategory.BASE) {
            final CallContext callContext = internalCallContextFactory.createCallContext(context);
            eventSent = onBasePlanEvent(subscription, event, catalog, 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) SubscriptionCatalog(org.killbill.billing.subscription.catalog.SubscriptionCatalog) InternalCallContext(org.killbill.billing.callcontext.InternalCallContext) CallContext(org.killbill.billing.util.callcontext.CallContext) BusEvent(org.killbill.bus.api.BusEvent)

Example 18 with BusEvent

use of org.killbill.bus.api.BusEvent in project killbill by killbill.

the class TestBeatrixListener method testInvoiceAdjustment.

@Test(groups = "fast")
public void testInvoiceAdjustment() throws Exception {
    InvoiceAdjustmentInternalEvent event = mock(InvoiceAdjustmentInternalEvent.class);
    provideCommonBusEventInfo(event);
    when(event.getBusEventType()).thenReturn(BusInternalEventType.INVOICE_ADJUSTMENT);
    when(event.getInvoiceId()).thenReturn(OBJECT_ID);
    when(internalCallContextFactory.getAccountId(OBJECT_ID, ObjectType.INVOICE, tenantContext)).thenReturn(ACCOUNT_ID);
    ArgumentCaptor<BusEvent> eventCaptor = ArgumentCaptor.forClass(BusEvent.class);
    beatrixListener.handleAllInternalKillbillEvents(event);
    verify(externalBus).post(eventCaptor.capture());
    DefaultBusExternalEvent postedEvent = (DefaultBusExternalEvent) eventCaptor.getValue();
    assertEquals(postedEvent.getObjectId(), OBJECT_ID);
    assertEquals(postedEvent.getObjectType(), ObjectType.INVOICE);
    assertEquals(postedEvent.getEventType(), ExtBusEventType.INVOICE_ADJUSTMENT);
    assertNull(postedEvent.getMetaData());
    assertCommonFieldsWithAccountId(postedEvent);
}
Also used : InvoiceAdjustmentInternalEvent(org.killbill.billing.events.InvoiceAdjustmentInternalEvent) BusEvent(org.killbill.bus.api.BusEvent) Test(org.testng.annotations.Test)

Example 19 with BusEvent

use of org.killbill.bus.api.BusEvent in project killbill by killbill.

the class TestBeatrixListener method testPaymentError.

@Test(groups = "fast")
public void testPaymentError() throws Exception {
    PaymentErrorInternalEvent event = mock(PaymentErrorInternalEvent.class);
    provideCommonBusEventInfo(event);
    when(event.getBusEventType()).thenReturn(BusInternalEventType.PAYMENT_ERROR);
    when(event.getPaymentId()).thenReturn(OBJECT_ID);
    when(event.getAccountId()).thenReturn(ACCOUNT_ID);
    provideCommonPaymentInfo(event);
    ArgumentCaptor<PaymentMetadata> metadataCaptor = ArgumentCaptor.forClass(PaymentMetadata.class);
    when(objectMapper.writeValueAsString(metadataCaptor.capture())).thenReturn(METADATA);
    ArgumentCaptor<BusEvent> eventCaptor = ArgumentCaptor.forClass(BusEvent.class);
    beatrixListener.handleAllInternalKillbillEvents(event);
    verify(externalBus).post(eventCaptor.capture());
    DefaultBusExternalEvent postedEvent = (DefaultBusExternalEvent) eventCaptor.getValue();
    assertEquals(postedEvent.getObjectId(), OBJECT_ID);
    assertEquals(postedEvent.getObjectType(), ObjectType.PAYMENT);
    assertEquals(postedEvent.getEventType(), ExtBusEventType.PAYMENT_FAILED);
    assertEquals(postedEvent.getMetaData(), METADATA);
    assertCommonFieldsWithAccountId(postedEvent);
    PaymentMetadata paymentMetadata = metadataCaptor.getValue();
    assertPaymentMetadataFields(paymentMetadata);
}
Also used : PaymentErrorInternalEvent(org.killbill.billing.events.PaymentErrorInternalEvent) InvoicePaymentErrorInternalEvent(org.killbill.billing.events.InvoicePaymentErrorInternalEvent) PaymentMetadata(org.killbill.billing.notification.plugin.api.PaymentMetadata) InvoicePaymentMetadata(org.killbill.billing.notification.plugin.api.InvoicePaymentMetadata) BusEvent(org.killbill.bus.api.BusEvent) Test(org.testng.annotations.Test)

Example 20 with BusEvent

use of org.killbill.bus.api.BusEvent in project killbill by killbill.

the class TestBeatrixListener method testUserTagCreation.

@Test(groups = "fast")
public void testUserTagCreation() throws Exception {
    UserTagCreationInternalEvent event = mock(UserTagCreationInternalEvent.class);
    provideCommonBusEventInfo(event);
    when(event.getBusEventType()).thenReturn(BusInternalEventType.USER_TAG_CREATION);
    when(event.getTagId()).thenReturn(OBJECT_ID);
    when(event.getTagDefinition()).thenReturn(new DefaultTagDefinition("MY_TAG", "", false));
    when(internalCallContextFactory.getAccountId(OBJECT_ID, ObjectType.TAG, tenantContext)).thenReturn(ACCOUNT_ID);
    ArgumentCaptor<BusEvent> eventCaptor = ArgumentCaptor.forClass(BusEvent.class);
    beatrixListener.handleAllInternalKillbillEvents(event);
    verify(externalBus).post(eventCaptor.capture());
    DefaultBusExternalEvent postedEvent = (DefaultBusExternalEvent) eventCaptor.getValue();
    assertEquals(postedEvent.getObjectId(), OBJECT_ID);
    assertEquals(postedEvent.getObjectType(), ObjectType.TAG);
    assertEquals(postedEvent.getEventType(), ExtBusEventType.TAG_CREATION);
    assertEquals(postedEvent.getMetaData(), "MY_TAG");
    assertCommonFieldsWithAccountId(postedEvent);
}
Also used : DefaultTagDefinition(org.killbill.billing.util.tag.DefaultTagDefinition) UserTagCreationInternalEvent(org.killbill.billing.events.UserTagCreationInternalEvent) BusEvent(org.killbill.bus.api.BusEvent) Test(org.testng.annotations.Test)

Aggregations

BusEvent (org.killbill.bus.api.BusEvent)27 Test (org.testng.annotations.Test)20 InvoicePaymentMetadata (org.killbill.billing.notification.plugin.api.InvoicePaymentMetadata)5 EventBusException (org.killbill.bus.api.PersistentBus.EventBusException)4 PaymentMetadata (org.killbill.billing.notification.plugin.api.PaymentMetadata)3 DefaultEffectiveSubscriptionEvent (org.killbill.billing.subscription.api.user.DefaultEffectiveSubscriptionEvent)3 SubscriptionBaseTransitionData (org.killbill.billing.subscription.api.user.SubscriptionBaseTransitionData)3 DefaultTagDefinition (org.killbill.billing.util.tag.DefaultTagDefinition)3 NotificationEvent (org.killbill.notificationq.api.NotificationEvent)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 OutputStream (java.io.OutputStream)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 StreamingOutput (javax.ws.rs.core.StreamingOutput)2 DateTime (org.joda.time.DateTime)2 InternalCallContext (org.killbill.billing.callcontext.InternalCallContext)2 InvoicePaymentErrorInternalEvent (org.killbill.billing.events.InvoicePaymentErrorInternalEvent)2