Class FulfillmentCapturingPaymentListener
- java.lang.Object
-
- com.broadleafcommerce.orderoperation.service.messaging.fulfillments.FulfillmentCapturingPaymentListener
-
public class FulfillmentCapturingPaymentListener extends Object
Listens to fulfillment capturing payment events and captures payment for them if necessary.
-
-
Constructor Summary
Constructors Constructor Description FulfillmentCapturingPaymentListener(com.broadleafcommerce.common.extension.TypeFactory typeFactory, OrderProvider<com.broadleafcommerce.order.client.domain.Order> orderProvider, PaymentCaptureService paymentCaptureService, PaymentCaptureAttemptedProducer paymentCaptureCompletionProducer, FulfillmentOperationService fulfillmentOperationService, com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentMessageService, ResourceLockProvider resourceLockProvider, PaymentProvider paymentProvider)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
attemptPaymentCapture(@NonNull com.broadleafcommerce.order.client.domain.Order order, @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Attempts to capture payments for theOrderFulfillment
.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)
protected PaymentCaptureAttemptResultStatus
determineNonFailureResultStatus(@NonNull javax.money.MonetaryAmount amountToCapture, @NonNull List<TransactionExecutionResponse> responses)
Determines thePaymentCaptureAttemptResultStatus
based on the givenamountToCapture
andTransactionExecutionResponses
.protected javax.money.MonetaryAmount
getAmountCapturedOrBeingCaptured(List<PaymentSummary> paymentSummaries, javax.money.CurrencyUnit currency)
Gets the total of amount captured or capture awaiting result from the givenPaymentSummaries
.protected javax.money.MonetaryAmount
getAmountToCapture(@NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @NonNull com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Determines the amount that can be captured for the fulfilledOrderFulfillment
.protected FulfillmentOperationService
getFulfillmentOperationService()
protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService
getIdempotentMessageService()
protected com.broadleafcommerce.order.client.domain.OrderFulfillmentStatus
getNewStatusForPaymentCaptureResult(@NonNull PaymentCaptureAttemptResultStatus result)
protected com.broadleafcommerce.order.client.domain.Order
getOrder(@NonNull FulfillmentStatusChangeEvent event)
Get theOrder
in theevent
, refreshing in case any payment changes have occurred on the order.protected OrderProvider<com.broadleafcommerce.order.client.domain.Order>
getOrderProvider()
protected PaymentCaptureAttemptedProducer
getPaymentCaptureCompletionProducer()
protected PaymentCaptureService
getPaymentCaptureService()
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 com.broadleafcommerce.common.extension.TypeFactory
getTypeFactory()
protected boolean
hasFulfillmentBeenCaptured(@NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @NonNull com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Deprecated, for removal: This API element is subject to removal in a future version.since 1.7.2, no longer usedprotected 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<FulfillmentStatusChangeEvent> message)
protected void
processEvent(@NonNull org.springframework.messaging.Message<FulfillmentStatusChangeEvent> 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
shouldCapturePayment(@NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @NonNull com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Determine whether theOrderFulfillment
should be captured.
-
-
-
Constructor Detail
-
FulfillmentCapturingPaymentListener
public FulfillmentCapturingPaymentListener(com.broadleafcommerce.common.extension.TypeFactory typeFactory, OrderProvider<com.broadleafcommerce.order.client.domain.Order> orderProvider, PaymentCaptureService paymentCaptureService, PaymentCaptureAttemptedProducer paymentCaptureCompletionProducer, FulfillmentOperationService fulfillmentOperationService, com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentMessageService, ResourceLockProvider resourceLockProvider, PaymentProvider paymentProvider)
-
-
Method Detail
-
listen
@StreamListener("orderOperationsFulfillmentCapturingPaymentInput") public void listen(org.springframework.messaging.Message<FulfillmentStatusChangeEvent> message)
-
processEvent
protected void processEvent(@NonNull @NonNull org.springframework.messaging.Message<FulfillmentStatusChangeEvent> message)
-
attemptPaymentCapture
protected void attemptPaymentCapture(@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)
Attempts to capture payments for theOrderFulfillment
.- Parameters:
order
- theOrder
that the givenOrderFulfillment
belongs tofulfillment
- theOrderFulfillment
to capturecontextInfo
- 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
-
getAmountCapturedOrBeingCaptured
protected javax.money.MonetaryAmount getAmountCapturedOrBeingCaptured(List<PaymentSummary> paymentSummaries, javax.money.CurrencyUnit currency)
Gets the total of amount captured or capture awaiting result from the givenPaymentSummaries
.- Parameters:
paymentSummaries
- the list ofPaymentSummaries
to get the total fromcurrency
- theCurrencyUnit
- Returns:
- the total of amount captured or capture awaiting result from the given
PaymentSummaries
-
getOrder
protected com.broadleafcommerce.order.client.domain.Order getOrder(@NonNull @NonNull FulfillmentStatusChangeEvent event)
Get theOrder
in theevent
, refreshing in case any payment changes have occurred on the order.- Parameters:
event
- the event of the fulfillment being fulfilled- Returns:
- the retrieved order based on the event
-
shouldCapturePayment
protected boolean shouldCapturePayment(@NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Determine whether theOrderFulfillment
should be captured. Extend this method to use some other criteria to capture payment.- Parameters:
fulfillment
- The fulfillment to possibly capture payment fororder
- the order the fulfillment belongs tocontextInfo
- context information around sandbox and multitenant state- Returns:
- whether the fulfillment should have payment captured
-
hasFulfillmentBeenCaptured
@Deprecated(since="1.7.2", forRemoval=true) protected boolean hasFulfillmentBeenCaptured(@NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Deprecated, for removal: This API element is subject to removal in a future version.since 1.7.2, no longer usedDetermines whether theOrderFulfillment
has been captured by looking atPaymentSummaries
related to thisOrderFulfillment
.- Parameters:
fulfillment
- theOrderFulfillment
to check againstorder
- theOrder
that theOrderFulfillment
belongs tocontextInfo
- context information around sandbox and multitenant state- Returns:
- whether the
OrderFulfillment
has been captured
-
getAmountToCapture
protected javax.money.MonetaryAmount getAmountToCapture(@NonNull @NonNull com.broadleafcommerce.order.client.domain.OrderFulfillment fulfillment, @NonNull @NonNull com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Determines the amount that can be captured for the fulfilledOrderFulfillment
.- Parameters:
fulfillment
- theOrderFulfillment
to determine the capturable amount for- Returns:
- the amount of money that can be captured for the fulfillment
-
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
-
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)
-
determineNonFailureResultStatus
protected PaymentCaptureAttemptResultStatus determineNonFailureResultStatus(@NonNull @NonNull javax.money.MonetaryAmount amountToCapture, @NonNull @NonNull List<TransactionExecutionResponse> responses)
Determines thePaymentCaptureAttemptResultStatus
based on the givenamountToCapture
andTransactionExecutionResponses
.Note that this method only determines non-failure statuses, since a
PaymentTransactionFailureException
is expected to be thrown if any one of the capture transactions failed.- Parameters:
amountToCapture
- the total amount expected to be capturedresponses
- theTransactionExecutionResponses
for the capture transactions- Returns:
- the
PaymentCaptureAttemptResultStatus
based on the givenamountToCapture
andTransactionExecutionResponses
-
getNewStatusForPaymentCaptureResult
protected com.broadleafcommerce.order.client.domain.OrderFulfillmentStatus getNewStatusForPaymentCaptureResult(@NonNull @NonNull PaymentCaptureAttemptResultStatus result)
-
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.
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-
getOrderProvider
protected OrderProvider<com.broadleafcommerce.order.client.domain.Order> getOrderProvider()
-
getPaymentCaptureService
protected PaymentCaptureService getPaymentCaptureService()
-
getPaymentCaptureCompletionProducer
protected PaymentCaptureAttemptedProducer getPaymentCaptureCompletionProducer()
-
getFulfillmentOperationService
protected FulfillmentOperationService getFulfillmentOperationService()
-
getIdempotentMessageService
protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService getIdempotentMessageService()
-
getResourceLockProvider
protected ResourceLockProvider getResourceLockProvider()
-
getPaymentProvider
protected PaymentProvider getPaymentProvider()
-
-