Class FulfillmentCaptureWebhookListener
- java.lang.Object
-
- com.broadleafcommerce.orderoperation.service.messaging.transactionwebhook.FulfillmentCaptureWebhookListener
-
public class FulfillmentCaptureWebhookListener extends Object
Listens forTransactionWebhookEvent
with typeDefaultTransactionTypes.CAPTURE
and changes theOrderFulfillment.getStatus()
.This listener does not determine the
OrderFulfillment.getStatus()
based on theTransactionWebhookEvent
result, it rather reacts to the fact that a capture transaction result for theOrderFulfillment
is received, and determines the status based on the latest transaction state for theOrderFulfillment
.- Author:
- Sunny Yu
-
-
Constructor Summary
Constructors Constructor Description FulfillmentCaptureWebhookListener(com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentMessageService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, PaymentCaptureAttemptedProducer paymentCaptureCompletionProducer, FulfillmentOperationService fulfillmentOperationService, OrderProvider<com.broadleafcommerce.order.client.domain.Order> orderProvider, FulfillmentProvider<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillmentProvider, PaymentProvider paymentProvider, ResourceLockProvider resourceLockProvider)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected com.broadleafcommerce.order.client.domain.OrderFulfillment
changeFulfillmentStatus(@NonNull PaymentCaptureAttemptResultStatus result, @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Changes theOrderFulfillment.getStatus()
based on the givenPaymentCaptureAttemptResultStatus
.protected void
changeFulfillmentStatusAndSendEvent(@NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull PaymentCaptureAttemptResultStatus resultStatus, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Changes theOrderFulfillment.getStatus()
based on the givenPaymentCaptureAttemptResultStatus
and send event.protected PaymentCaptureAttemptResultStatus
determineCaptureResultStatus(@NonNull TransactionWebhookEvent event, @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Determines thePaymentCaptureAttemptResultStatus
based on the latest transaction state for the givenOrderFulfillment
.protected <T> javax.money.MonetaryAmount
getAmountTotal(@NonNull List<T> objects, @NonNull Function<T,javax.money.MonetaryAmount> amountGetter, @NonNull javax.money.CurrencyUnit currency)
Helper method to sum up theMonetaryAmounts
for each given object using the givenamountGetter function
.protected FulfillmentOperationService
getFulfillmentOperationService()
protected FulfillmentProvider<com.broadleafcommerce.order.client.domain.OrderFulfillment>
getFulfillmentProvider()
protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService
getIdempotentMessageService()
protected com.broadleafcommerce.order.client.domain.OrderFulfillmentStatus
getNewStatusForPaymentCaptureResult(@NonNull PaymentCaptureAttemptResultStatus result)
Gets theOrderFulfillmentStatus
based on the givenPaymentCaptureAttemptResultStatus
.protected OrderProvider<com.broadleafcommerce.order.client.domain.Order>
getOrderProvider()
protected PaymentCaptureAttemptedProducer
getPaymentCaptureCompletionProducer()
protected PaymentProvider
getPaymentProvider()
protected List<PaymentSummary>
getPaymentSummariesForOrderFulfillment(@NonNull String cartType, @NonNull String cartId, @NonNull String orderFulfillmentId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Gets a list ofPaymentSummaries
for theOrderFulfillment
.protected ResourceLockProvider
getResourceLockProvider()
protected javax.money.MonetaryAmount
getTotalFailedToCapture(@NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @NonNull javax.money.MonetaryAmount totalCaptured, @NonNull javax.money.MonetaryAmount totalCaptureAwaiting)
Determines the total failed to capture based on the givenOrderFulfillment
andMonetaryAmounts
.protected com.broadleafcommerce.common.extension.TypeFactory
getTypeFactory()
protected javax.money.MonetaryAmount
identifyAmountToCapture(@NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment)
Determines the total amount that should be captured for the fulfilledOrderFulfillment
.void
listen(org.springframework.messaging.Message<TransactionWebhookEvent> message)
protected void
process(@NonNull TransactionWebhookEvent event)
Processes the givenTransactionWebhookEvent
and updates the associatedOrderFulfillment
accordingly.protected void
processMessage(@NonNull org.springframework.messaging.Message<TransactionWebhookEvent> message)
protected void
sendPaymentCaptureAttemptResult(@NonNull String result, @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Produces & sends an event indicating that the order's payments were just successfully captured so that other systems/services can react accordingly.protected boolean
shouldProcessEvent(@NonNull TransactionWebhookEvent event)
Determines if the givenTransactionWebhookEvent
should be processed.protected boolean
shouldProcessEventForFulfillment(@NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment)
Determines if the givenOrderFulfillment
should be processed.
-
-
-
Constructor Detail
-
FulfillmentCaptureWebhookListener
public FulfillmentCaptureWebhookListener(com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentMessageService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, PaymentCaptureAttemptedProducer paymentCaptureCompletionProducer, FulfillmentOperationService fulfillmentOperationService, OrderProvider<com.broadleafcommerce.order.client.domain.Order> orderProvider, FulfillmentProvider<com.broadleafcommerce.order.client.domain.OrderFulfillment> fulfillmentProvider, PaymentProvider paymentProvider, ResourceLockProvider resourceLockProvider)
-
-
Method Detail
-
listen
@StreamListener("orderOperationsCaptureTransactionWebhookInput") public void listen(org.springframework.messaging.Message<TransactionWebhookEvent> message)
-
processMessage
protected void processMessage(@NonNull @NonNull org.springframework.messaging.Message<TransactionWebhookEvent> message)
-
shouldProcessEvent
protected boolean shouldProcessEvent(@NonNull @NonNull TransactionWebhookEvent event)
Determines if the givenTransactionWebhookEvent
should be processed.Any custom logic should be added here.
- Parameters:
event
- theTransactionWebhookEvent
to check- Returns:
- true if the given
TransactionWebhookEvent
should be processed, otherwise false
-
process
protected void process(@NonNull @NonNull TransactionWebhookEvent event)
Processes the givenTransactionWebhookEvent
and updates the associatedOrderFulfillment
accordingly.- Parameters:
event
- theTransactionWebhookEvent
to process
-
shouldProcessEventForFulfillment
protected boolean shouldProcessEventForFulfillment(@NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment)
Determines if the givenOrderFulfillment
should be processed. This will ensure that theOrderFulfillment
will remainOrderFulfillmentStatus.PAYMENT_CAPTURE_FAILED
if any of the previous captures have already failed.Any custom logic should be added here.
- Parameters:
fulfillment
- theOrderFulfillment
to check- Returns:
- true if the given
OrderFulfillment
should be processed, otherwise false
-
determineCaptureResultStatus
protected PaymentCaptureAttemptResultStatus determineCaptureResultStatus(@NonNull @NonNull TransactionWebhookEvent event, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Determines thePaymentCaptureAttemptResultStatus
based on the latest transaction state for the givenOrderFulfillment
.- Parameters:
event
- theTransactionWebhookEvent
to deteremine the status withorder
- theOrder
associated with theTransactionWebhookEvent
fulfillment
- theOrderFulfillment
that theTransactionWebhookEvent
is forcontextInfo
- context information around sandbox and multitenant state- Returns:
- the
PaymentCaptureAttemptResultStatus
based on the latest transaction state for the givenOrderFulfillment
-
getTotalFailedToCapture
protected javax.money.MonetaryAmount getTotalFailedToCapture(@NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @NonNull @NonNull javax.money.MonetaryAmount totalCaptured, @NonNull @NonNull javax.money.MonetaryAmount totalCaptureAwaiting)
Determines the total failed to capture based on the givenOrderFulfillment
andMonetaryAmounts
.- Parameters:
fulfillment
- theOrderFulfillment
to determine the amount failed to capture fortotalCaptured
- the total captured for theOrderFulfillment
totalCaptureAwaiting
- the total capture awaiting result for theOrderFulfillment
- Returns:
- the total failed to capture based on the given
OrderFulfillment
andMonetaryAmounts
-
changeFulfillmentStatusAndSendEvent
protected void changeFulfillmentStatusAndSendEvent(@NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull @NonNull PaymentCaptureAttemptResultStatus resultStatus, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Changes theOrderFulfillment.getStatus()
based on the givenPaymentCaptureAttemptResultStatus
and send event.- Parameters:
fulfillment
- theOrderFulfillment
to change status fororder
- theOrder
that theOrderFulfillment
belongs toresultStatus
- thePaymentCaptureAttemptResultStatus
contextInfo
- context information around sandbox and multitenant state
-
getPaymentSummariesForOrderFulfillment
protected List<PaymentSummary> getPaymentSummariesForOrderFulfillment(@NonNull @NonNull String cartType, @NonNull @NonNull String cartId, @NonNull @NonNull String orderFulfillmentId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Gets a list ofPaymentSummaries
for theOrderFulfillment
.- Parameters:
cartType
- the type of the cart that owns the paymentscartId
- the id of the cart that owns the paymentsorderFulfillmentId
- theOrderFulfillment.getId()
to filter the transactions forcontextInfo
- context information surrounding multitenant state- Returns:
- a list of
PaymentSummaries
for theOrderFulfillment
-
identifyAmountToCapture
protected javax.money.MonetaryAmount identifyAmountToCapture(@NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment)
Determines the total amount that should be captured for the fulfilledOrderFulfillment
.- Parameters:
fulfillment
- The fulfillment to be captured- Returns:
- the amount of money to capture based on the fulfillment
-
getAmountTotal
protected <T> javax.money.MonetaryAmount getAmountTotal(@NonNull @NonNull List<T> objects, @NonNull @NonNull Function<T,javax.money.MonetaryAmount> amountGetter, @NonNull @NonNull javax.money.CurrencyUnit currency)
Helper method to sum up theMonetaryAmounts
for each given object using the givenamountGetter function
.- Type Parameters:
T
- the type of the object- Parameters:
objects
- a list of objects to sumamountGetter
- theFunction
used to get theMonetaryAmounts
from the given objectscurrency
- theCurrencyUnit
- Returns:
- the total amount summed from the given objects
-
changeFulfillmentStatus
protected com.broadleafcommerce.order.client.domain.OrderFulfillment changeFulfillmentStatus(@NonNull @NonNull PaymentCaptureAttemptResultStatus result, @NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Changes theOrderFulfillment.getStatus()
based on the givenPaymentCaptureAttemptResultStatus
.- Parameters:
result
- thePaymentCaptureAttemptResultStatus
fulfillment
- theOrderFulfillment
to change status forcontextInfo
- context information surrounding multitenant state- Returns:
- the
OrderFulfillment
with the updated status
-
getNewStatusForPaymentCaptureResult
protected com.broadleafcommerce.order.client.domain.OrderFulfillmentStatus getNewStatusForPaymentCaptureResult(@NonNull @NonNull PaymentCaptureAttemptResultStatus result)
Gets theOrderFulfillmentStatus
based on the givenPaymentCaptureAttemptResultStatus
.- Parameters:
result
- thePaymentCaptureAttemptResultStatus
to determine theOrderFulfillmentStatus
with- Returns:
- the
OrderFulfillmentStatus
based on the givenPaymentCaptureAttemptResultStatus
-
sendPaymentCaptureAttemptResult
protected void sendPaymentCaptureAttemptResult(@NonNull @NonNull String result, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Produces & sends an event indicating that the order's payments were just successfully captured so that other systems/services can react accordingly.- Parameters:
result
- thePaymentCaptureAttemptResultStatus
of attempting the capture, indicating types of success or failureorder
- The most up-to-date order with partially or fully captured paymentsfulfillment
- The fulfillment which had payment capturedcontextInfo
- Context information around sandbox and multitenant state.
-
getIdempotentMessageService
protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService getIdempotentMessageService()
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-
getPaymentCaptureCompletionProducer
protected PaymentCaptureAttemptedProducer getPaymentCaptureCompletionProducer()
-
getFulfillmentOperationService
protected FulfillmentOperationService getFulfillmentOperationService()
-
getOrderProvider
protected OrderProvider<com.broadleafcommerce.order.client.domain.Order> getOrderProvider()
-
getFulfillmentProvider
protected FulfillmentProvider<com.broadleafcommerce.order.client.domain.OrderFulfillment> getFulfillmentProvider()
-
getPaymentProvider
protected PaymentProvider getPaymentProvider()
-
getResourceLockProvider
protected ResourceLockProvider getResourceLockProvider()
-
-