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

    Constructors
    Constructor
    Description
    DefaultPaymentTransactionService(PaymentTransactionRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    buildChildPaymentTransactionForResponse(@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
     
    claimTransactionsForRequest(@NonNull Payment payment, @NonNull String requestId, @NonNull String expectedTransactionType, boolean resetTransactionReversalState, String lockToken, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    protected String
    determineTransactionStatus(T transaction, @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse response)
    Determines the new status of the PaymentTransaction based on the contents of the PaymentResponse
     
     
    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 given PaymentTransaction based on the given PaymentResponse and persists the PaymentTransaction.
    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
     
    void
     
    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 given PaymentTransaction based on the given PaymentResponse

    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 interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<T extends PaymentTransaction>
      Overrides:
      updateSort in class com.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 interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<T extends PaymentTransaction>
      Overrides:
      replace in class com.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 interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<T extends PaymentTransaction>
      Overrides:
      replaceAll in class com.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 interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<T extends PaymentTransaction>
      Overrides:
      replaceAllAllowingPartialSuccess in class com.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 interface PaymentTransactionService<T extends PaymentTransaction>
      Parameters:
      contextIds - the ids of the transactions
      managementStates - the management states of the transactions
      context - 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 interface PaymentTransactionService<T extends PaymentTransaction>
      Parameters:
      managementStates - the management states of the transactions
      page - 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 interface PaymentTransactionService<T extends PaymentTransaction>
      Parameters:
      managementStates - the management states of the transactions
      transactionStatuses - the statuses of the transactions
      page - 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 interface PaymentTransactionService<T extends PaymentTransaction>
      Parameters:
      date - the date until which the transaction was recorded
      managementStates - the management states to avoid
      page - 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 interface PaymentTransactionService<T extends PaymentTransaction>
      Parameters:
      transactionReferenceId - the transaction id known by the payment gateway
      context - 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 interface PaymentTransactionService<T extends PaymentTransaction>
      Parameters:
      transactionReferenceId - the transaction id known by the payment gateway
      context - 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 interface PaymentTransactionService<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 interface PaymentTransactionService<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 given PaymentTransaction based on the given PaymentResponse and persists the PaymentTransaction.
      Specified by:
      recordTransactionResponse in interface PaymentTransactionService<T extends PaymentTransaction>
      Parameters:
      transaction - the PaymentTransaction to update and persist
      response - the PaymentResponse to get the data from
      saveResult - save updated transaction if true
      contextInfo - 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 with DefaultTransactionManagementStates.REVERSAL_CANDIDATE management state, DefaultTransactionStatuses.SUCCESS status and that have not been updated within a specified duration.
      Specified by:
      readTransactionsToReverse in interface PaymentTransactionService<T extends PaymentTransaction>
      Parameters:
      reversalCandidateTtl - the amount of time the payment transactions have not been updated and can be reversed
      page - The requested page of results from the database
      context - 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
      Specified by:
      claimTransactionsForRequest in interface PaymentTransactionService<T extends PaymentTransaction>
      Parameters:
      payment - the Payment instance
      requestId - id used to represent the request that produced this transaction e.g during checkout
      expectedTransactionType - the transaction type to change
      resetTransactionReversalState - reset or not the state of the transaction reversal
      lockToken - token granted to resource that owns the payment lock
      context - 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 interface PaymentTransactionService<T extends PaymentTransaction>
      Parameters:
      payment - the Payment instance
      parentTransaction - the parent transaction
      paymentResponse - the PaymentResponse to get the data from
      Returns:
      the new child PaymentTransaction for the specified payment and parent transaction
    • buildPaymentRef

      protected PaymentRef buildPaymentRef(Payment payment)
    • updateTransactionBasedOnResponse

      public T updateTransactionBasedOnResponse(@NonNull T transaction, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse response)
      Updates the given PaymentTransaction based on the given PaymentResponse
      Specified by:
      updateTransactionBasedOnResponse in interface PaymentTransactionService<T extends PaymentTransaction>
      Parameters:
      transaction - the PaymentTransaction to update
      response - the PaymentResponse to get the data from
      Returns:
      the updated PaymentTransaction based on the given PaymentResponse
    • determineTransactionStatus

      protected String determineTransactionStatus(@NonNull T transaction, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse response)
      Determines the new status of the PaymentTransaction based on the contents of the PaymentResponse

      If the PaymentTransaction being updated is an DefaultTransactionTypes.AUTHORIZE_AND_CAPTURE, this would determine the status based on the PaymentResponse.getTransactionType(). If PaymentResponse.getTransactionType() is DefaultTransactionTypes.AUTHORIZE, the status should be DefaultTransactionStatuses.AWAITING_ASYNC_RESULTS, as certain payment gateways communicate the DefaultTransactionTypes.CAPTURE portion of the DefaultTransactionTypes.AUTHORIZE_AND_CAPTURE asynchronously.

      Parameters:
      transaction - the PaymentTransaction being updated
      response - the payment gateway's response to the executed transaction
      Returns:
      the new status of the PaymentTransaction based on the contents of the PaymentResponse
    • 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 class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<T extends PaymentTransaction>
    • setPaymentLockService

      @Autowired public void setPaymentLockService(PaymentLockService<Payment> paymentLockService)
    • getPaymentLockService

      protected PaymentLockService<Payment> getPaymentLockService()
    • setPaymentService

      @Autowired public void setPaymentService(PaymentService<Payment> paymentService)
    • getPaymentService

      protected PaymentService<Payment> getPaymentService()
    • setTypeFactory

      @Autowired public void setTypeFactory(@Nullable com.broadleafcommerce.common.extension.TypeFactory typeFactory)