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
ConstructorDescriptionDefaultPaymentTransactionService
(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 PaymentRef
buildPaymentRef
(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 String
determineTransactionStatus
(T transaction, @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse response) Determines the new status of thePaymentTransaction
based on the contents of thePaymentResponse
protected PaymentLockService<Payment>
protected PaymentService<Payment>
protected PaymentTransactionRepository<com.broadleafcommerce.data.tracking.core.Trackable>
protected boolean
isIndeterminateResult
(@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 givenPaymentTransaction
based on the givenPaymentResponse
and 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) void
setPaymentLockService
(PaymentLockService<Payment> paymentLockService) void
setPaymentService
(PaymentService<Payment> paymentService) void
setTypeFactory
(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 givenPaymentTransaction
based on the givenPaymentResponse
Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService
getRsqlHelper, readAll, readAll, readAll, readAll
Methods 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, updateAllAllowingPartialSuccess
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService
create, createAll, createAllAllowingPartialSuccess, delete, readAll, readAll, readAll, readAllByContextId, readByContextId, update, updateAll, updateAllAllowingPartialSuccess
Methods inherited from interface com.broadleafcommerce.paymenttransaction.service.PaymentTransactionService
recordTransactionResponse
Methods 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:
updateSort
in interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<T extends PaymentTransaction>
- Overrides:
updateSort
in 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:
replace
in interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<T extends PaymentTransaction>
- Overrides:
replace
in 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:
replaceAll
in interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<T extends PaymentTransaction>
- Overrides:
replaceAll
in 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:
replaceAllAllowingPartialSuccess
in interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<T extends PaymentTransaction>
- Overrides:
replaceAllAllowingPartialSuccess
in 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:PaymentTransactionService
Returns the transactions with the specified ids and management states.- Specified by:
readAllByContextIdInAndManagementStateIn
in 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:PaymentTransactionService
Returns the transactions with the specified management states.- Specified by:
readAllByManagementStateIn
in 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:PaymentTransactionService
Returns the transactions with the specified management states and transaction statuses.- Specified by:
readAllByManagementStateInAndStatusIn
in 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:PaymentTransactionService
Returns the transactions with the recorded date before the specified time and management statuses not in the specified list.- Specified by:
readAllByDateRecordedBeforeAndManagementStateIsNotIn
in 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:PaymentTransactionService
Returns the transactions with the specified transaction reference id.- Specified by:
readByTransactionReferenceId
in 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:PaymentTransactionService
Returns the transaction with the specified transaction reference id, ignoring other context filtering like archival status.- Specified by:
readByTransactionReferenceIdAndTenantId
in 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:PaymentTransactionService
Returns transaction identified by the gateway transaction id.- Specified by:
readByGatewayTransactionId
in 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:PaymentTransactionService
Returns the transaction identified by the gateway transaction id, ignoring other context filtering like archival status.- Specified by:
readByGatewayTransactionIdAndTenantId
in 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:PaymentTransactionService
Updates the givenPaymentTransaction
based on the givenPaymentResponse
and persists thePaymentTransaction
.- Specified by:
recordTransactionResponse
in interfacePaymentTransactionService<T extends PaymentTransaction>
- Parameters:
transaction
- thePaymentTransaction
to update and persistresponse
- thePaymentResponse
to 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:PaymentTransactionService
Reads the payment transactions that are eligible for reversal. By default, this method returns the transaction withDefaultTransactionManagementStates.REVERSAL_CANDIDATE
management state,DefaultTransactionStatuses.SUCCESS
status and that have not been updated within a specified duration.- Specified by:
readTransactionsToReverse
in 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:PaymentTransactionService
Updates thePaymentTransaction.getRequestId()
with the new value, stores the previous value toPaymentTransaction.getPreviousRequestIds()
, clearsPaymentTransaction.getManagementState()
andPaymentTransaction.getManagementStateReason()
.- Specified by:
claimTransactionsForRequest
in interfacePaymentTransactionService<T extends PaymentTransaction>
- Parameters:
payment
- thePayment
instancerequestId
- 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
Payment
record
-
buildChildPaymentTransactionForResponse
public T buildChildPaymentTransactionForResponse(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction parentTransaction, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse) Description copied from interface:PaymentTransactionService
Creates 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:
buildChildPaymentTransactionForResponse
in interfacePaymentTransactionService<T extends PaymentTransaction>
- Parameters:
payment
- thePayment
instanceparentTransaction
- the parent transactionpaymentResponse
- thePaymentResponse
to get the data from- Returns:
- the new child
PaymentTransaction
for the specified payment and parent transaction
-
buildPaymentRef
-
updateTransactionBasedOnResponse
public T updateTransactionBasedOnResponse(@NonNull T transaction, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse response) Updates the givenPaymentTransaction
based on the givenPaymentResponse
- Specified by:
updateTransactionBasedOnResponse
in interfacePaymentTransactionService<T extends PaymentTransaction>
- Parameters:
transaction
- thePaymentTransaction
to updateresponse
- thePaymentResponse
to get the data from- Returns:
- the updated
PaymentTransaction
based on the givenPaymentResponse
-
determineTransactionStatus
protected String determineTransactionStatus(@NonNull T transaction, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse response) Determines the new status of thePaymentTransaction
based on the contents of thePaymentResponse
If the
PaymentTransaction
being 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.CAPTURE
portion of theDefaultTransactionTypes.AUTHORIZE_AND_CAPTURE
asynchronously.- Parameters:
transaction
- thePaymentTransaction
being updatedresponse
- the payment gateway's response to the executed transaction- Returns:
- the new status of the
PaymentTransaction
based 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:
getRepository
in 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)
-