Class FinalizeCartAwaitingPaymentResultJobListener
Carts
that
have the status of DefaultCartStatuses.AWAITING_PAYMENT_RESULT
.
If all the cart payments have results and match the cart's total, then the cart is finalized. If there's any failed payment for the cart, meaning that cart payments have results but don't match the cart's total, the checkout is rolled back.
- Author:
- Sunny Yu
-
Field Summary
-
Constructor Summary
ConstructorDescriptionFinalizeCartAwaitingPaymentResultJobListener
(com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentMessageService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, ResourceLockProvider resourceLockProvider, CartProvider cartProvider, PaymentProvider<PaymentSummary> paymentProvider, CheckoutWorkflow checkoutWorkflow, CheckoutService checkoutService, CartOperationCheckoutProperties checkoutProperties) -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
allPaymentsHaveResult
(@NonNull List<PaymentSummary> payments) Determines if all the payments have a result from the payment gateway rather than pending.protected com.broadleafcommerce.data.tracking.core.context.ContextInfo
buildContextInfoForRead
(org.springframework.messaging.Message<com.broadleafcommerce.common.messaging.domain.ScheduledJobRef> message) Builds aContextInfo
object forOperationType.READ
.protected com.broadleafcommerce.data.tracking.core.context.ContextInfo
buildContextInfoForUpdate
(@NonNull 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 String
getApplicationIdFromContext
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected int
getBatchSize
(@NonNull com.broadleafcommerce.common.messaging.domain.ScheduledJobRef jobRef) Gets the batch size to use when fetching payment transactions.protected CartProvider
protected CartOperationCheckoutProperties
protected CheckoutService
protected String
getCheckoutTransactionType
(@NonNull String gatewayType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated.protected String
getCheckoutTransactionType
(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 ResourceLockProvider
protected String
getTenantIdFromContext
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected com.broadleafcommerce.common.extension.TypeFactory
void
listen
(org.springframework.messaging.Message<com.broadleafcommerce.common.messaging.domain.ScheduledJobRef> message) protected boolean
paymentsMatchCartTotal
(@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 List<com.broadleafcommerce.cart.client.domain.Cart>
prepareCartsForJob
(@NonNull List<com.broadleafcommerce.cart.client.domain.Cart> carts, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Prepares the givenCarts
before executing the scheduled job.protected void
process
(@NonNull org.springframework.messaging.Message<com.broadleafcommerce.common.messaging.domain.ScheduledJobRef> message) Initiates the scheduled job to finalize cart awaiting payment result based on the provided message.protected boolean
processCart
(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Rolls back or finalizes checkout for the givenCart
based on whether its payments failed or succeeded.protected void
processCarts
(@NonNull List<com.broadleafcommerce.cart.client.domain.Cart> carts, com.broadleafcommerce.data.tracking.core.context.ContextInfo updateContext) Processes the givenCarts
.protected void
resetCartsToPendingPaymentIfNecessary
(@NonNull List<String> cartsToReset, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Resets the givencart ids
back toDefaultCartStatuses.AWAITING_PAYMENT_RESULT
.
-
Field Details
-
FINALIZE_CART_AWAITING_PAYMENT_RESULT_JOB_TYPE
- See Also:
-
BATCH_SIZE_FLD
- See Also:
-
-
Constructor Details
-
FinalizeCartAwaitingPaymentResultJobListener
public FinalizeCartAwaitingPaymentResultJobListener(com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentMessageService, com.broadleafcommerce.common.extension.TypeFactory typeFactory, ResourceLockProvider resourceLockProvider, CartProvider cartProvider, PaymentProvider<PaymentSummary> paymentProvider, CheckoutWorkflow checkoutWorkflow, CheckoutService checkoutService, CartOperationCheckoutProperties checkoutProperties)
-
-
Method Details
-
listen
@StreamListener("triggeredJobEventInputFinalizeCartAwaitingPaymentResult") public void listen(org.springframework.messaging.Message<com.broadleafcommerce.common.messaging.domain.ScheduledJobRef> message) -
process
protected void process(@NonNull @NonNull org.springframework.messaging.Message<com.broadleafcommerce.common.messaging.domain.ScheduledJobRef> message) Initiates the scheduled job to finalize cart awaiting payment result based on the provided message.- Parameters:
message
- theMessage
containing the scheduled job detail
-
processCarts
protected void processCarts(@NonNull @NonNull List<com.broadleafcommerce.cart.client.domain.Cart> carts, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo updateContext) Processes the givenCarts
.- Parameters:
carts
- theCarts
to processupdateContext
- theContextInfo
withOperationType.UPDATE
-
prepareCartsForJob
protected List<com.broadleafcommerce.cart.client.domain.Cart> prepareCartsForJob(@NonNull @NonNull List<com.broadleafcommerce.cart.client.domain.Cart> carts, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Prepares the givenCarts
before executing the scheduled job. By default, it simply sets the status toDefaultCartStatuses.PAYMENT_RESULT_CHECK_IN_PROGRESS
.- Parameters:
carts
- theCarts
to prepare for the scheduled jobcontextInfo
- context information around sandbox and multitenant state- Returns:
- the updated
Carts
-
processCart
protected boolean processCart(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Rolls back or finalizes checkout for the givenCart
based on whether its payments failed or succeeded. If the payments for the givenCart
is still awaiting result, this would returnfalse
.- Parameters:
cart
- theCart
to roll back or finalize checkout forcontextInfo
- context information around sandbox and multitenant state- Returns:
- Whether the cart was successfully processed
-
getBatchSize
protected int getBatchSize(@NonNull @NonNull com.broadleafcommerce.common.messaging.domain.ScheduledJobRef jobRef) Gets the batch size to use when fetching payment transactions. Defaults to 10.We want a generally small batch size because it will take time to process finalizing carts awaiting payment result. If the batch size is too large, then the time between gathering carts & their relevant payments will be long enough to potentially make the payments & out-of-date by the time that we attempt to process them.
- Parameters:
jobRef
- theScheduledJobRef
containing the scheduled job details- Returns:
- the batch size to use when fetching carts
-
paymentsMatchCartTotal
protected boolean paymentsMatchCartTotal(@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
-
allPaymentsHaveResult
Determines if all the payments have a result from the payment gateway rather than pending.- Parameters:
payments
- thePaymentSummaries
to check- Returns:
- true if all the payments have a result, otherwise false
-
resetCartsToPendingPaymentIfNecessary
protected void resetCartsToPendingPaymentIfNecessary(@NonNull @NonNull List<String> cartsToReset, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Resets the givencart ids
back toDefaultCartStatuses.AWAITING_PAYMENT_RESULT
.This is useful when the one or more payments is still pending for the cart by the time the job is executed, or exception is thrown when finalizing or rolling back the cart.
- Parameters:
cartsToReset
-cart ids
that should be reset toDefaultCartStatuses.AWAITING_PAYMENT_RESULT
contextInfo
- context information around sandbox and multitenant state
-
getCheckoutTransactionType
protected String getCheckoutTransactionType(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
-
getCheckoutTransactionType
protected String getCheckoutTransactionType(@NonNull @NonNull String gatewayType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Deprecated. -
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
-
buildContextInfoForRead
protected com.broadleafcommerce.data.tracking.core.context.ContextInfo buildContextInfoForRead(org.springframework.messaging.Message<com.broadleafcommerce.common.messaging.domain.ScheduledJobRef> message) Builds aContextInfo
object forOperationType.READ
.- Parameters:
message
- Contains scheduled job details about the context- Returns:
- a
ContextInfo
object forOperationType.READ
-
buildContextInfoForUpdate
protected com.broadleafcommerce.data.tracking.core.context.ContextInfo buildContextInfoForUpdate(@NonNull @NonNull 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
-
getIdempotentMessageService
protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService getIdempotentMessageService() -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getResourceLockProvider
-
getCartProvider
-
getPaymentProvider
-
getCheckoutWorkflow
-
getCheckoutService
-
getCheckoutProperties
-
getCheckoutTransactionType(PaymentSummary, ContextInfo)