Class RecordOfferUsageEventListener
java.lang.Object
com.broadleafcommerce.promotion.offer.service.messaging.checkout.RecordOfferUsageEventListener
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)
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
protected static final String
-
Constructor Summary
ConstructorDescriptionRecordOfferUsageEventListener
(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 Summary
Modifier and TypeMethodDescriptionprotected com.broadleafcommerce.data.tracking.core.context.ContextInfo
buildContextInfo
(@NonNull String applicationId, @NonNull String tenantId) Builds aContextInfo
for the application context id and tenant idprotected OfferUsageDetails
buildOfferUsageDetails
(@NonNull String orderId, javax.money.MonetaryAmount totalSavings, @NonNull RecordOfferUsageEventListener.Adjustment adjustment) Builds theOfferAuditDetail
for the used offer codeprotected UserTarget
buildUserTarget
(String customerId) Build theUserTarget
associated with the Offer Code's useprotected com.jayway.jsonpath.DocumentContext
getDocumentContext
(@NonNull String payload) Parses the message payload into a `DocumentContext` which allows for JsonPath parsing using Jackson providers.protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService
protected com.fasterxml.jackson.databind.ObjectMapper
protected OfferAuditDetailService<OfferAuditDetail>
protected OfferMessagingProperties
protected org.springframework.transaction.support.TransactionTemplate
protected com.broadleafcommerce.common.extension.TypeFactory
protected String
getUserTargetValue
(@NonNull com.jayway.jsonpath.DocumentContext jsonContext) Retrieves the value to set for theUserTarget.getTargetValue()
on the audit detail(s).void
Event listener entry point.void
processMessage
(org.springframework.messaging.Message<String> message) Processes the received message by extracting fields relevant to recording offer code usage and creatingOfferAuditDetails
-
Field Details
-
SUBMITTED
- See Also:
-
APPLICATION_ID_PATH
- See Also:
-
TENANT_ID_PATH
- See Also:
-
CART_ID_PATH
- See Also:
-
ORDER_STATUS_PATH
- See Also:
-
CUSTOMER_ID_PATH
- See Also:
-
CUSTOMER_USERNAME_PATH
- See Also:
-
CART_EMAIL_PATH
- See Also:
-
ADJUSTMENTS_PATH
- See Also:
-
ORDER_ITEM_ADJUSTMENTS_PATH
- See Also:
-
FULFILLMENT_ITEM_ADJUSTMENTS_PATH
- See Also:
-
FULFILLMENT_GROUP_ADJUSTMENTS_PATH
- See Also:
-
-
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
Processes the received message by extracting fields relevant to recording offer code usage and creatingOfferAuditDetails
- Parameters:
message
- the message payload
-
getUserTargetValue
protected String getUserTargetValue(@NonNull @NonNull com.jayway.jsonpath.DocumentContext jsonContext) Retrieves the value to set for theUserTarget.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
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
Build theUserTarget
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 theOfferAuditDetail
for the used offer code- Parameters:
orderId
- the id of the order that was placedadjustment
- 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 aContextInfo
for the application context id and tenant id- Parameters:
applicationId
- the application context id for the requesttenantId
- the tenant id for the request- Returns:
- a
ContextInfo
for the creation of theOfferAuditDetail
-
getIdempotentConsumptionService
protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService getIdempotentConsumptionService() -
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
-