Class RecordOfferUsageEventListener

java.lang.Object
com.broadleafcommerce.promotion.offer.service.messaging.checkout.RecordOfferUsageEventListener

@DataRouteByKey("offer") public class RecordOfferUsageEventListener extends Object
An event listener that triggers when an order is successfully submitted. Responsible for recording any offer usages associated with the order.
Author:
Jon Fleschler (jfleschler), Nathan Moore (nathandmoore)
  • Field Details

  • Constructor Details

    • RecordOfferUsageEventListener

      public RecordOfferUsageEventListener(com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentConsumptionService, OfferAuditDetailService<OfferAuditDetail> offerAuditDetailService, org.springframework.transaction.support.TransactionTemplate template, com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, OfferMessagingProperties offerMessagingProperties)
  • Method Details

    • listen

      @StreamListener("checkoutCompletionInputOffer") public void listen(org.springframework.messaging.Message<String> message)
      Event listener entry point. Checks if the message has already been received and, if not, begins processing it.
      Parameters:
      message - the message payload
    • processMessage

      public void processMessage(org.springframework.messaging.Message<String> message)
      Processes the received message by extracting fields relevant to recording offer code usage and creating OfferAuditDetails
      Parameters:
      message - the message payload
    • getUserTargetValue

      protected String getUserTargetValue(@NonNull @NonNull com.jayway.jsonpath.DocumentContext jsonContext)
      Retrieves the value to set for the UserTarget.getTargetValue() on the audit detail(s). This defaults to the user's email.
      Parameters:
      jsonContext - The message payload
      Returns:
      the value to set for the UserTarget.getTargetValue() on the audit detail(s).
    • getDocumentContext

      protected com.jayway.jsonpath.DocumentContext getDocumentContext(@NonNull @NonNull String payload)
      Parses the message payload into a `DocumentContext` which allows for JsonPath parsing using Jackson providers.
      Parameters:
      payload - the message payload
      Returns:
      a `DocumentContext` representation of the message payload
    • buildUserTarget

      protected UserTarget buildUserTarget(@Nullable String customerId)
      Build the UserTarget associated with the Offer Code's use
      Parameters:
      customerId - the id of the customer that used the offer code
      Returns:
      a UserTarget of type customer
    • buildOfferUsageDetails

      protected OfferUsageDetails buildOfferUsageDetails(@NonNull @NonNull String orderId, javax.money.MonetaryAmount totalSavings, @NonNull @NonNull RecordOfferUsageEventListener.Adjustment adjustment)
      Builds the OfferAuditDetail for the used offer code
      Parameters:
      orderId - the id of the order that was placed
      adjustment - the adjustment that was applied to the order (offer id and code used)
      Returns:
      an OfferAuditDetail for the code used
    • buildContextInfo

      protected com.broadleafcommerce.data.tracking.core.context.ContextInfo buildContextInfo(@NonNull @NonNull String applicationId, @NonNull @NonNull String tenantId)
      Builds a ContextInfo for the application context id and tenant id
      Parameters:
      applicationId - the application context id for the request
      tenantId - the tenant id for the request
      Returns:
      a ContextInfo for the creation of the OfferAuditDetail
    • getIdempotentConsumptionService

      protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService getIdempotentConsumptionService()
    • getOfferAuditDetailService

      protected OfferAuditDetailService<OfferAuditDetail> getOfferAuditDetailService()
    • getTemplate

      protected org.springframework.transaction.support.TransactionTemplate getTemplate()
    • getObjectMapper

      protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • getOfferMessagingProperties

      protected OfferMessagingProperties getOfferMessagingProperties()