Class ExternalPaymentTransactionResultListener
java.lang.Object
com.broadleafcommerce.cartoperation.service.messaging.finalizecart.ExternalPaymentTransactionResultListener
Listens for
PaymentTransactionResultEvents
for transactions
that were executed outside the Broadleaf ecosystem as part of a checkout interaction (e.g. some
3DS interactions and most HPP interactions). From there, it determines if the cart's payments
have successful checkout transactions matching the cart total. If so, then an event is sent to
finalize the cart. Note: This flow all requires that the cart status is
DefaultCartStatuses.AWAITING_PAYMENT_FINALIZATION
, which should have been declared with
the initial checkout attempt.- Author:
- mariestandeven
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CartProvider
protected final CartOperationCheckoutProperties
protected final com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService
protected final PaymentProvider<PaymentSummary>
protected final com.broadleafcommerce.common.extension.TypeFactory
-
Constructor Summary
ConstructorsConstructorDescriptionExternalPaymentTransactionResultListener
(com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentMessageConsumptionService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, CartProvider cartProvider, PaymentProvider<PaymentSummary> paymentProvider, CartOperationCheckoutProperties checkoutProperties) -
Method Summary
Modifier and TypeMethodDescriptionprotected com.broadleafcommerce.data.tracking.core.context.ContextInfo
buildUpdateContextInfoFromCart
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart) Builds aContextInfo
withOperationType.UPDATE
from the givenCart
.protected boolean
cartPaymentAmountsMatchCartTotal
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if all the payments for the givenCart
add up to cart's total.protected boolean
checkIfTransactionTypeMatchesExpectedType
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull PaymentTransactionResultEvent transactionResultEvent, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected String
getApplicationIdFromContext
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected CartProvider
protected CartOperationCheckoutProperties
protected String
getCheckoutTransactionType
(@NonNull String gatewayType, @NonNull String paymentType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService
protected PaymentProvider<PaymentSummary>
protected String
getTenantIdFromContext
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected com.broadleafcommerce.common.extension.TypeFactory
void
listen
(org.springframework.messaging.Message<PaymentTransactionResultEvent> message) protected void
processMessage
(@NonNull org.springframework.messaging.Message<PaymentTransactionResultEvent> message) protected com.broadleafcommerce.cart.client.domain.Cart
retrieveCart
(@NonNull PaymentTransactionResultEvent transactionResultEvent, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected boolean
shouldFinalizeCart
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull PaymentTransactionResultEvent transactionResultEvent, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected boolean
shouldProcessTransactionResult
(@NonNull PaymentTransactionResultEvent transactionResultEvent, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
Field Details
-
idempotentMessageConsumptionService
protected final com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentMessageConsumptionService -
typeFactory
protected final com.broadleafcommerce.common.extension.TypeFactory typeFactory -
cartProvider
-
paymentProvider
-
checkoutProperties
-
-
Constructor Details
-
ExternalPaymentTransactionResultListener
public ExternalPaymentTransactionResultListener(com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentMessageConsumptionService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, CartProvider cartProvider, PaymentProvider<PaymentSummary> paymentProvider, CartOperationCheckoutProperties checkoutProperties)
-
-
Method Details
-
listen
@StreamListener("externalPaymentTransactionResultInput") public void listen(org.springframework.messaging.Message<PaymentTransactionResultEvent> message) -
processMessage
protected void processMessage(@NonNull @NonNull org.springframework.messaging.Message<PaymentTransactionResultEvent> message) -
shouldProcessTransactionResult
protected boolean shouldProcessTransactionResult(@NonNull @NonNull PaymentTransactionResultEvent transactionResultEvent, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
retrieveCart
protected com.broadleafcommerce.cart.client.domain.Cart retrieveCart(@NonNull @NonNull PaymentTransactionResultEvent transactionResultEvent, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
shouldFinalizeCart
protected boolean shouldFinalizeCart(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull PaymentTransactionResultEvent transactionResultEvent, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
checkIfTransactionTypeMatchesExpectedType
protected boolean checkIfTransactionTypeMatchesExpectedType(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull PaymentTransactionResultEvent transactionResultEvent, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
cartPaymentAmountsMatchCartTotal
protected boolean cartPaymentAmountsMatchCartTotal(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if all the payments for the givenCart
add up to cart's total.If all the cart's payments have results but the amounts don't add up to cart's total, that means one or more payments failed, as failed transactions are excluded from the amounts in
PaymentSummary
.- Parameters:
cart
- theCart
to check againstcontextInfo
- context information around sandbox and multitenant state- Returns:
- true if all the payments for the given
Cart
match the cart's total, otherwise false - Throws:
UnsupportedOperationException
- if the checkout transaction type is not supported
-
getCheckoutTransactionType
-
getApplicationIdFromContext
@Nullable protected String getApplicationIdFromContext(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getTenantIdFromContext
@Nullable protected String getTenantIdFromContext(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
buildUpdateContextInfoFromCart
protected com.broadleafcommerce.data.tracking.core.context.ContextInfo buildUpdateContextInfoFromCart(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart) Builds aContextInfo
withOperationType.UPDATE
from the givenCart
.This is useful to make requests for
Cart
in the correct context, since scheduled job itself doesn't have application context. This method makes it easier to achieve that rather than creating new endpoints for each operation to ignore application context.- Parameters:
cart
- theCart
to build the context info from- Returns:
- a
ContextInfo
withOperationType.UPDATE
from the givenCart
-
getIdempotentMessageConsumptionService
protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService getIdempotentMessageConsumptionService() -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getCartProvider
-
getPaymentProvider
-
getCheckoutProperties
-