Class FulfillmentCaptureWebhookListener
- java.lang.Object
-
- com.broadleafcommerce.orderoperation.service.messaging.transactionwebhook.FulfillmentCaptureWebhookListener
-
public class FulfillmentCaptureWebhookListener extends Object
Listens forTransactionWebhookEventwith typeDefaultTransactionTypes.CAPTUREand changes theOrderFulfillment.getStatus().This listener does not determine the
OrderFulfillment.getStatus()based on theTransactionWebhookEventresult, it rather reacts to the fact that a capture transaction result for theOrderFulfillmentis 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.OrderFulfillmentchangeFulfillmentStatus(@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 voidchangeFulfillmentStatusAndSendEvent(@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 givenPaymentCaptureAttemptResultStatusand send event.protected PaymentCaptureAttemptResultStatusdetermineCaptureResultStatus(@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 thePaymentCaptureAttemptResultStatusbased on the latest transaction state for the givenOrderFulfillment.protected <T> javax.money.MonetaryAmountgetAmountTotal(@NonNull List<T> objects, @NonNull Function<T,javax.money.MonetaryAmount> amountGetter, @NonNull javax.money.CurrencyUnit currency)Helper method to sum up theMonetaryAmountsfor each given object using the givenamountGetter function.protected FulfillmentOperationServicegetFulfillmentOperationService()protected FulfillmentProvider<com.broadleafcommerce.order.client.domain.OrderFulfillment>getFulfillmentProvider()protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionServicegetIdempotentMessageService()protected com.broadleafcommerce.order.client.domain.OrderFulfillmentStatusgetNewStatusForPaymentCaptureResult(@NonNull PaymentCaptureAttemptResultStatus result)Gets theOrderFulfillmentStatusbased on the givenPaymentCaptureAttemptResultStatus.protected OrderProvider<com.broadleafcommerce.order.client.domain.Order>getOrderProvider()protected PaymentCaptureAttemptedProducergetPaymentCaptureCompletionProducer()protected PaymentProvidergetPaymentProvider()protected List<PaymentSummary>getPaymentSummariesForOrderFulfillment(@NonNull String cartType, @NonNull String cartId, @NonNull String orderFulfillmentId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Gets a list ofPaymentSummariesfor theOrderFulfillment.protected ResourceLockProvidergetResourceLockProvider()protected javax.money.MonetaryAmountgetTotalFailedToCapture(@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 givenOrderFulfillmentandMonetaryAmounts.protected com.broadleafcommerce.common.extension.TypeFactorygetTypeFactory()protected javax.money.MonetaryAmountidentifyAmountToCapture(@NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment)Determines the total amount that should be captured for the fulfilledOrderFulfillment.voidlisten(org.springframework.messaging.Message<TransactionWebhookEvent> message)protected voidprocess(@NonNull TransactionWebhookEvent event)Processes the givenTransactionWebhookEventand updates the associatedOrderFulfillmentaccordingly.protected voidprocessMessage(@NonNull org.springframework.messaging.Message<TransactionWebhookEvent> message)protected voidsendPaymentCaptureAttemptResult(@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 booleanshouldProcessEvent(@NonNull TransactionWebhookEvent event)Determines if the givenTransactionWebhookEventshould be processed.protected booleanshouldProcessEventForFulfillment(@NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment)Determines if the givenOrderFulfillmentshould 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 givenTransactionWebhookEventshould be processed.Any custom logic should be added here.
- Parameters:
event- theTransactionWebhookEventto check- Returns:
- true if the given
TransactionWebhookEventshould be processed, otherwise false
-
process
protected void process(@NonNull @NonNull TransactionWebhookEvent event)Processes the givenTransactionWebhookEventand updates the associatedOrderFulfillmentaccordingly.- Parameters:
event- theTransactionWebhookEventto process
-
shouldProcessEventForFulfillment
protected boolean shouldProcessEventForFulfillment(@NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment)Determines if the givenOrderFulfillmentshould be processed. This will ensure that theOrderFulfillmentwill remainOrderFulfillmentStatus.PAYMENT_CAPTURE_FAILEDif any of the previous captures have already failed.Any custom logic should be added here.
- Parameters:
fulfillment- theOrderFulfillmentto check- Returns:
- true if the given
OrderFulfillmentshould 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 thePaymentCaptureAttemptResultStatusbased on the latest transaction state for the givenOrderFulfillment.- Parameters:
event- theTransactionWebhookEventto deteremine the status withorder- theOrderassociated with theTransactionWebhookEventfulfillment- theOrderFulfillmentthat theTransactionWebhookEventis forcontextInfo- context information around sandbox and multitenant state- Returns:
- the
PaymentCaptureAttemptResultStatusbased 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 givenOrderFulfillmentandMonetaryAmounts.- Parameters:
fulfillment- theOrderFulfillmentto determine the amount failed to capture fortotalCaptured- the total captured for theOrderFulfillmenttotalCaptureAwaiting- the total capture awaiting result for theOrderFulfillment- Returns:
- the total failed to capture based on the given
OrderFulfillmentandMonetaryAmounts
-
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 givenPaymentCaptureAttemptResultStatusand send event.- Parameters:
fulfillment- theOrderFulfillmentto change status fororder- theOrderthat theOrderFulfillmentbelongs toresultStatus- thePaymentCaptureAttemptResultStatuscontextInfo- 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 ofPaymentSummariesfor 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
PaymentSummariesfor 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 theMonetaryAmountsfor each given object using the givenamountGetter function.- Type Parameters:
T- the type of the object- Parameters:
objects- a list of objects to sumamountGetter- theFunctionused to get theMonetaryAmountsfrom 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- thePaymentCaptureAttemptResultStatusfulfillment- theOrderFulfillmentto change status forcontextInfo- context information surrounding multitenant state- Returns:
- the
OrderFulfillmentwith the updated status
-
getNewStatusForPaymentCaptureResult
protected com.broadleafcommerce.order.client.domain.OrderFulfillmentStatus getNewStatusForPaymentCaptureResult(@NonNull @NonNull PaymentCaptureAttemptResultStatus result)Gets theOrderFulfillmentStatusbased on the givenPaymentCaptureAttemptResultStatus.- Parameters:
result- thePaymentCaptureAttemptResultStatusto determine theOrderFulfillmentStatuswith- Returns:
- the
OrderFulfillmentStatusbased 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- thePaymentCaptureAttemptResultStatusof 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()
-
-