Class DefaultPaymentTransactionExecutionService
- java.lang.Object
-
- com.broadleafcommerce.cartoperation.service.payment.DefaultPaymentTransactionExecutionService
-
- All Implemented Interfaces:
PaymentTransactionExecutionService
public class DefaultPaymentTransactionExecutionService extends Object implements PaymentTransactionExecutionService
This service is meant to coordinate the execution of payment transactions against the cart'sPaymentSummaries
in the context of a checkout submission.- Author:
- Chris Kittrell (ckittrell)
-
-
Constructor Summary
Constructors Constructor Description DefaultPaymentTransactionExecutionService(PaymentTransactionExecutionProvider transactionExecutionProvider, PaymentProvider<PaymentSummary> paymentProvider, CartOperationCheckoutProperties properties, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected TransactionExecutionRequest
buildTransactionExecutionRequest(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull PaymentSummary paymentSummary, @NonNull String requestId, String securityCode)
Builds aTransactionExecutionRequest
to execute a transaction against the providedPaymentSummary
.protected List<PaymentTransactionFailureDetail>
buildTransactionFailureDetails(@NonNull TransactionExecutionResponse response)
Builds a list ofPaymentTransactionFailureDetails
based on theTransactionExecutionResponse
that was returned from PaymentTransactionServices.com.broadleafcommerce.cart.client.domain.Cart
executeCartPaymentTransactions(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String requestId, @NonNull Map<String,String> paymentLockTokens, @NonNull Map<String,String> securityCodes, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Executes set of payment transactions against the cart'sPaymentSummaries
.protected com.broadleafcommerce.cart.client.domain.Cart
executePaymentTransaction(@NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull String requestId, @NonNull PaymentSummary paymentSummary, @NonNull String checkoutTransactionType, String lockToken, String securityCode, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Executes a payment transaction against the providedPaymentSummary
.protected String
getApplicationIdFromContext(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected String
getCheckoutTransactionType(@NonNull String gatewayType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Based on the providedPaymentGatewayType
, determine whichTransactionType
should be used to execute the payment stage of the checkout.protected PaymentProvider<PaymentSummary>
getPaymentProvider()
protected CartOperationCheckoutProperties
getProperties()
protected String
getTenantIdFromContext(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
protected PaymentTransactionExecutionProvider
getTransactionExecutionProvider()
protected com.broadleafcommerce.common.extension.TypeFactory
getTypeFactory()
protected boolean
shouldExecutePaymentTransaction(PaymentSummary paymentSummary, String checkoutTransactionType)
Determine whether to execute a transaction for this payment.protected List<PaymentSummary>
sortPayments(List<PaymentSummary> payments)
Hook used to order the cart's payments to produce the most favorable conditions when executing transactions against the payment.
-
-
-
Constructor Detail
-
DefaultPaymentTransactionExecutionService
public DefaultPaymentTransactionExecutionService(PaymentTransactionExecutionProvider transactionExecutionProvider, PaymentProvider<PaymentSummary> paymentProvider, CartOperationCheckoutProperties properties, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Detail
-
executeCartPaymentTransactions
public com.broadleafcommerce.cart.client.domain.Cart executeCartPaymentTransactions(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String requestId, @NonNull @NonNull Map<String,String> paymentLockTokens, @NonNull @NonNull Map<String,String> securityCodes, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Description copied from interface:PaymentTransactionExecutionService
Executes set of payment transactions against the cart'sPaymentSummaries
.- Specified by:
executeCartPaymentTransactions
in interfacePaymentTransactionExecutionService
- Parameters:
cart
- The cart that is being checked out & that owns the relatedPaymentSummary
.requestId
- The id representing this request to checkout.paymentLockTokens
- Tokens that grant this service access to act upon the payment. The presence of these tokens indicates that this execution flow owns the lock.securityCodes
- The map of card security codes keyed by payment id for processing saved paymentscontextInfo
- The context of the user's request.- Returns:
- The most up-to-date cart following the execution of the transaction
-
sortPayments
protected List<PaymentSummary> sortPayments(List<PaymentSummary> payments)
Hook used to order the cart's payments to produce the most favorable conditions when executing transactions against the payment. This is primarily meant to help mitigate the challenges of multi-payment scenarios. For example, if you have a payment method whose transactions are very challenging to roll back (in the case of a checkout failure), then it's best to order that payment last. If thePaymentTransactionExecutionActivity
is the last activity in the workflow and the payment with the challenging rollback is processed last, then the rollback will actually never occur. Instead, either this payment's transaction will pass and the checkout completes, or the transaction fails and only previously completed work may need to be rolled back.- Parameters:
payments
- The un-ordered list of cart payments- Returns:
- The sorted list of cart payments
-
getCheckoutTransactionType
protected String getCheckoutTransactionType(@NonNull @NonNull String gatewayType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Based on the providedPaymentGatewayType
, determine whichTransactionType
should be used to execute the payment stage of the checkout.- Parameters:
gatewayType
- The payment gateway's unique identifier that should be used to lookup the desired transaction type- 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)
-
shouldExecutePaymentTransaction
protected boolean shouldExecutePaymentTransaction(PaymentSummary paymentSummary, String checkoutTransactionType)
Determine whether to execute a transaction for this payment.- Parameters:
paymentSummary
- the payment summary to be evaluated- Returns:
- true if a transaction should be executed against this payment, false otherwise
-
executePaymentTransaction
protected com.broadleafcommerce.cart.client.domain.Cart executePaymentTransaction(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull String requestId, @NonNull @NonNull PaymentSummary paymentSummary, @NonNull @NonNull String checkoutTransactionType, @Nullable String lockToken, @Nullable String securityCode, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Executes a payment transaction against the providedPaymentSummary
.- Parameters:
cart
- The cart that is being checked out & that owns the relatedPaymentSummary
.requestId
- The id representing this request to checkout.paymentSummary
- ThePaymentSummary
of the payment that will be acted upon by the transaction.checkoutTransactionType
- The type of transaction that is to be executed.securityCode
- The payment method security code that may be required to execute the transaction.contextInfo
- The context of the user's request.- Returns:
- The most up-to-date cart following the execution of the transaction
- Throws:
PaymentTransactionFailureException
- if the transaction was not successfully executed, either due to a transaction failure or an unexpected exception.
-
buildTransactionExecutionRequest
protected TransactionExecutionRequest buildTransactionExecutionRequest(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull PaymentSummary paymentSummary, @NonNull @NonNull String requestId, @Nullable String securityCode)
Builds aTransactionExecutionRequest
to execute a transaction against the providedPaymentSummary
.- Parameters:
cart
- The cart that is being checked out & that owns the relatedPaymentSummary
.paymentSummary
- ThePaymentSummary
of the payment that will be acted upon by executing a transaction.requestId
- The id representing this request to checkout.securityCode
- The payment method security code that may be required to execute the transaction.- Returns:
- A
TransactionExecutionRequest
based on the providedPaymentSummary
.
-
buildTransactionFailureDetails
protected List<PaymentTransactionFailureDetail> buildTransactionFailureDetails(@NonNull @NonNull TransactionExecutionResponse response)
Builds a list ofPaymentTransactionFailureDetails
based on theTransactionExecutionResponse
that was returned from PaymentTransactionServices.- Parameters:
response
- TheTransactionExecutionResponse
returned from PaymentTransaction from PaymentTransactionServices.- Returns:
- a list of
PaymentTransactionFailureDetails
based on theTransactionExecutionResponse
that was returned from PaymentTransactionServices.
-
getTransactionExecutionProvider
protected PaymentTransactionExecutionProvider getTransactionExecutionProvider()
-
getPaymentProvider
protected PaymentProvider<PaymentSummary> getPaymentProvider()
-
getProperties
protected CartOperationCheckoutProperties getProperties()
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-
-