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 Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final StringTheApiError.getType()that indicates that the transaction was already attempted.static final StringTheApiError.getType()that indicates that the transaction request is invalid.Fields inherited from class com.broadleafcommerce.billing.service.provider.external.AbstractExternalProvider
ENTITY_NOT_FOUND -
Constructor Summary
ConstructorsConstructorDescriptionExternalPaymentTransactionExecutionProvider(org.springframework.web.reactive.function.client.WebClient webClient, com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.broadleafcommerce.common.extension.TypeFactory typeFactory, ExternalPaymentTransactionExecutionProviderProperties properties) -
Method Summary
Modifier and TypeMethodDescriptionauthorizeAndCapture(@NonNull String savedPaymentMethodId, @NonNull SavedPaymentMethodTransactionExecutionRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Authorize and Captures an amount described by theSavedPaymentMethodTransactionExecutionRequestagainst the saved payment method described by the providedsavedPaymentMethodId.protected RuntimeExceptionbuildBadRequestException(org.springframework.web.reactive.function.client.WebClientResponseException.BadRequest bre) Builds a not found exception that correlates to the givenWebClientResponseException.BadRequestexception.protected <T> TexecuteRequest(Supplier<T> request) Executes a request with default Web Client error handling.protected org.springframework.web.util.UriComponentsBuilderGets the base URI common to all requests this provider will make.protected Stringprotected booleanisDuplicateTransactionAttempt(org.springframework.http.ResponseEntity<com.broadleafcommerce.common.error.ApiError> apiError) Determines if the givenResponseEntityindicates entity not found.protected booleanisInvalidTransactionRequest(org.springframework.http.ResponseEntity<com.broadleafcommerce.common.error.ApiError> apiError) Determines if the givenResponseEntityindicates entity not found.lookupAuthAndCaptureTransactionResults(@NonNull String savedPaymentMethodId, @NonNull String requestId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Using the providedsavedPaymentMethodId&requestId(must match the requestId provided in the attempted AuthorizeAndCapture transaction) to lookup transaction results for the transaction.lookupRefundTransactionResults(@NonNull String paymentId, @NonNull String requestId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Using the providedpaymentId&requestId(must match the requestId provided in the attempted Refund transaction) to lookup transaction results for the transaction.refund(@NonNull String paymentId, @NonNull TransactionExecutionRequest request, @NonNull String paymentVersion, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Refunds an amount for the given payment.Methods inherited from class com.broadleafcommerce.billing.service.provider.external.AbstractExternalProvider
addOffsetOrPageNumber, buildNotFoundException, getHeaders, getObjectMapper, getTypeFactory, getWebClient, isEntityNotFound, pageableToParams, uriVars
-
Field Details
-
DEFAULT_HEADER_PAYMENT_VERSION
- See Also:
-
INVALID_TRANSACTION_REQUEST
TheApiError.getType()that indicates that the transaction request is invalid.- See Also:
-
DUPLICATE_TRANSACTION_ATTEMPT
TheApiError.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:PaymentTransactionExecutionProviderAuthorize and Captures an amount described by theSavedPaymentMethodTransactionExecutionRequestagainst the saved payment method described by the providedsavedPaymentMethodId. Note: The combination ofsavedPaymentMethodId&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:
authorizeAndCapturein interfacePaymentTransactionExecutionProvider- Parameters:
savedPaymentMethodId- The id of a saved payment method stored in PaymentTransactionServicesrequest- The request payload describing the transaction that is to be executedcontextInfo- context information around the multi-tenant state- Returns:
- the
TransactionExecutionResponsefor 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:PaymentTransactionExecutionProviderUsing the providedsavedPaymentMethodId&requestId(must match the requestId provided in the attempted AuthorizeAndCapture transaction) to lookup transaction results for the transaction.- Specified by:
lookupAuthAndCaptureTransactionResultsin interfacePaymentTransactionExecutionProvider- Parameters:
savedPaymentMethodId- The id of a saved payment method stored in PaymentTransactionServicesrequestId- The request id provided viaSavedPaymentMethodTransactionExecutionRequest.getRequestId()with the attempted AuthorizeAndCapture transactioncontextInfo- 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:PaymentTransactionExecutionProviderRefunds an amount for the given payment.This method assumes that the parent transaction of this execution belongs to the same source entity, hence using
sourceEntityTypeasparentSourceEntityType.- Specified by:
refundin interfacePaymentTransactionExecutionProvider- Parameters:
paymentId- the id of the PaymentTransactionServices Payment that was created as part of the AuthorizeAndCapture transaction using a saved payment methodrequest- theTransactionExecutionRequestto executepaymentVersion- 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
TransactionExecutionResponsefor 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:PaymentTransactionExecutionProviderUsing the providedpaymentId&requestId(must match the requestId provided in the attempted Refund transaction) to lookup transaction results for the transaction.- Specified by:
lookupRefundTransactionResultsin interfacePaymentTransactionExecutionProvider- Parameters:
paymentId- The id of a Payment in PaymentTransactionServicesrequestId- The request id provided viaSavedPaymentMethodTransactionExecutionRequest.getRequestId()with the attempted Refund transactioncontextInfo- context information around the multi-tenant state- Returns:
- an optional containing the results of the Refund transaction, if they can be found
-
executeRequest
Executes a request with default Web Client error handling.- Overrides:
executeRequestin classAbstractExternalProvider- 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 givenWebClientResponseException.BadRequestexception.If the exception is of type
DUPLICATE_TRANSACTION_ATTEMPT, aDuplicateTransactionAttemptExceptionis thrown. Otherwise, it's wrapped inProviderApiException.- Parameters:
bre- theWebClientResponseException.BadRequestto build the not found exception from- Returns:
- a not found exception that correlates to the given
WebClientResponseException.BadRequestexception
-
isInvalidTransactionRequest
protected boolean isInvalidTransactionRequest(org.springframework.http.ResponseEntity<com.broadleafcommerce.common.error.ApiError> apiError) Determines if the givenResponseEntityindicates entity not found.This is useful to distinguish a
HttpStatus.BAD_REQUESTresponse indicating that the transaction request was invalid.- Parameters:
apiError- theResponseEntityto check against- Returns:
- true if the given
ResponseEntityindicates entity not found
-
isDuplicateTransactionAttempt
protected boolean isDuplicateTransactionAttempt(org.springframework.http.ResponseEntity<com.broadleafcommerce.common.error.ApiError> apiError) Determines if the givenResponseEntityindicates entity not found.This is useful to distinguish a
HttpStatus.BAD_REQUESTresponse indicating that the payment transaction was already attempted.- Parameters:
apiError- theResponseEntityto check against- Returns:
- true if the given
ResponseEntityindicates 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
-
getProperties
-