Class DefaultPaymentTransactionService<T extends PaymentTransaction>
java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<T>
com.broadleafcommerce.paymenttransaction.service.DefaultPaymentTransactionService<T>
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.service.CrudEntityService<T>,com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<T>,PaymentTransactionService<T>
public class DefaultPaymentTransactionService<T extends PaymentTransaction>
extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<T>
implements PaymentTransactionService<T>
- Author:
- Chris Kittrell (ckittrell)
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultPaymentTransactionService(PaymentTransactionRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper) -
Method Summary
Modifier and TypeMethodDescriptionbuildChildPaymentTransactionForResponse(@NonNull Payment payment, @NonNull PaymentTransaction parentTransaction, @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse) Creates the new child payment transaction for the specified parent transaction based on the payment response.protected PaymentRefbuildPaymentRef(Payment payment) claimTransactionsForRequest(@NonNull Payment payment, @NonNull String requestId, @NonNull String expectedTransactionType, boolean resetTransactionReversalState, String lockToken, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Updates thePaymentTransaction.getRequestId()with the new value, stores the previous value toPaymentTransaction.getPreviousRequestIds(), clearsPaymentTransaction.getManagementState()andPaymentTransaction.getManagementStateReason().protected StringdetermineTransactionStatus(T transaction, @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse response) Determines the new status of thePaymentTransactionbased on the contents of thePaymentResponseprotected PaymentLockService<Payment>protected PaymentService<Payment>protected PaymentTransactionRepository<com.broadleafcommerce.data.tracking.core.Trackable>protected StringgetTransactionType(PaymentTransaction parentTransaction, com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse) protected booleanisIndeterminateResult(@NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse response) Determines whether or not the payment response represents an indeterminate result.readAllByContextIdInAndManagementStateIn(List<String> contextIds, List<String> managementStates, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Returns the transactions with the specified ids and management states.org.springframework.data.domain.Page<T>readAllByDateRecordedBeforeAndManagementStateIsNotIn(Instant date, List<String> managementStates, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Returns the transactions with the recorded date before the specified time and management statuses not in the specified list.org.springframework.data.domain.Page<T>readAllByManagementStateIn(List<String> managementStates, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Returns the transactions with the specified management states.org.springframework.data.domain.Page<T>readAllByManagementStateInAndStatusIn(List<String> managementStates, List<String> transactionStatuses, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Returns the transactions with the specified management states and transaction statuses.readByGatewayTransactionId(String gatewayTransactionId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Returns transaction identified by the gateway transaction id.readByGatewayTransactionIdAndTenantId(String gatewayTransactionId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Returns the transaction identified by the gateway transaction id, ignoring other context filtering like archival status.readByTransactionReferenceId(String transactionReferenceId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Returns the transactions with the specified transaction reference id.readByTransactionReferenceIdAndTenantId(String transactionReferenceId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Returns the transaction with the specified transaction reference id, ignoring other context filtering like archival status.org.springframework.data.domain.Page<T>readTransactionsToReverse(Duration reversalCandidateTtl, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Reads the payment transactions that are eligible for reversal.recordTransactionResponse(T transaction, @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse response, boolean saveResult, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Updates the givenPaymentTransactionbased on the givenPaymentResponseand persists thePaymentTransaction.replace(String id, T businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) replaceAll(List<com.broadleafcommerce.data.tracking.core.service.Update<T>> replacements, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<T>replaceAllAllowingPartialSuccess(List<com.broadleafcommerce.data.tracking.core.service.Update<T>> replacements, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) voidsetPaymentLockService(PaymentLockService<Payment> paymentLockService) voidsetPaymentService(PaymentService<Payment> paymentService) voidsetTypeFactory(com.broadleafcommerce.common.extension.TypeFactory typeFactory) updateSort(com.broadleafcommerce.data.tracking.core.sort.SortPositionRequest sortPositionRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) updateTransactionBasedOnResponse(T transaction, @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse response) Updates the givenPaymentTransactionbased on the givenPaymentResponseMethods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService
getRsqlHelper, readAll, readAll, readAll, readAllMethods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService
convertFromPersistentDomain, convertToPersistentDomain, create, createAll, createAllAllowingPartialSuccess, delete, getHelper, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, readByContextId, setSortPositionStrategy, update, updateAll, updateAllAllowingPartialSuccessMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService
create, createAll, createAllAllowingPartialSuccess, delete, readAll, readAll, readAll, readAllByContextId, readByContextId, update, updateAll, updateAllAllowingPartialSuccessMethods inherited from interface com.broadleafcommerce.paymenttransaction.service.PaymentTransactionService
recordTransactionResponseMethods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService
readAll, readAll, readAll, readAll
-
Constructor Details
-
DefaultPaymentTransactionService
public DefaultPaymentTransactionService(PaymentTransactionRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper)
-
-
Method Details
-
updateSort
public T updateSort(com.broadleafcommerce.data.tracking.core.sort.SortPositionRequest sortPositionRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
updateSortin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<T extends PaymentTransaction>- Overrides:
updateSortin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<T extends PaymentTransaction>
-
replace
public T replace(String id, T businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
replacein interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<T extends PaymentTransaction>- Overrides:
replacein classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<T extends PaymentTransaction>
-
replaceAll
public List<T> replaceAll(List<com.broadleafcommerce.data.tracking.core.service.Update<T>> replacements, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
replaceAllin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<T extends PaymentTransaction>- Overrides:
replaceAllin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<T extends PaymentTransaction>
-
replaceAllAllowingPartialSuccess
public com.broadleafcommerce.data.tracking.core.service.BulkPersistenceResponse<T> replaceAllAllowingPartialSuccess(List<com.broadleafcommerce.data.tracking.core.service.Update<T>> replacements, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
replaceAllAllowingPartialSuccessin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<T extends PaymentTransaction>- Overrides:
replaceAllAllowingPartialSuccessin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<T extends PaymentTransaction>
-
readAllByContextIdInAndManagementStateIn
public List<T> readAllByContextIdInAndManagementStateIn(List<String> contextIds, List<String> managementStates, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:PaymentTransactionServiceReturns the transactions with the specified ids and management states.- Specified by:
readAllByContextIdInAndManagementStateInin interfacePaymentTransactionService<T extends PaymentTransaction>- Parameters:
contextIds- the ids of the transactionsmanagementStates- the management states of the transactionscontext- Request context information around sandbox and multitenant state- Returns:
- the transactions with the specified ids and management states
-
readAllByManagementStateIn
public org.springframework.data.domain.Page<T> readAllByManagementStateIn(List<String> managementStates, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:PaymentTransactionServiceReturns the transactions with the specified management states.- Specified by:
readAllByManagementStateInin interfacePaymentTransactionService<T extends PaymentTransaction>- Parameters:
managementStates- the management states of the transactionspage- The requested page of results from the database.context- Request context information around sandbox and multitenant state- Returns:
- the transactions with the specified management states
-
readAllByManagementStateInAndStatusIn
public org.springframework.data.domain.Page<T> readAllByManagementStateInAndStatusIn(List<String> managementStates, List<String> transactionStatuses, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:PaymentTransactionServiceReturns the transactions with the specified management states and transaction statuses.- Specified by:
readAllByManagementStateInAndStatusInin interfacePaymentTransactionService<T extends PaymentTransaction>- Parameters:
managementStates- the management states of the transactionstransactionStatuses- the statuses of the transactionspage- The requested page of results from the database.context- Request context information around sandbox and multitenant state- Returns:
- the transactions with the specified management states and transaction statuses
-
readAllByDateRecordedBeforeAndManagementStateIsNotIn
public org.springframework.data.domain.Page<T> readAllByDateRecordedBeforeAndManagementStateIsNotIn(Instant date, List<String> managementStates, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:PaymentTransactionServiceReturns the transactions with the recorded date before the specified time and management statuses not in the specified list.- Specified by:
readAllByDateRecordedBeforeAndManagementStateIsNotInin interfacePaymentTransactionService<T extends PaymentTransaction>- Parameters:
date- the date until which the transaction was recordedmanagementStates- the management states to avoidpage- The requested page of results from the database.context- Request context information around sandbox and multitenant state- Returns:
- the transactions with the specified management states
-
readByTransactionReferenceId
public T readByTransactionReferenceId(String transactionReferenceId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:PaymentTransactionServiceReturns the transactions with the specified transaction reference id.- Specified by:
readByTransactionReferenceIdin interfacePaymentTransactionService<T extends PaymentTransaction>- Parameters:
transactionReferenceId- the transaction id known by the payment gatewaycontext- Request context information around sandbox and multitenant state- Returns:
- the transactions with the specified transaction reference id
-
readByTransactionReferenceIdAndTenantId
public T readByTransactionReferenceIdAndTenantId(String transactionReferenceId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:PaymentTransactionServiceReturns the transaction with the specified transaction reference id, ignoring other context filtering like archival status.- Specified by:
readByTransactionReferenceIdAndTenantIdin interfacePaymentTransactionService<T extends PaymentTransaction>- Parameters:
transactionReferenceId- the transaction id known by the payment gatewaycontext- Request context information around sandbox and multitenant state- Returns:
- the transaction with the specified transaction reference id
-
readByGatewayTransactionId
public T readByGatewayTransactionId(String gatewayTransactionId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:PaymentTransactionServiceReturns transaction identified by the gateway transaction id.- Specified by:
readByGatewayTransactionIdin interfacePaymentTransactionService<T extends PaymentTransaction>- Parameters:
gatewayTransactionId- The id of the payment gateway's transaction representation.context- Request context information around sandbox and multitenant state- Returns:
- Transaction with the specified gateway transaction id.
-
readByGatewayTransactionIdAndTenantId
public T readByGatewayTransactionIdAndTenantId(String gatewayTransactionId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:PaymentTransactionServiceReturns the transaction identified by the gateway transaction id, ignoring other context filtering like archival status.- Specified by:
readByGatewayTransactionIdAndTenantIdin interfacePaymentTransactionService<T extends PaymentTransaction>- Parameters:
gatewayTransactionId- The id of the payment gateway's transaction representation.context- Request context information around sandbox and multitenant state- Returns:
- Transaction with the specified gateway transaction id.
-
recordTransactionResponse
public T recordTransactionResponse(@NonNull T transaction, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse response, boolean saveResult, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:PaymentTransactionServiceUpdates the givenPaymentTransactionbased on the givenPaymentResponseand persists thePaymentTransaction.- Specified by:
recordTransactionResponsein interfacePaymentTransactionService<T extends PaymentTransaction>- Parameters:
transaction- thePaymentTransactionto update and persistresponse- thePaymentResponseto get the data fromsaveResult- save updated transaction if truecontextInfo- context information related to multitenancy- Returns:
- updated and persisted
PaymentTransaction
-
readTransactionsToReverse
public org.springframework.data.domain.Page<T> readTransactionsToReverse(Duration reversalCandidateTtl, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:PaymentTransactionServiceReads the payment transactions that are eligible for reversal. By default, this method returns the transaction withDefaultTransactionManagementStates.REVERSAL_CANDIDATEmanagement state,DefaultTransactionStatuses.SUCCESSstatus and that have not been updated within a specified duration.- Specified by:
readTransactionsToReversein interfacePaymentTransactionService<T extends PaymentTransaction>- Parameters:
reversalCandidateTtl- the amount of time the payment transactions have not been updated and can be reversedpage- The requested page of results from the databasecontext- context information related to multitenancy- Returns:
- the payment transactions that are eligible for reversal
- See Also:
-
claimTransactionsForRequest
public Payment claimTransactionsForRequest(@NonNull @NonNull Payment payment, @NonNull @NonNull String requestId, @NonNull @NonNull String expectedTransactionType, boolean resetTransactionReversalState, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:PaymentTransactionServiceUpdates thePaymentTransaction.getRequestId()with the new value, stores the previous value toPaymentTransaction.getPreviousRequestIds(), clearsPaymentTransaction.getManagementState()andPaymentTransaction.getManagementStateReason().- Specified by:
claimTransactionsForRequestin interfacePaymentTransactionService<T extends PaymentTransaction>- Parameters:
payment- thePaymentinstancerequestId- id used to represent the request that produced this transaction e.g during checkoutexpectedTransactionType- the transaction type to changeresetTransactionReversalState- reset or not the state of the transaction reversallockToken- token granted to resource that owns the payment lockcontext- context information related to multitenancy- Returns:
- The up-to-date
Paymentrecord
-
buildChildPaymentTransactionForResponse
public T buildChildPaymentTransactionForResponse(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction parentTransaction, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse) Description copied from interface:PaymentTransactionServiceCreates the new child payment transaction for the specified parent transaction based on the payment response. By default this method doesn't store the created transaction.- Specified by:
buildChildPaymentTransactionForResponsein interfacePaymentTransactionService<T extends PaymentTransaction>- Parameters:
payment- thePaymentinstanceparentTransaction- the parent transactionpaymentResponse- thePaymentResponseto get the data from- Returns:
- the new child
PaymentTransactionfor the specified payment and parent transaction
-
getTransactionType
protected String getTransactionType(PaymentTransaction parentTransaction, com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse) -
buildPaymentRef
-
updateTransactionBasedOnResponse
public T updateTransactionBasedOnResponse(@NonNull T transaction, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse response) Updates the givenPaymentTransactionbased on the givenPaymentResponse- Specified by:
updateTransactionBasedOnResponsein interfacePaymentTransactionService<T extends PaymentTransaction>- Parameters:
transaction- thePaymentTransactionto updateresponse- thePaymentResponseto get the data from- Returns:
- the updated
PaymentTransactionbased on the givenPaymentResponse
-
determineTransactionStatus
protected String determineTransactionStatus(@NonNull T transaction, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse response) Determines the new status of thePaymentTransactionbased on the contents of thePaymentResponseIf the
PaymentTransactionbeing updated is anDefaultTransactionTypes.AUTHORIZE_AND_CAPTURE, this would determine the status based on thePaymentResponse.getTransactionType(). IfPaymentResponse.getTransactionType()isDefaultTransactionTypes.AUTHORIZE, the status should beDefaultTransactionStatuses.AWAITING_ASYNC_RESULTS, as certain payment gateways communicate theDefaultTransactionTypes.CAPTUREportion of theDefaultTransactionTypes.AUTHORIZE_AND_CAPTUREasynchronously.- Parameters:
transaction- thePaymentTransactionbeing updatedresponse- the payment gateway's response to the executed transaction- Returns:
- the new status of the
PaymentTransactionbased on the contents of thePaymentResponse
-
isIndeterminateResult
protected boolean isIndeterminateResult(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse response) Determines whether or not the payment response represents an indeterminate result.For example, if a network error occurred, it we won't know if the transaction was completed or not on the gateway side of things.
- Parameters:
response- the payment gateway's response to the executed transaction- Returns:
- whether the response yielded an indeterminate payment response or not
-
getRepository
@NonNull protected PaymentTransactionRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository()- Overrides:
getRepositoryin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<T extends PaymentTransaction>
-
setPaymentLockService
-
getPaymentLockService
-
setPaymentService
-
getPaymentService
-
setTypeFactory
@Autowired public void setTypeFactory(@Nullable com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-