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 CheckoutProcessDtobuildCheckoutProcessDto(@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.ContextInfobuildContextInfoForUpdate(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfoForRead) Builds aContextInfoobject forOperationType.UPDATEprotected com.broadleafcommerce.data.tracking.core.context.ContextInfobuildUpdateContextInfoFromCart(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart) Builds aContextInfowithOperationType.UPDATEfrom the givenCart.protected voidfinalizeCart(@NonNull CheckoutProcessDto processDto, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finalizes the cart for checkout.protected StringgetApplicationIdFromContext(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected CartProviderprotected CartOperationCheckoutPropertiesprotected CheckoutServiceprotected StringgetCheckoutTransactionType(@NonNull PaymentSummary paymentSummary, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Based on the providedPaymentSummary, determine whichTransactionTypeshould be used to execute the payment stage of the checkout.protected CheckoutWorkflowprotected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionServiceprotected StringgetLatestCheckoutRequestId(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart) Gets the latest checkout request id for the givenCart.protected PaymentProvider<PaymentSummary>protected StringgetTenantIdFromContext(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected com.broadleafcommerce.common.extension.TypeFactoryvoidlisten(org.springframework.messaging.Message<ExternalPaymentTransactionCartFinalizationEvent> message) protected booleanpaymentAmountsMatchCartTotal(@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 givenCartadd up to cart's total.protected voidprocess(@NonNull org.springframework.messaging.Message<ExternalPaymentTransactionCartFinalizationEvent> message) protected voidprocessCart(@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 voidunlockPayments(@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- theCartthat 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- theCheckoutProcessDtoto 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 givenCartadd 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- theCartto check againstcartPayments- thePaymentSummariesowned by the cartcontextInfo- context information around sandbox and multitenant state- Returns:
- true if all the payments for the given
Cartmatch 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 whichTransactionTypeshould 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- theCartto 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 aContextInfowithOperationType.UPDATEfrom the givenCart.This is useful to make requests for
Cartin 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- theCartto build the context info from- Returns:
- a
ContextInfowithOperationType.UPDATEfrom the givenCart
-
buildContextInfoForUpdate
@Nullable protected com.broadleafcommerce.data.tracking.core.context.ContextInfo buildContextInfoForUpdate(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfoForRead) Builds aContextInfoobject forOperationType.UPDATE- Parameters:
contextInfoForRead- theContextInfowithOperationType.READto build from- Returns:
- a
ContextInfoobject 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
-