Class DefaultTransactionWebhookService

java.lang.Object
com.broadleafcommerce.paymenttransaction.service.webhook.DefaultTransactionWebhookService
All Implemented Interfaces:
TransactionWebhookService

public class DefaultTransactionWebhookService extends Object implements TransactionWebhookService
The default implementation of TransactionWebhookService
Author:
Dima Myroniuk (dmyroniuk)
  • Constructor Details

  • Method Details

    • handleWebhook

      public org.springframework.http.ResponseEntity<?> handleWebhook(String gatewayType, @NonNull @NonNull org.springframework.http.HttpHeaders headers, String requestBody, @NonNull @NonNull Map<String,String> parameters)
      Description copied from interface: TransactionWebhookService
      Handles the payment webhook request for the specified gateway type.
      Specified by:
      handleWebhook in interface TransactionWebhookService
      Parameters:
      gatewayType - the gateway type that is used to identify the appropriate PaymentGatewayWebhookHandler
      headers - the webhook request headers
      requestBody - the webhook request body
      parameters - the webhook request parameters
      Returns:
      a ResponseEntity meant to communicate to the gateway with the processing result of the webhook.
    • handleHostedPaymentPageSetupTransactionResult

      protected PaymentTransaction handleHostedPaymentPageSetupTransactionResult(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @NonNull @NonNull PaymentTransaction paymentTransaction, @NonNull @NonNull Payment payment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • handleThreeDSTransactionResult

      protected PaymentTransaction handleThreeDSTransactionResult(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @NonNull @NonNull PaymentTransaction paymentTransaction, @NonNull @NonNull Payment payment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • handleAwaitingAsyncTransactionResult

      protected PaymentTransaction handleAwaitingAsyncTransactionResult(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @NonNull @NonNull PaymentTransaction paymentTransaction, @NonNull @NonNull Payment payment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • handleSubsequentTransactionResult

      protected PaymentTransaction handleSubsequentTransactionResult(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @NonNull @NonNull PaymentTransaction paymentTransaction, @NonNull @NonNull Payment payment, @NonNull @NonNull String eventId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • handleFraudReviewTransactionResult

      protected PaymentTransaction handleFraudReviewTransactionResult(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @NonNull @NonNull PaymentTransaction paymentTransaction, @NonNull @NonNull Payment payment, @NonNull @NonNull String eventId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • handleTransactionResultsUpdated

      protected PaymentTransaction handleTransactionResultsUpdated(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @NonNull @NonNull PaymentTransaction paymentTransaction, @NonNull @NonNull Payment payment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Since:
      Payment Transaction Service 2.0.6, Release Train 2.1.4, Release Train 2.2.0
    • determineTransactionToUpdate

      protected PaymentTransaction determineTransactionToUpdate(@NotNull @NotNull PaymentTransaction paymentTransaction, Optional<PaymentTransaction> childPaymentTransaction)
    • updateManagementStateAndRecordTransaction

      protected PaymentTransaction updateManagementStateAndRecordTransaction(@NotNull @NotNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @NotNull @NotNull Payment payment, @NotNull @NotNull PaymentTransaction transactionToUpdate, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • requiresReversalOfReverseAuthTransaction

      protected boolean requiresReversalOfReverseAuthTransaction(@NotNull @NotNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @NotNull @NotNull PaymentTransaction transactionToUpdate, Optional<PaymentTransaction> transactionToReverse)
    • failedAuthorizationIsUpdatedToSuccess

      protected boolean failedAuthorizationIsUpdatedToSuccess(@NotNull @NotNull PaymentTransaction paymentTransaction, @NotNull @NotNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse)
    • isNotificationTypeSupported

      protected boolean isNotificationTypeSupported(@NonNull @NonNull com.broadleafcommerce.paymentgateway.service.PaymentGatewayWebhookHandler webhookHandler, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.enums.SupportedWebhookNotificationType webhookNotificationType)
    • isFraudReviewResult

      protected boolean isFraudReviewResult(@NonNull @NonNull PaymentTransaction paymentTransaction, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse)
    • recordFraudReviewResults

      protected PaymentTransaction recordFraudReviewResults(@NonNull @NonNull PaymentTransaction paymentTransaction, @NonNull @NonNull Payment payment, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Updates the provided PaymentTransaction to indicate that the fraud review is finalized/closed & records the results of that review.
      Parameters:
      paymentTransaction - The PaymentTransaction transaction to be updated.
      payment - The Payment that owns the payment transaction.
      paymentResponse - The PaymentResponse describing the transaction's result.
      contextInfo - context information related to multi-tenancy.
      Returns:
      The updated PaymentTransaction.
    • isSubsequentTransactionResult

      protected boolean isSubsequentTransactionResult(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction paymentTransaction, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse)
      Determines if the PaymentResponse results represent a subsequent transaction that was executed after the known PaymentTransaction. If the transaction was triggered within PaymentTransactionServices, then the transaction types should be the same between the PaymentResponse & the PaymentTransaction. In that case, this method should return false. If the transaction was triggered outside of PaymentTransactionServices, but we have knowledge of a previous transaction (i.e. the PaymentTransaction), then we need to record a new PaymentTransaction for this PaymentResponse. In that case, this method should return true.
      Parameters:
      payment - The payment owning the PaymentTransaction
      paymentTransaction - The known PaymentTransaction
      paymentResponse - The transaction results
      Returns:
      boolean declaring if the PaymentResponse results represent a subsequent transaction that was executed after the known PaymentTransaction.
    • identifyParentTransaction

      protected PaymentTransaction identifyParentTransaction(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction paymentTransaction, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse)
    • isSubsequentTransactionAlreadyCreated

      protected boolean isSubsequentTransactionAlreadyCreated(@NonNull @NonNull Payment payment, @NonNull @NonNull String eventId)
    • recordSubsequentTransactionResults

      protected PaymentTransaction recordSubsequentTransactionResults(@NonNull @NonNull PaymentTransaction parentTransaction, @NonNull @NonNull Payment payment, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @NonNull @NonNull String eventId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Builds & records a PaymentTransaction based on the PaymentResponse which has been identified as a subsequent transaction to the provided parent transaction.
      Parameters:
      parentTransaction - The parent of the subsequent transaction.
      payment - The Payment that owns the parent & subsequent transactions.
      paymentResponse - The PaymentResponse describing the subsequent transaction's results.
      eventId - The id of the webhook event
      contextInfo - context information related to multi-tenancy.
      Returns:
      The PaymentTransaction created to represent the subsequent transaction.
    • shouldRecordImpliedReverseAuth

      protected boolean shouldRecordImpliedReverseAuth(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction captureTransaction)
    • recordImpliedReverseAuth

      protected PaymentTransaction recordImpliedReverseAuth(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction captureTransaction, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • recordImpliedReverseAuth

      protected PaymentTransaction recordImpliedReverseAuth(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction captureTransaction, @NonNull @NonNull PaymentTransaction parentAuthTransaction, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • recordTransactionResponse

      protected PaymentTransaction recordTransactionResponse(@NonNull @NonNull PaymentTransaction paymentTransaction, @NonNull @NonNull Payment payment, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • isTransactionRequiring3DSVerification

      protected boolean isTransactionRequiring3DSVerification(@NonNull @NonNull PaymentTransaction paymentTransaction, @NonNull @NonNull Payment payment, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse)
    • isHostedPaymentPageSetupTransaction

      protected boolean isHostedPaymentPageSetupTransaction(@NonNull @NonNull PaymentTransaction paymentTransaction, @NonNull @NonNull Payment payment, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse)
    • isTransactionResultsUpdated

      protected boolean isTransactionResultsUpdated(@NonNull @NonNull PaymentTransaction paymentTransaction, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @NonNull @NonNull com.broadleafcommerce.paymentgateway.service.PaymentGatewayWebhookHandler webhookHandler)
      Since:
      Payment Transaction Service 2.0.6, Release Train 2.1.4, Release Train 2.2.0
    • buildPaymentTransactionResultAudit

      protected PaymentTransactionResultAudit buildPaymentTransactionResultAudit(@NonNull @NonNull PaymentTransaction paymentTransaction, @NonNull @NonNull Payment payment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Builds the PaymentTransactionResultAudit to record previous transaction results for this transaction.
      Parameters:
      paymentTransaction - the transaction results previously recorded
      payment - the payment for the transaction
      contextInfo - context information related to multitenancy.
      Returns:
      the PaymentTransactionResultAudit containing details about the previous transaction results
    • getChildTransactionResult

      protected Optional<PaymentTransaction> getChildTransactionResult(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction transactionRequiringExternalInteraction)
    • updateChildTransactionResults

      protected PaymentTransaction updateChildTransactionResults(@NonNull @NonNull PaymentTransaction externalTransactionResult, @NonNull @NonNull Payment payment, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @NonNull @NonNull String managementStateReason, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Updates the child external transaction based on the given PaymentResponse.
      Parameters:
      externalTransactionResult - the transaction result PaymentTransaction to update
      payment - the Payment that this transaction belongs to
      paymentResponse - the PaymentResponse to update the transaction with
      managementStateReason - transaction management reason.
      contextInfo - context information related to multitenancy.
      Returns:
      the updated child transaction based on the given PaymentResponse
    • get3DSTransactionResult

      protected Optional<PaymentTransaction> get3DSTransactionResult(@NonNull @NonNull Payment payment, @NonNull @NonNull PaymentTransaction transactionRequiring3DS)
    • createChildTransactionAndRecordResponse

      protected PaymentTransaction createChildTransactionAndRecordResponse(@NonNull @NonNull PaymentTransaction parentTransaction, @NonNull @NonNull Payment payment, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • createChildTransactionAndRecordResponse

      protected PaymentTransaction createChildTransactionAndRecordResponse(@NonNull @NonNull PaymentTransaction parentTransaction, @NonNull @NonNull Payment payment, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @NonNull @NonNull String managementStateReason, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • updateChild3DSTransaction

      protected PaymentTransaction updateChild3DSTransaction(@NonNull @NonNull PaymentTransaction threeDSResultTransaction, @NonNull @NonNull Payment payment, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Updates the child 3DS transaction based on the given PaymentResponse.
      Parameters:
      threeDSResultTransaction - the 3DS PaymentTransaction to update
      payment - the Payment that this transaction belongs to
      paymentResponse - the PaymentResponse to update the 3DS transaction with
      contextInfo - context information related to multitenancy.
      Returns:
      the updated child 3DS transaction based on the given PaymentResponse
    • identifyTransaction

      protected PaymentTransaction identifyTransaction(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.TransactionIdentifier transactionIdentifier, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • buildErrorResponse

      protected org.springframework.http.ResponseEntity<?> buildErrorResponse(@Nullable com.broadleafcommerce.paymentgateway.service.PaymentGatewayWebhookHandler webhookHandler, @NonNull @NonNull Exception e)
    • sendTransactionWebhookMessage

      protected void sendTransactionWebhookMessage(Payment payment, PaymentTransaction transaction, boolean transactionRequiredExternalInteraction, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • identifyPaymentForTransaction

      protected Payment identifyPaymentForTransaction(com.broadleafcommerce.paymentgateway.domain.TransactionIdentifier transactionIdentifier, PaymentTransaction paymentTransaction, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • updateParentTransactionManagementStateForReversalTransaction

      protected void updateParentTransactionManagementStateForReversalTransaction(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentResponse paymentResponse, @NonNull @NonNull PaymentTransaction paymentTransaction, @NonNull @NonNull Payment payment, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • getContextInfo

      protected com.broadleafcommerce.data.tracking.core.context.ContextInfo getContextInfo(@NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.TransactionIdentifier transactionIdentifier)
    • 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
    • getWEBHOOK_SOURCE_TYPE

      protected static String getWEBHOOK_SOURCE_TYPE()
    • getWEBHOOK_SOURCE_ENTITY_TYPE

      protected static String getWEBHOOK_SOURCE_ENTITY_TYPE()
    • getPaymentGatewayResourceProvider

      protected com.broadleafcommerce.paymentgateway.service.provider.PaymentGatewayResourceProvider getPaymentGatewayResourceProvider()
    • getPaymentService

      protected PaymentService<Payment> getPaymentService()
    • getPaymentTransactionService

      protected PaymentTransactionService<PaymentTransaction> getPaymentTransactionService()
    • setPaymentTransactionResultAuditService

      @Autowired public void setPaymentTransactionResultAuditService(PaymentTransactionResultAuditService<PaymentTransactionResultAudit> paymentTransactionResultAuditService)
    • getPaymentTransactionResultAuditService

      protected PaymentTransactionResultAuditService<PaymentTransactionResultAudit> getPaymentTransactionResultAuditService()
    • getPaymentLockService

      protected PaymentLockService<Payment> getPaymentLockService()
    • getTransactionExecutionService

      protected TransactionExecutionService getTransactionExecutionService()
    • getTransactionWebhookMessageService

      protected TransactionWebhookMessageService getTransactionWebhookMessageService()
    • getObjectMapper

      protected com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
    • setTypeFactory

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