Class ExternalPaymentTransactionExecutionProvider

java.lang.Object
com.broadleafcommerce.billing.service.provider.external.AbstractExternalProvider
com.broadleafcommerce.billing.service.provider.external.ExternalPaymentTransactionExecutionProvider
All Implemented Interfaces:
PaymentTransactionExecutionProvider

public class ExternalPaymentTransactionExecutionProvider extends AbstractExternalProvider implements PaymentTransactionExecutionProvider
Author:
Chris Kittrell (ckittrell)
  • Field Details

    • DEFAULT_HEADER_PAYMENT_VERSION

      public static final String DEFAULT_HEADER_PAYMENT_VERSION
      See Also:
    • INVALID_TRANSACTION_REQUEST

      public static final String INVALID_TRANSACTION_REQUEST
      The ApiError.getType() that indicates that the transaction request is invalid.
      See Also:
    • DUPLICATE_TRANSACTION_ATTEMPT

      public static final String DUPLICATE_TRANSACTION_ATTEMPT
      The ApiError.getType() that indicates that the transaction was already attempted.
      See Also:
  • Constructor Details

    • ExternalPaymentTransactionExecutionProvider

      public ExternalPaymentTransactionExecutionProvider(org.springframework.web.reactive.function.client.WebClient webClient, com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, ExternalPaymentTransactionExecutionProviderProperties properties)
  • Method Details

    • authorizeAndCapture

      public TransactionExecutionResponse authorizeAndCapture(@NonNull @NonNull String savedPaymentMethodId, @NonNull @NonNull SavedPaymentMethodTransactionExecutionRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentTransactionExecutionProvider
      Authorize and Captures an amount described by the SavedPaymentMethodTransactionExecutionRequest against the saved payment method described by the provided savedPaymentMethodId.

      Note: The combination of savedPaymentMethodId & SavedPaymentMethodTransactionExecutionRequest.getRequestId() are used to describe the uniqueness of the attempted interaction. This combination must be unique, or the request will be rejected.

      Specified by:
      authorizeAndCapture in interface PaymentTransactionExecutionProvider
      Parameters:
      savedPaymentMethodId - The id of a saved payment method stored in PaymentTransactionServices
      request - The request payload describing the transaction that is to be executed
      contextInfo - context information around the multi-tenant state
      Returns:
      the TransactionExecutionResponse for the AuthorizeAndCapture transaction
    • lookupAuthAndCaptureTransactionResults

      public Optional<TransactionExecutionResponse> lookupAuthAndCaptureTransactionResults(@NonNull @NonNull String savedPaymentMethodId, @NonNull @NonNull String requestId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentTransactionExecutionProvider
      Using the provided savedPaymentMethodId & requestId (must match the requestId provided in the attempted AuthorizeAndCapture transaction) to lookup transaction results for the transaction.
      Specified by:
      lookupAuthAndCaptureTransactionResults in interface PaymentTransactionExecutionProvider
      Parameters:
      savedPaymentMethodId - The id of a saved payment method stored in PaymentTransactionServices
      requestId - The request id provided via SavedPaymentMethodTransactionExecutionRequest.getRequestId() with the attempted AuthorizeAndCapture transaction
      contextInfo - context information around the multi-tenant state
      Returns:
      an optional containing the results of the AuthorizeAndCapture transaction, if they can be found
    • refund

      public TransactionExecutionResponse refund(@NonNull @NonNull String paymentId, @NonNull @NonNull TransactionExecutionRequest request, @NonNull @NonNull String paymentVersion, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentTransactionExecutionProvider
      Refunds an amount for the given payment.

      This method assumes that the parent transaction of this execution belongs to the same source entity, hence using sourceEntityType as parentSourceEntityType.

      Specified by:
      refund in interface PaymentTransactionExecutionProvider
      Parameters:
      paymentId - the id of the PaymentTransactionServices Payment that was created as part of the AuthorizeAndCapture transaction using a saved payment method
      request - the TransactionExecutionRequest to execute
      paymentVersion - the known version of the PaymentTransactionServices Payment. Note: If this value is out-of-date (i.e. the Payment has since been updated or a transaction has been executed), then the BillingService could be making an incorrect decision about executing a refund.
      contextInfo - context information around the multi-tenant state
      Returns:
      the TransactionExecutionResponse for the Refund transaction
    • lookupRefundTransactionResults

      public Optional<TransactionExecutionResponse> lookupRefundTransactionResults(@NonNull @NonNull String paymentId, @NonNull @NonNull String requestId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentTransactionExecutionProvider
      Using the provided paymentId & requestId (must match the requestId provided in the attempted Refund transaction) to lookup transaction results for the transaction.
      Specified by:
      lookupRefundTransactionResults in interface PaymentTransactionExecutionProvider
      Parameters:
      paymentId - The id of a Payment in PaymentTransactionServices
      requestId - The request id provided via SavedPaymentMethodTransactionExecutionRequest.getRequestId() with the attempted Refund transaction
      contextInfo - context information around the multi-tenant state
      Returns:
      an optional containing the results of the Refund transaction, if they can be found
    • executeRequest

      protected <T> T executeRequest(Supplier<T> request)
      Executes a request with default Web Client error handling.
      Overrides:
      executeRequest in class AbstractExternalProvider
      Type Parameters:
      T - the return type of the request operation
      Parameters:
      request - the request to execute
      Returns:
      the value generated by the supplier
    • buildBadRequestException

      protected RuntimeException buildBadRequestException(org.springframework.web.reactive.function.client.WebClientResponseException.BadRequest bre)
      Builds a not found exception that correlates to the given WebClientResponseException.BadRequest exception.

      If the exception is of type DUPLICATE_TRANSACTION_ATTEMPT, a DuplicateTransactionAttemptException is thrown. Otherwise, it's wrapped in ProviderApiException.

      Parameters:
      bre - the WebClientResponseException.BadRequest to build the not found exception from
      Returns:
      a not found exception that correlates to the given WebClientResponseException.BadRequest exception
    • isInvalidTransactionRequest

      protected boolean isInvalidTransactionRequest(org.springframework.http.ResponseEntity<com.broadleafcommerce.common.error.ApiError> apiError)
      Determines if the given ResponseEntity indicates entity not found.

      This is useful to distinguish a HttpStatus.BAD_REQUEST response indicating that the transaction request was invalid.

      Parameters:
      apiError - the ResponseEntity to check against
      Returns:
      true if the given ResponseEntity indicates entity not found
    • isDuplicateTransactionAttempt

      protected boolean isDuplicateTransactionAttempt(org.springframework.http.ResponseEntity<com.broadleafcommerce.common.error.ApiError> apiError)
      Determines if the given ResponseEntity indicates entity not found.

      This is useful to distinguish a HttpStatus.BAD_REQUEST response indicating that the payment transaction was already attempted.

      Parameters:
      apiError - the ResponseEntity to check against
      Returns:
      true if the given ResponseEntity indicates entity not found
    • getBaseUri

      protected org.springframework.web.util.UriComponentsBuilder getBaseUri()
      Gets the base URI common to all requests this provider will make.
      Returns:
      a URI components builder with the base URI set up
    • getServiceClient

      protected String getServiceClient()
    • getProperties