Class ExternalPaymentTransactionCartFinalizationListener
java.lang.Object
com.broadleafcommerce.cartoperation.service.messaging.finalizecart.ExternalPaymentTransactionCartFinalizationListener
Message listener used to finalize carts that are in the
DefaultCartStatuses.AWAITING_PAYMENT_FINALIZATION
cart status. Prior to finalizing the
cart, this listener first verifies that the cart's payments have successful checkout transactions
matching the cart total. While it's expected that this validation is completed prior to sending a
ExternalPaymentTransactionCartFinalizationEvent
, this listener double-checks the validity
of the cart finalization attempt.- Author:
- Dima Myroniuk (dmyroniuk)
-
Constructor Summary
ConstructorsConstructorDescriptionExternalPaymentTransactionCartFinalizationListener
(com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentMessageService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, CartProvider cartProvider, PaymentProvider<PaymentSummary> paymentProvider, CheckoutWorkflow checkoutWorkflow, CheckoutService checkoutService, CartOperationCheckoutProperties checkoutProperties) -
Method Summary
Modifier and TypeMethodDescriptionprotected CheckoutProcessDto
buildCheckoutProcessDto
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String checkoutRequestId, @NonNull List<PaymentSummary> cartPayments, @NonNull Map<String, String> paymentLockTokens) protected com.broadleafcommerce.data.tracking.core.context.ContextInfo
buildContextInfoForUpdate
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfoForRead) Builds aContextInfo
object forOperationType.UPDATE
protected com.broadleafcommerce.data.tracking.core.context.ContextInfo
buildUpdateContextInfoFromCart
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart) Builds aContextInfo
withOperationType.UPDATE
from the givenCart
.protected void
finalizeCart
(@NonNull CheckoutProcessDto processDto, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finalizes the cart for checkout.protected String
getApplicationIdFromContext
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected CartProvider
protected CartOperationCheckoutProperties
protected CheckoutService
protected String
getCheckoutTransactionType
(@NonNull PaymentSummary paymentSummary, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Based on the providedPaymentSummary
, determine whichTransactionType
should be used to execute the payment stage of the checkout.protected CheckoutWorkflow
protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService
protected String
getLatestCheckoutRequestId
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart) Gets the latest checkout request id for the givenCart
.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<ExternalPaymentTransactionCartFinalizationEvent> message) protected boolean
paymentAmountsMatchCartTotal
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull List<PaymentSummary> cartPayments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if all the payments for the givenCart
add up to cart's total.protected void
process
(@NonNull org.springframework.messaging.Message<ExternalPaymentTransactionCartFinalizationEvent> message) protected void
processCart
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates that the cart's payments have successful checkout transactions that match the cart total.protected void
unlockPayments
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull Map<String, String> paymentLockTokens, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Sends a request to PaymentTransactionServices to unlock the cart's payments, based on the lock tokens that were previously obtained viaPaymentProvider.lockAndRetrieveCartPayments(Cart, ContextInfo)
.
-
Constructor Details
-
ExternalPaymentTransactionCartFinalizationListener
public ExternalPaymentTransactionCartFinalizationListener(com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentMessageService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, CartProvider cartProvider, PaymentProvider<PaymentSummary> paymentProvider, CheckoutWorkflow checkoutWorkflow, CheckoutService checkoutService, CartOperationCheckoutProperties checkoutProperties)
-
-
Method Details
-
listen
@StreamListener("externalPaymentTransactionCartFinalizationInput") public void listen(org.springframework.messaging.Message<ExternalPaymentTransactionCartFinalizationEvent> message) -
process
protected void process(@NonNull @NonNull org.springframework.messaging.Message<ExternalPaymentTransactionCartFinalizationEvent> message) -
processCart
protected void processCart(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates that the cart's payments have successful checkout transactions that match the cart total. If so, attempts to finalize the cart.- Parameters:
cart
- theCart
that is to be finalizedcontextInfo
- context information related to multitenancy.
-
buildCheckoutProcessDto
protected CheckoutProcessDto buildCheckoutProcessDto(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String checkoutRequestId, @NonNull @NonNull List<PaymentSummary> cartPayments, @NonNull @NonNull Map<String, String> paymentLockTokens) -
finalizeCart
protected void finalizeCart(@NonNull @NonNull CheckoutProcessDto processDto, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finalizes the cart for checkout.- Parameters:
processDto
- theCheckoutProcessDto
to finalizecontextInfo
- context information around sandbox and multitenant state
-
paymentAmountsMatchCartTotal
protected boolean paymentAmountsMatchCartTotal(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull List<PaymentSummary> cartPayments, @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 againstcartPayments
- thePaymentSummaries
owned by the cartcontextInfo
- 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
protected String getCheckoutTransactionType(@NonNull @NonNull PaymentSummary paymentSummary, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Based on the providedPaymentSummary
, determine whichTransactionType
should be used to execute the payment stage of the checkout.- Parameters:
paymentSummary
- One of the cart's payment summaries- Returns:
- The desired transaction type for the gateway
-
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) -
getLatestCheckoutRequestId
protected String getLatestCheckoutRequestId(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart) Gets the latest checkout request id for the givenCart
.- Parameters:
cart
- theCart
to get the latest checkout request id from- Returns:
- the latest checkout request id for the given
Cart
-
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
-
buildContextInfoForUpdate
@Nullable protected com.broadleafcommerce.data.tracking.core.context.ContextInfo buildContextInfoForUpdate(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfoForRead) Builds aContextInfo
object forOperationType.UPDATE
- Parameters:
contextInfoForRead
- theContextInfo
withOperationType.READ
to build from- Returns:
- a
ContextInfo
object forOperationType.UPDATE
-
unlockPayments
protected void unlockPayments(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull Map<String, String> paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Sends a request to PaymentTransactionServices to unlock the cart's payments, based on the lock tokens that were previously obtained viaPaymentProvider.lockAndRetrieveCartPayments(Cart, ContextInfo)
.- Parameters:
cart
- The cart that owns the locked paymentspaymentLockTokens
- The payment lock tokens that were obtained fromPaymentProvider.lockAndRetrieveCartPayments(Cart, ContextInfo)
contextInfo
- The context of the user's request
-
getIdempotentMessageService
protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService getIdempotentMessageService() -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getCartProvider
-
getPaymentProvider
-
getCheckoutWorkflow
-
getCheckoutService
-
getCheckoutProperties
-