java.lang.Object
com.broadleafcommerce.cartoperation.service.provider.external.AbstractExternalProvider
com.broadleafcommerce.cartoperation.service.provider.external.payments.ExternalPaymentProvider<P>
All Implemented Interfaces:
PaymentProvider<P>

public class ExternalPaymentProvider<P extends PaymentSummary> extends AbstractExternalProvider implements PaymentProvider<P>
This particular implementation of PaymentProvider is designed to interact with the payment transaction service.
Author:
Dima Myroniuk (dmyroniuk)
  • Field Details

  • Constructor Details

    • ExternalPaymentProvider

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

    • readAllByOwnerTypeAndOwnerId

      public List<P> readAllByOwnerTypeAndOwnerId(@NonNull @NonNull String ownerType, @NonNull @NonNull String ownerId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: PaymentProvider
      Retrieves a list of PaymentSummaries that belong to the given owner type and owner id.
      Specified by:
      readAllByOwnerTypeAndOwnerId in interface PaymentProvider<P extends PaymentSummary>
      Parameters:
      ownerType - the owner type of the PaymentSummaries to retrieve
      ownerId - the owner id of the PaymentSummaries to retrieve
      context - context information around sandbox and multitenant state.
      Returns:
      a list of PaymentSummaries based on the given owner type and owner id
    • patchPayment

      public PaymentSummary patchPayment(UpdatePaymentRequest updatePaymentRequest, Integer version, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: PaymentProvider
      Updates the payment based on the provided UpdatePaymentRequest. This method can be used to partially update the payment. To do so provide only the fields you would like to update. The default implementation archives the payment if UpdatePaymentRequest.getAmount() is equal to zero.
      Specified by:
      patchPayment in interface PaymentProvider<P extends PaymentSummary>
      Parameters:
      updatePaymentRequest - the request payload used to update the payment
      version - the payment version
      lockToken - the token that owns the payment lock
      context - Context information related to multitenancy
      Returns:
      the updated payment summary.
    • archivePayment

      public void archivePayment(String paymentId, Integer version, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: PaymentProvider
      Archives the payment based on the provided id and version.
      Specified by:
      archivePayment in interface PaymentProvider<P extends PaymentSummary>
      Parameters:
      paymentId - the context id of the payment
      version - the payment version
      lockToken - Token that can be used to unlock the cart's payment
      context - context information related to multitenancy
    • lockCartPayments

      public Map<String,String> lockCartPayments(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentProvider
      Locks the cart's payments to ensure that all of the work done within the CheckoutWorkflow and checkout process in general is consistently interacting with payments that will not change. With these locks in place, only this executing process will have access to modify the payments, until the lock TTL expires. Note: make sure that the checkout process can sufficiently be contained within the payment lock TTL. This can be configured in PaymentTransactionServices.
      Specified by:
      lockCartPayments in interface PaymentProvider<P extends PaymentSummary>
      Parameters:
      cart - the Cart whose payments are to be locked.
      contextInfo - context information around sandbox and multitenant state.
      Returns:
      A map of payment id to lock token.
    • lockAndRetrieveCartPayments

      public LockPaymentsResponse lockAndRetrieveCartPayments(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.Cart cart, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentProvider
      Same functionality as PaymentProvider.lockCartPayments(Cart, ContextInfo) but this method also includes the PaymentSummaries in the response.

      This is useful to reduce the amount of network calls.

      Specified by:
      lockAndRetrieveCartPayments in interface PaymentProvider<P extends PaymentSummary>
      Parameters:
      cart - the Cart whose payments are to be locked.
      contextInfo - context information around sandbox and multitenant state.
      Returns:
      A LockPaymentsResponse containing the payment locks and PaymentSummaries
    • lockPayments

      protected Map<String,String> lockPayments(@NonNull @NonNull LockPaymentRequest lockPaymentRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Locks the payments based on the given LockPaymentRequest.
      Parameters:
      lockPaymentRequest - the LockPaymentRequest
      contextInfo - context information around sandbox and multitenant state
      Returns:
      A map of payment id to lock token.
      Throws:
      PaymentLockException - if a lock could not be obtained.
    • lockAndRetrievePayments

      protected LockPaymentsResponse lockAndRetrievePayments(@NonNull @NonNull LockPaymentRequest lockPaymentRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Locks the payments based on the given LockPaymentRequest.
      Parameters:
      lockPaymentRequest - the LockPaymentRequest
      contextInfo - context information around sandbox and multitenant state
      Returns:
      A map of payment id to lock token.
      Throws:
      PaymentLockException - if a lock could not be obtained.
    • unlockCartPayments

      public void unlockCartPayments(Collection<String> lockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentProvider
      Unlocks the cart's payments, based on the lock tokens that were previously obtained via PaymentProvider.lockCartPayments(Cart, ContextInfo).
      Specified by:
      unlockCartPayments in interface PaymentProvider<P extends PaymentSummary>
      Parameters:
      lockTokens - Tokens that can be used to unlock the cart's payments
    • finalizePaymentsForCheckout

      public UpdatePaymentsResponse finalizePaymentsForCheckout(String cartId, Map<String,String> paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentProvider
      The PaymentTransactionServices internally prepares and finalizes the payments for checkout.
      Specified by:
      finalizePaymentsForCheckout in interface PaymentProvider<P extends PaymentSummary>
      Parameters:
      cartId - the owner id of the PaymentSummaries to finalize
      paymentLockTokens - Tokens that can be used to unlock the cart's payments
      contextInfo - context information around sandbox and multitenant state.
    • blockCustomerMutabilityForPayments

      public UpdatePaymentsResponse blockCustomerMutabilityForPayments(@NonNull @NonNull String cartId, Map<String,String> paymentLockTokens, boolean markTransactionsIneligibleForAutoReversal, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentProvider
      Blocks customer mutability for the cart's payments.
      Specified by:
      blockCustomerMutabilityForPayments in interface PaymentProvider<P extends PaymentSummary>
      Parameters:
      cartId - the owner id of the PaymentSummaries to finalize
      paymentLockTokens - Tokens that can be used to unlock the cart's payments
      markTransactionsIneligibleForAutoReversal - Determines if the payments' transactions should be marked ineligible for automatic reversal
      contextInfo - context information around sandbox and multitenant state.
    • blockCustomerMutabilityForPaymentFinalization

      public UpdatePaymentsResponse blockCustomerMutabilityForPaymentFinalization(@NonNull @NonNull String cartId, @NonNull @NonNull Map<String,String> paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentProvider
      Blocks customer mutability for the cart's payments while payment finalization is completed. Note: this block can be removed via PaymentProvider.removeCustomerMutabilityBlockForPaymentFinalization(String, Map, ContextInfo) if the customer chooses to opt-out of the finalization interaction.
      Specified by:
      blockCustomerMutabilityForPaymentFinalization in interface PaymentProvider<P extends PaymentSummary>
      Parameters:
      cartId - the id of the payment-owning cart
      paymentLockTokens - Tokens that can be used to unlock the cart's payments
      contextInfo - context information around sandbox and multitenant state.
    • removeCustomerMutabilityBlockForPaymentFinalization

      public UpdatePaymentsResponse removeCustomerMutabilityBlockForPaymentFinalization(@NonNull @NonNull String cartId, @NonNull @NonNull Map<String,String> paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentProvider
      Unblocks customer mutability for the cart's payments.
      Specified by:
      removeCustomerMutabilityBlockForPaymentFinalization in interface PaymentProvider<P extends PaymentSummary>
      Parameters:
      cartId - the id of the payment-owning cart
      paymentLockTokens - Tokens that can be used to unlock the cart's payments
      contextInfo - context information around sandbox and multitenant state.
    • transferPaymentsToCSR

      public UpdatePaymentsResponse transferPaymentsToCSR(String cartId, Map<String,String> paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentProvider
      The PaymentTransactionServices internally prepares and transfers the payments to the CSR user. The expectation is that the payments will no longer be owned by the customer and cannot be accessed except by the CSR user.
      Specified by:
      transferPaymentsToCSR in interface PaymentProvider<P extends PaymentSummary>
      Parameters:
      cartId - the owner id of the PaymentSummaries to transfer
      paymentLockTokens - Tokens that can be used to unlock the cart's payments
      contextInfo - context information around sandbox and multitenant state.
    • transferPaymentsToCustomer

      public UpdatePaymentsResponse transferPaymentsToCustomer(String cartId, Map<String,String> paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentProvider
      The PaymentTransactionServices internally prepares and transfers the payments to the customer user.
      Specified by:
      transferPaymentsToCustomer in interface PaymentProvider<P extends PaymentSummary>
      Parameters:
      cartId - the owner id of the PaymentSummaries to transfer
      paymentLockTokens - Tokens that can be used to unlock the cart's payments
      contextInfo - context information around sandbox and multitenant state.
    • claimTransactionsForRequest

      public PaymentSummary claimTransactionsForRequest(@NonNull @NonNull ClaimCheckoutTransactionsRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentProvider
      Updates the payment transaction request id with the new value, stores the previous value, clears transaction management state and management state reason.
      Specified by:
      claimTransactionsForRequest in interface PaymentProvider<P extends PaymentSummary>
      Parameters:
      request - the ClaimCheckoutTransactionsRequest to claim the transactions for a checkout request
      contextInfo - context information related to multitenancy
    • 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
    • getType

      protected org.springframework.core.ParameterizedTypeReference<P> getType()
      Gets the type reference for payment summary.
      Returns:
      type reference for payment summary
    • getPageType

      protected org.springframework.core.ParameterizedTypeReference<ResponsePageGenerator<P>> getPageType()
      Gets the type reference for a page generator of item list items.
      Returns:
      type reference for a page generator of item list items
    • getMapType

      protected org.springframework.core.ParameterizedTypeReference<Map<String,String>> getMapType()
      Gets the type reference for a list of item list items.
      Returns:
      type reference for a list of item list items
    • writePaymentLockTokensAsHeaderString

      protected String writePaymentLockTokensAsHeaderString(Map<String,String> paymentLockTokens)
    • getServiceClient

      protected String getServiceClient()
    • getProperties

      protected ExternalPaymentProperties getProperties()