Class DefaultPaymentManagementService<P extends Payment>

java.lang.Object
com.broadleafcommerce.paymenttransaction.service.DefaultPaymentManagementService<P>
All Implemented Interfaces:
PaymentManagementService<P>

public class DefaultPaymentManagementService<P extends Payment> extends Object implements PaymentManagementService<P>
Author:
Chris Kittrell (ckittrell)
  • Constructor Details

  • Method Details

    • createPayment

      public P createPayment(@NonNull @NonNull CreatePaymentRequest createPaymentRequest, @Nullable CustomerRef customerRef, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentManagementService
      Creates a Payment based on the provided CreatePaymentRequest.
      Specified by:
      createPayment in interface PaymentManagementService<P extends Payment>
      Parameters:
      createPaymentRequest - The request payload used to build a new Payment.
      contextInfo - Context information related to multitenancy.
      Returns:
      A Payment based on the provided CreatePaymentRequest.
    • readAllByPaymentIds

      public List<P> readAllByPaymentIds(@NonNull Iterable<String> ids, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: PaymentManagementService
      Find a list of payments for the given payment ids.
      Specified by:
      readAllByPaymentIds in interface PaymentManagementService<P extends Payment>
      Parameters:
      ids - , The ids of the payments.
      context - Context information related to multitenancy.
      Returns:
      A list of payments for the given ids.
    • readAllByOwnerTypeAndOwnerId

      public org.springframework.data.domain.Page<P> readAllByOwnerTypeAndOwnerId(@NonNull @NonNull String ownerType, @NonNull @NonNull String ownerId, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: PaymentManagementService
      Find a page of payments for the given owner type and owner id.
      Specified by:
      readAllByOwnerTypeAndOwnerId in interface PaymentManagementService<P extends Payment>
      Parameters:
      ownerType - The type of the payment's owner.
      ownerId - The id of the payment's owner.
      page - The requested page of results from the database.
      context - Context information related to multitenancy.
      Returns:
      A page of payments for the given owner type and id.
    • updatePaymentForCustomer

      @Nullable public P updatePaymentForCustomer(@NonNull @NonNull String id, @NonNull @NonNull UpdatePaymentRequest updateRequest, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: PaymentManagementService
      Updates the Payment for the customer based on the provided UpdatePaymentRequest. The default implementation archives the payment if UpdatePaymentRequest.getAmount() is equal to zero.
      Specified by:
      updatePaymentForCustomer in interface PaymentManagementService<P extends Payment>
      Parameters:
      id - The context id for the Payment.
      updateRequest - The request payload used to update the Payment.
      lockToken - Token granted to resource that owns the payment lock.
      context - Context information related to multitenancy.
      Returns:
      The updated Payment.
    • updatePayment

      @Nullable public P updatePayment(@NonNull @NonNull String id, @NonNull @NonNull UpdatePaymentRequest updateRequest, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: PaymentManagementService
      Updates the Payment based on the provided UpdatePaymentRequest. The default implementation archives the payment if UpdatePaymentRequest.getAmount() is equal to zero.
      Specified by:
      updatePayment in interface PaymentManagementService<P extends Payment>
      Parameters:
      id - The context id for the Payment.
      updateRequest - The request payload used to update the Payment.
      lockToken - Token granted to resource that owns the payment lock.
      context - Context information related to multitenancy.
      Returns:
      The updated Payment.
    • archivePayment

      @Transactional("paymentTransactionTransactionManager") public void archivePayment(@NonNull @NonNull String id, @Nullable String lockToken, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: PaymentManagementService
      Archives the Payment based on the provided id.
      Specified by:
      archivePayment in interface PaymentManagementService<P extends Payment>
      Parameters:
      id - The context id for the Payment.
      lockToken - Token granted to resource that owns the payment lock.
      context - Context information related to multitenancy.
    • blockCustomerMutability

      public UpdatePaymentsResponse blockCustomerMutability(org.springframework.data.domain.Page<Payment> payments, PaymentLockTokens paymentLockTokens, boolean shouldMarkTransactionsIneligibleForAutomaticReversal, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentManagementService
      Finalizes the list of payments provided.
      Specified by:
      blockCustomerMutability in interface PaymentManagementService<P extends Payment>
      Parameters:
      payments - the page of payments to finalize
      paymentLockTokens - the collection of payment lock tokens to grant access to the payments
      shouldMarkTransactionsIneligibleForAutomaticReversal - whether or not to mark the payments as ineligible for automatic reversal
      contextInfo - Context information related to multitenancy.
      Returns:
      the response of successful and failed payments
    • transferPaymentsToCSR

      public UpdatePaymentsResponse transferPaymentsToCSR(org.springframework.data.domain.Page<Payment> payments, PaymentLockTokens paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentManagementService
      Transfers the list of payments provided to the CSR.
      Specified by:
      transferPaymentsToCSR in interface PaymentManagementService<P extends Payment>
      Parameters:
      payments - the page of payments to transfer
      paymentLockTokens - the collection of payment lock tokens to grant access to the payments
      contextInfo - Context information related to multitenancy.
      Returns:
      the response of successful and failed payments
    • transferPaymentsFromCSR

      public UpdatePaymentsResponse transferPaymentsFromCSR(org.springframework.data.domain.Page<Payment> payments, PaymentLockTokens paymentLockTokens, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: PaymentManagementService
      Transfers the list of payments provided from the CSR.
      Specified by:
      transferPaymentsFromCSR in interface PaymentManagementService<P extends Payment>
      Parameters:
      payments - the page of payments to transfer
      paymentLockTokens - the collection of payment lock tokens to grant access to the payments
      contextInfo - Context information related to multitenancy.
      Returns:
      the response of successful and failed payments
    • buildUpdatePaymentsResponse

      protected UpdatePaymentsResponse buildUpdatePaymentsResponse(List<Payment> failedPayments, List<Payment> successfulPayments, Map<String,String> failureMessages)
    • buildPayment

      protected P buildPayment(@NonNull @NonNull CreatePaymentRequest createPaymentRequest, @Nullable CustomerRef customerRef, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • populatePaymentFromRequest

      protected P populatePaymentFromRequest(@NonNull P payment, @NonNull @NonNull CreatePaymentRequest createPaymentRequest, @Nullable CustomerRef customerRef, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • modifyPaymentMethodProperties

      protected P modifyPaymentMethodProperties(@NonNull P payment, @NonNull @NonNull CreatePaymentRequest createPaymentRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • populatePaymentOwningUser

      protected void populatePaymentOwningUser(@NonNull P payment, @NonNull @NonNull CreatePaymentRequest createPaymentRequest, @Nullable CustomerRef customerRef)
      Populates the properties describing the owning user of the given Payment.

      The owning user properties will be resolved first using the given CustomerRef. If they cannot be resolved, the values specified in the given CreatePaymentRequest will be used instead.

      Parameters:
      payment - the Payment to populate the owning user properties for
      createPaymentRequest - the CreatePaymentRequest for the Payment
      customerRef - the CustomerRef
    • populatePaymentFromSavedPayment

      @Deprecated(forRemoval=true) protected P populatePaymentFromSavedPayment(@NonNull P payment, @NonNull @NonNull CreatePaymentRequest createPaymentRequest, @Nullable CustomerRef customerRef, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • populatePaymentFromSavedPayment

      protected P populatePaymentFromSavedPayment(@NonNull P payment, @NonNull @NonNull String savedPaymentMethodId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Populates the given Payment with the saved payment method specified in Payment.getSavedPaymentMethodId().
      Parameters:
      payment - the Payment to populate for
      savedPaymentMethodId - the saved payment method id to retrieve the saved payment from
      contextInfo - context information surrounding multitenant state
      Returns:
      the Payment populated with the saved payment method
    • buildBillingAddress

      @Deprecated(forRemoval=true) protected Address buildBillingAddress(PaymentAccount paymentAccount)
      Deprecated, for removal: This API element is subject to removal in a future version.
      no longer used
    • validateCreatedPayment

      protected void validateCreatedPayment(@NonNull @NonNull Payment payment, @NonNull @NonNull CreatePaymentRequest createPaymentRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Check the validity of the provided Payment that is to be created.
      Parameters:
      payment - The candidate payment to be created.
      createPaymentRequest - The request to add a payment.
      contextInfo - Context information around sandbox and multitenant state
      Throws:
      InvalidCreatePaymentRequestException - if the create payment request produced an invalid payment
    • validateGatewayType

      protected void validateGatewayType(@NonNull @NonNull Payment payment)
      Validate that the Payment has a supported Payment.getGatewayType() value.
      Parameters:
      payment - The candidate payment to be added.
      Throws:
      InvalidCreatePaymentRequestException - if the provided gatewayType is not supported
    • isPaymentGatewaySupported

      protected boolean isPaymentGatewaySupported(@Nullable String gatewayType)
      Checks if PaymentGatewayConfiguration has been registered for the payment's Payment.getGatewayType()
      Parameters:
      gatewayType - The gateway type specified by a Payment
      Returns:
      whether or not PaymentGatewayConfiguration has been registered for the payment's Payment.getGatewayType()
    • validatePaymentAmounts

      protected void validatePaymentAmounts(@NonNull @NonNull Payment payment)
      Validate that the Payment amount is not a negative amount.
      Parameters:
      payment - The candidate payment to be added.
      Throws:
      InvalidCreatePaymentRequestException - if the provided payment amount is negative
    • validateRequestToSavePayment

      protected void validateRequestToSavePayment(@NonNull @NonNull Payment payment)
      Validate that the request to save the payment method for future use is not done for an already saved payment method.
      Parameters:
      payment - The candidate payment method to be added.
      Throws:
      InvalidCreatePaymentRequestException - if the provided payment method cannot be saved for future use
    • validatePaymentGatewayProperties

      protected void validatePaymentGatewayProperties(@NonNull @NonNull Payment payment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Validate that the Payment sufficiently represents a payment method for the declared Payment.getGatewayType().
      Parameters:
      payment - The candidate payment to be added.
      contextInfo - Context information around sandbox and multitenant state
      Throws:
      com.broadleafcommerce.paymentgateway.service.exception.InvalidPaymentConfigurationException - if the payment doesn't include sufficient data to execute transactions for the related gateway
    • populateAndValidatePaymentUpdates

      protected P populateAndValidatePaymentUpdates(@NonNull P payment, @NonNull @NonNull UpdatePaymentRequest updateRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • populatePaymentUpdatesFromRequest

      protected P populatePaymentUpdatesFromRequest(@NonNull P payment, @NonNull @NonNull UpdatePaymentRequest updateRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • populatePaymentUpdatesFromSavedPayment

      protected P populatePaymentUpdatesFromSavedPayment(@NonNull P payment, @NonNull @NonNull UpdatePaymentRequest updateRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • updatePaymentAmount

      protected void updatePaymentAmount(@NonNull @NonNull Payment payment, @NonNull @NonNull javax.money.MonetaryAmount amount, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • hasSuccessfulTransactionOfType

      protected boolean hasSuccessfulTransactionOfType(@NonNull @NonNull Payment payment, @NonNull @NonNull String transactionType)
    • requestReversalForTransactions

      @Deprecated protected List<PaymentTransaction> requestReversalForTransactions(@NonNull @NonNull Payment payment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • requestReversalForEligibleTransactions

      @Deprecated protected List<PaymentTransaction> requestReversalForEligibleTransactions(@NonNull @NonNull Payment payment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • requestReversalForEligibleTransactions

      protected List<PaymentTransaction> requestReversalForEligibleTransactions(@NonNull @NonNull Payment payment, @Nullable String reversalReason, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • shouldMarkTransactionsIneligibleForAutomaticReversal

      protected boolean shouldMarkTransactionsIneligibleForAutomaticReversal(@NonNull P payment, @NonNull @NonNull UpdatePaymentRequest updateRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Parameters:
      payment - the Payment being updated
      updateRequest - the UpdatePaymentRequest containing the details to update the Payment
      context - context information around sandbox and multitenant state
      Returns:
      true if the Payment.getTransactions() should be marked to DefaultTransactionManagementStates.AUTOMATIC_REVERSAL_NOT_ALLOWED, otherwise false
    • markTransactionsIneligibleForAutomaticReversal

      protected List<PaymentTransaction> markTransactionsIneligibleForAutomaticReversal(@NonNull P payment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Parameters:
      payment - the Payment containing the PaymentTransactions to mark the management state for
      context - context information around sandbox and multitenant state
      Returns:
      the PaymentTransactions with the updated management state
    • validateUpdatePaymentRequest

      protected void validateUpdatePaymentRequest(@NonNull @NonNull Payment payment, @NonNull @NonNull UpdatePaymentRequest updatePaymentRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Validate that the updates provided by the UpdatePaymentRequest parameter will produce a valid Payment.
      Parameters:
      payment - The payment that is to be updated.
      updatePaymentRequest - The request to update a payment.
      contextInfo - Context information around sandbox and multitenant state
      Throws:
      InvalidUpdatePaymentRequestException - if the update payment request produced an invalid payment
    • buildPaymentValidationRequest

      protected com.broadleafcommerce.paymentgateway.domain.PaymentValidationRequest buildPaymentValidationRequest(@NonNull @NonNull Payment payment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • populateAddressesByType

      protected void populateAddressesByType(@NonNull @NonNull Payment payment, @NonNull @NonNull com.broadleafcommerce.paymentgateway.domain.PaymentValidationRequest paymentValidationRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • buildTransactions

      protected List<com.broadleafcommerce.paymentgateway.domain.PaymentTransaction> buildTransactions(@NonNull @NonNull Payment payment, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • setupPaymentForClone

      protected P setupPaymentForClone(P payment)
    • getMessage

      protected String getMessage(@NonNull @NonNull String errorMessage, @Nullable Object... args)
    • getApplicationIdFromContext

      @Nullable protected String getApplicationIdFromContext(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • getTenantIdFromContext

      @Nullable protected String getTenantIdFromContext(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • getPaymentService

      protected PaymentService<P> getPaymentService()
    • getPaymentLockService

      protected PaymentLockService<P> getPaymentLockService()
    • getPaymentTransactionService

      protected PaymentTransactionService<PaymentTransaction> getPaymentTransactionService()
    • getPaymentGatewayResourceProvider

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

      @Deprecated @Nullable protected CustomerPaymentAccountProvider<PaymentAccount> getPaymentAccountProvider()
      Deprecated.
      no longer used
    • getMessageSource

      protected org.springframework.context.MessageSource getMessageSource()
    • getTypeFactory

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

      protected PaymentSummaryService getPaymentSummaryService()
    • setPaymentSummaryService

      @Autowired public void setPaymentSummaryService(PaymentSummaryService paymentSummaryService)
    • getSavedPaymentMethodManagementService

      protected SavedPaymentMethodManagementService getSavedPaymentMethodManagementService()
    • setSavedPaymentMethodManagementService

      @Autowired public void setSavedPaymentMethodManagementService(SavedPaymentMethodManagementService savedPaymentMethodManagementService)