Class PaymentTransactionReversalJobListener

java.lang.Object
com.broadleafcommerce.paymenttransaction.service.messaging.reversals.PaymentTransactionReversalJobListener

@DataRouteByKey("paymentTransaction") public class PaymentTransactionReversalJobListener extends Object
Scheduled Job listener that is responsible for processing PaymentTransaction reversals.
Author:
Chris Kittrell (ckittrell), Dima Myroniuk (dmyroniuk)
  • Field Details

  • Constructor Details

    • PaymentTransactionReversalJobListener

      public PaymentTransactionReversalJobListener(com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentMessageService, com.broadleafcommerce.data.tracking.core.service.scheduledjob.ScheduledJobContextService scheduledJobContextService, PaymentService<Payment> paymentService, PaymentTransactionService<PaymentTransaction> paymentTransactionService, TransactionExecutionService transactionExecutionService)
  • Method Details

    • listen

      @StreamListener("triggeredJobEventInputPaymentTransactionReversal") public void listen(org.springframework.messaging.Message<com.broadleafcommerce.common.messaging.domain.ScheduledJobRef> message)
    • processTransactionReversals

      protected void processTransactionReversals(@NonNull @NonNull org.springframework.messaging.Message<com.broadleafcommerce.common.messaging.domain.ScheduledJobRef> message)
      Responsible for initiating payment transaction reversals based on the provided message.
      Parameters:
      message - Contains the scheduled job detail
    • 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. Note: We want a generally small batch size because it will take time to process reversal transactions. If the batch size is too large, then the time between gathering transactions & their relevant payments will be long enough to potentially make the payments & transactions out-of-date by the time that we attempt to process them.
      Parameters:
      jobRef - Contains the scheduled job detail with this property
      Returns:
      The batch size to use when fetching payment transactions
    • getPaymentsById

      protected Map<String,Payment> getPaymentsById(@NonNull @NonNull List<PaymentTransaction> transactions, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Gather the Payments related to the provided PaymentTransactions.
      Parameters:
      transactions - The transactions that are to be reversed
      contextInfo - context information related to multitenancy.
      Returns:
      the Payments related to the provided PaymentTransactions.
    • processTransactionReversalsForPayments

      protected void processTransactionReversalsForPayments(@NonNull @NonNull List<PaymentTransaction> transactions, @NonNull @NonNull Map<String,Payment> paymentsById, @NonNull @NonNull String jobIdempotencyKey, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Responsible for initiating payment transaction reversals for the provided payments.
      Parameters:
      transactions - the list of transactions to be reversed.
      paymentsById - the payments for the transactions grouped by ID.
      jobIdempotencyKey - A unique identifier for this job execution.
      contextInfo - context information related to multitenancy.
    • prepareTransactionsForReversal

      protected List<PaymentTransaction> prepareTransactionsForReversal(List<PaymentTransaction> transactions, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Updates the transaction management state to REVERSAL_IN_PROGRESS.
      Parameters:
      transactions - the list of transactions to be reversed
      contextInfo - context information related to multitenancy.
      Returns:
      the updated transactions
    • reversePaymentTransactions

      @Deprecated(since="1.0.2", forRemoval=true) protected List<PaymentTransaction> reversePaymentTransactions(@NonNull @NonNull List<PaymentTransaction> transactions, @NonNull @NonNull Map<String,Payment> paymentsById, @NonNull @NonNull String jobIdempotencyKey, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Responsible for processing payment transaction reversals.
      Parameters:
      transactions - the list of transactions to be reversed.
      paymentsById - the payments for the transactions grouped by ID.
      jobIdempotencyKey - A unique identifier for this job execution.
      contextInfo - context information related to multitenancy.
      Returns:
      The processed transactions with the updated transaction management state.
    • reversePaymentTransactions

      protected void reversePaymentTransactions(@NonNull @NonNull Payment payment, @NonNull @NonNull List<PaymentTransaction> transactions, @NonNull @NonNull String jobIdempotencyKey, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Responsible for processing payment transaction reversals.
      Parameters:
      payment - the payment for transactions.
      transactions - the list of transactions to be reversed.
      jobIdempotencyKey - A unique identifier for this job execution.
      lockToken - Token granted to resource that owns the payment lock.
      contextInfo - context information related to multitenancy.
    • reversePaymentTransaction

      @Deprecated(since="1.0.2", forRemoval=true) protected String reversePaymentTransaction(@NonNull @NonNull Map<String,Payment> paymentsById, @NonNull @NonNull PaymentTransaction parentTransaction, @NonNull @NonNull String jobIdempotencyKey, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Responsible for processing payment transaction reversals based on the provided payment and transaction.
      Parameters:
      paymentsById - the payments for the transactions grouped by ID.
      parentTransaction - The transaction that is being rolled back.
      jobIdempotencyKey - A unique identifier for this job execution.
      contextInfo - context information related to multitenancy.
      Returns:
      DefaultTransactionReversalStatuses.SUCCESS if the transaction was successfully reversed or DefaultTransactionReversalStatuses.FAILURE otherwise
    • reversePaymentTransaction

      protected String reversePaymentTransaction(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction parentTransaction, @NonNull @NonNull String jobIdempotencyKey, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Responsible for processing payment transaction reversals based on the provided payment and transaction.
      Parameters:
      payment - the payments for the transactions.
      parentTransaction - The transaction that is being rolled back.
      jobIdempotencyKey - A unique identifier for this job execution.
      lockToken - Token granted to resource that owns the payment lock.
      contextInfo - context information related to multitenancy.
      Returns:
      DefaultTransactionReversalStatuses.SUCCESS if the transaction was successfully reversed or DefaultTransactionReversalStatuses.FAILURE otherwise
    • reverseAuthTransaction

      @Deprecated(since="1.0.2", forRemoval=true) protected String reverseAuthTransaction(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction parentTransaction, @NonNull @NonNull String jobIdempotencyKey, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Communicates with the relevant payment gateway to execute a DefaultTransactionTypes.REVERSE_AUTH transaction.
      Parameters:
      payment - The payment that was previously authorized.
      parentTransaction - The transaction that is being rolled back.
      jobIdempotencyKey - A unique identifier for this job execution.
      contextInfo - context information related to multitenancy.
      Returns:
      DefaultTransactionReversalStatuses.SUCCESS if the transaction was successfully reversed or DefaultTransactionReversalStatuses.FAILURE otherwise
      See Also:
    • reverseAuthTransaction

      protected String reverseAuthTransaction(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction parentTransaction, @NonNull @NonNull String jobIdempotencyKey, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Communicates with the relevant payment gateway to execute a DefaultTransactionTypes.REVERSE_AUTH transaction.
      Parameters:
      payment - The payment for the transactions.
      parentTransaction - The transaction that is being rolled back.
      jobIdempotencyKey - A unique identifier for this job execution.
      lockToken - Token granted to resource that owns the payment lock.
      contextInfo - context information related to multitenancy.
      Returns:
      DefaultTransactionReversalStatuses.SUCCESS if the transaction was successfully reversed or DefaultTransactionReversalStatuses.FAILURE otherwise
      See Also:
    • reverseAuthAndCaptureTransaction

      @Deprecated(since="1.0.2", forRemoval=true) protected String reverseAuthAndCaptureTransaction(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction parentTransaction, @NonNull @NonNull String jobIdempotencyKey, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Reverses a successful authorizeAndCapture transaction by interacting with the relevant payment gateway to refund the authorizeAndCapture.
      Parameters:
      payment - The payment that was previously authorizeAndCaptured as a part of this checkout submission.
      parentTransaction - The transaction that is being rolled back.
      jobIdempotencyKey - A unique identifier for this job execution.
      contextInfo - context information related to multitenancy
      Returns:
      DefaultTransactionReversalStatuses.SUCCESS if the transaction was successfully reversed or DefaultTransactionReversalStatuses.FAILURE otherwise
    • reverseAuthAndCaptureTransaction

      protected String reverseAuthAndCaptureTransaction(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction parentTransaction, @NonNull @NonNull String jobIdempotencyKey, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Reverses a successful authorizeAndCapture transaction by interacting with the relevant payment gateway to refund the authorizeAndCapture.
      Parameters:
      payment - The payment that was previously authorizeAndCaptured as a part of this checkout submission.
      parentTransaction - The transaction that is being rolled back.
      jobIdempotencyKey - A unique identifier for this job execution.
      lockToken - Token granted to resource that owns the payment lock.
      contextInfo - context information related to multitenancy
      Returns:
      DefaultTransactionReversalStatuses.SUCCESS if the transaction was successfully reversed or DefaultTransactionReversalStatuses.FAILURE otherwise
    • reverseCaptureTransaction

      @Deprecated(since="1.0.2", forRemoval=true) protected String reverseCaptureTransaction(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction parentTransaction, @NonNull @NonNull String jobIdempotencyKey, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Reverses a successful capture transaction by interacting with the relevant payment gateway to refund the capture.
      Parameters:
      payment - The payment that was previously captured as a part of this checkout submission.
      parentTransaction - The transaction that is being rolled back.
      jobIdempotencyKey - A unique identifier for this job execution.
      contextInfo - context information related to multitenancy.
      Returns:
      DefaultTransactionReversalStatuses.SUCCESS if the transaction was successfully reversed or DefaultTransactionReversalStatuses.FAILURE otherwise
    • reverseCaptureTransaction

      protected String reverseCaptureTransaction(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction parentTransaction, @NonNull @NonNull String jobIdempotencyKey, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Reverses a successful capture transaction by interacting with the relevant payment gateway to refund the capture.
      Parameters:
      payment - The payment that was previously captured as a part of this checkout submission.
      parentTransaction - The transaction that is being rolled back.
      jobIdempotencyKey - A unique identifier for this job execution.
      lockToken - Token granted to resource that owns the payment lock.
      contextInfo - context information related to multitenancy.
      Returns:
      DefaultTransactionReversalStatuses.SUCCESS if the transaction was successfully reversed or DefaultTransactionReversalStatuses.FAILURE otherwise
    • refundTransaction

      @Deprecated(since="1.0.2", forRemoval=true) protected String refundTransaction(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction parentTransaction, @NonNull @NonNull String jobIdempotencyKey, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • refundTransaction

      protected String refundTransaction(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction parentTransaction, @NonNull @NonNull String jobIdempotencyKey, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • archiveSingleUsePayment

      protected void archiveSingleUsePayment(@NonNull @NonNull Payment payment, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Archives the Payment that represents a single-use payment method.
      Parameters:
      payment - The payment to archive.
      lockToken - Token granted to resource that owns the payment lock.
      contextInfo - context information related to multitenancy.
    • buildContextInfoForRead

      protected com.broadleafcommerce.data.tracking.core.context.ContextInfo buildContextInfoForRead(org.springframework.messaging.Message<com.broadleafcommerce.common.messaging.domain.ScheduledJobRef> message)
      Builds a ContextInfo object, which is used to gather and update the payments and transactions.
      Parameters:
      message - Contains scheduled job details about the context
      Returns:
      A ContextInfo object, which used to gather & update carts.
    • buildContextInfoForUpdate

      protected com.broadleafcommerce.data.tracking.core.context.ContextInfo buildContextInfoForUpdate(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfoForRead)
      Builds a ContextInfo object for OperationType.UPDATE, which is used to update the payments and transactions.

      The ContextInfo.isIgnoreNarrowing() is set to true for update, because it is also used to retrieve the owning payment, which may be archived.

      Parameters:
      contextInfoForRead - the ContextInfo with OperationType.READ to build from
      Returns:
      a ContextInfo object for OperationType.UPDATE
    • buildContextInfoForReadPayments

      protected com.broadleafcommerce.data.tracking.core.context.ContextInfo buildContextInfoForReadPayments(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfoForRead)
      Builds a ContextInfo object for OperationType.READ, which is used to read the payments.

      When reading Payments, a new ContextInfo is built with ContextInfo.isIgnoreNarrowing() set to true. This is done so that this job can reverse transactions even if their payments are archived. The payments should already be tenant discriminated, because their transactions should already be narrowed by specified tenant.

      Parameters:
      contextInfoForRead - the ContextInfo with OperationType.READ to build from
      Returns:
      a ContextInfo object for OperationType.UPDATE
    • getJobIdempotencyKey

      protected String getJobIdempotencyKey(org.springframework.messaging.Message<com.broadleafcommerce.common.messaging.domain.ScheduledJobRef> message)
    • processFailedTransactionReversal

      protected List<PaymentTransaction> processFailedTransactionReversal(List<PaymentTransaction> paymentTransactions, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Updates the transaction management state to FAILED_REVERSAL if the transaction in REVERSAL_IN_PROGRESS state.
      Parameters:
      paymentTransactions - the transactions to process
      contextInfo - context information related to multitenancy
      Returns:
      the failed transactions
    • getIdempotentMessageService

      protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService getIdempotentMessageService()
    • getScheduledJobContextService

      protected com.broadleafcommerce.data.tracking.core.service.scheduledjob.ScheduledJobContextService getScheduledJobContextService()
    • getPaymentService

      protected PaymentService<Payment> getPaymentService()
    • getPaymentTransactionService

      protected PaymentTransactionService<PaymentTransaction> getPaymentTransactionService()
    • getTransactionExecutionService

      protected TransactionExecutionService getTransactionExecutionService()
    • setProperties

      @Autowired public void setProperties(PaymentTransactionReversalProperties properties)
    • getProperties

      protected PaymentTransactionReversalProperties getProperties()
    • setPaymentManagementService

      @Autowired public void setPaymentManagementService(PaymentManagementService<Payment> paymentManagementService)
    • getPaymentManagementService

      protected PaymentManagementService<Payment> getPaymentManagementService()
    • setPaymentLockService

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

      protected PaymentLockService<Payment> getPaymentLockService()
    • getServiceProperties

      protected PaymentTransactionServiceProperties getServiceProperties()
    • setServiceProperties

      @Autowired public void setServiceProperties(PaymentTransactionServiceProperties serviceProperties)