Class DefaultSavedPaymentMethodService<P extends SavedPaymentMethod>

java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
com.broadleafcommerce.paymenttransaction.service.DefaultSavedPaymentMethodService<P>
All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>, SavedPaymentMethodService<P>

public class DefaultSavedPaymentMethodService<P extends SavedPaymentMethod> extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P> implements SavedPaymentMethodService<P>
  • Constructor Details

    • DefaultSavedPaymentMethodService

      public DefaultSavedPaymentMethodService(SavedPaymentMethodRepository<com.broadleafcommerce.data.tracking.core.Trackable> savedPaymentMethodRepository, com.broadleafcommerce.paymentgateway.service.provider.PaymentGatewayResourceProvider paymentGatewayResourceProvider, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
  • Method Details

    • createSavedPaymentMethod

      public P createSavedPaymentMethod(@NonNull @NonNull CreateSavedPaymentMethodRequest createRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SavedPaymentMethodService
      Specified by:
      createSavedPaymentMethod in interface SavedPaymentMethodService<P extends SavedPaymentMethod>
      Parameters:
      createRequest - the CreateSavedPaymentMethodRequest to create a SavedPaymentMethod from
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      the newly created saved payment method
    • create

      public P create(@NonNull P instance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Specified by:
      create in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends SavedPaymentMethod>
      Overrides:
      create in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends SavedPaymentMethod>
    • readAllByOwningUserTypeAndOwningUserId

      public org.springframework.data.domain.Page<P> readAllByOwningUserTypeAndOwningUserId(@NonNull @NonNull String ownerType, @NonNull @NonNull String ownerId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo, @Nullable org.springframework.data.domain.Pageable page, @Nullable cz.jirutka.rsql.parser.ast.Node filters)
      Description copied from interface: SavedPaymentMethodService
      Specified by:
      readAllByOwningUserTypeAndOwningUserId in interface SavedPaymentMethodService<P extends SavedPaymentMethod>
      Parameters:
      ownerType - the type of the owning user
      ownerId - the ID of the owning user
      contextInfo - context information surrounding sandboxing and multitenant state
      page - the requested page of results from the database
      filters - An RSQL filter used to narrow query results. May be EmptyNode if no filters should be applied
      Returns:
      the SavedPaymentMethods based on the given SavedPaymentMethod.getOwningUserType() and SavedPaymentMethod.getOwningUserId()
    • readAllAvailableToUseByOwningUserTypeAndOwningUserId

      public org.springframework.data.domain.Page<P> readAllAvailableToUseByOwningUserTypeAndOwningUserId(@NonNull @NonNull String owningUserType, @NonNull @NonNull String owningUserId, @Nullable org.springframework.data.domain.Pageable page, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SavedPaymentMethodService
      Finds all the saved payment methods available to use.
      Specified by:
      readAllAvailableToUseByOwningUserTypeAndOwningUserId in interface SavedPaymentMethodService<P extends SavedPaymentMethod>
      Parameters:
      owningUserType - the type of the owning user
      owningUserId - the ID of the owning user
      page - the requested page of results from the database
      filters - An RSQL filter used to narrow query results. May be EmptyNode if no filters should be applied
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      the saved payment methods available to use
    • readAllByOriginatingPaymentId

      public List<P> readAllByOriginatingPaymentId(@NonNull @NonNull List<String> originatingPaymentIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SavedPaymentMethodService
      Specified by:
      readAllByOriginatingPaymentId in interface SavedPaymentMethodService<P extends SavedPaymentMethod>
      Parameters:
      originatingPaymentIds - the payment IDs to query SavedPaymentMethod.getOriginatingPaymentId() against
      contextInfo - context information regarding sandboxing and multitenant state
      Returns:
      all the SavedPaymentMethods matching the given SavedPaymentMethod.getOriginatingPaymentId()
    • readSavedPaymentMethodsByContextId

      public List<P> readSavedPaymentMethodsByContextId(@NonNull @NonNull List<String> ids, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SavedPaymentMethodService
      Specified by:
      readSavedPaymentMethodsByContextId in interface SavedPaymentMethodService<P extends SavedPaymentMethod>
      Parameters:
      ids - the saved payment method IDs to query
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      the saved payment methods matching the given ids
    • updateSavedPaymentMethod

      public P updateSavedPaymentMethod(@NonNull @NonNull String savedPaymentMethodId, @NonNull @NonNull UpdateSavedPaymentMethodRequest updateRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SavedPaymentMethodService
      Updates the SavedPaymentMethod based on the given UpdateSavedPaymentMethodRequest.
      Specified by:
      updateSavedPaymentMethod in interface SavedPaymentMethodService<P extends SavedPaymentMethod>
      Parameters:
      savedPaymentMethodId - the SavedPaymentMethod.getId() to update
      updateRequest - the UpdateSavedPaymentMethodRequest containing the updates
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      the updated SavedPaymentMethod
    • update

      public P update(@NonNull @NonNull String id, @NonNull P updated, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Specified by:
      update in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends SavedPaymentMethod>
      Overrides:
      update in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends SavedPaymentMethod>
    • readAllByOwningUserTypeAndOwningUserIdAndTenantId

      public org.springframework.data.domain.Page<P> readAllByOwningUserTypeAndOwningUserIdAndTenantId(String owningUserType, String owningUserId, String tenantId, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: SavedPaymentMethodService
      Find a page of SavedPaymentMethods for the given owner type, owner id and tenant id.
      Specified by:
      readAllByOwningUserTypeAndOwningUserIdAndTenantId in interface SavedPaymentMethodService<P extends SavedPaymentMethod>
      Parameters:
      owningUserType - The type of the saved payment's owning user
      owningUserId - The id of the entity that owns this saved payment method
      tenantId - The ID of the Tenant the payments belong to.
      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.
    • readAllForAccount

      public org.springframework.data.domain.Page<P> readAllForAccount(String accountId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SavedPaymentMethodService
      Find a page of SavedPaymentMethods for the given account and its parent accounts This method is for B2B use cases where the SavedPaymentMethod.getOwningUserType() is DefaultSavedPaymentMethodOwningUserTypes.BLC_ACCOUNT.
      Specified by:
      readAllForAccount in interface SavedPaymentMethodService<P extends SavedPaymentMethod>
      Parameters:
      accountId - The id of the entity's account\
      filters - additional filters to apply in the query.
      page - the requested page of results from the database
      contextInfo - the context info
      Returns:
      a page of payments for the given account and parent accounts
    • readByIdForAccount

      public Optional<P> readByIdForAccount(String id, String accountId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SavedPaymentMethodService
      Find a SavedPaymentMethod given its payment id, account and its parent accounts This method is for B2B use cases where the SavedPaymentMethod.getOwningUserType() is DefaultSavedPaymentMethodOwningUserTypes.BLC_ACCOUNT.
      Specified by:
      readByIdForAccount in interface SavedPaymentMethodService<P extends SavedPaymentMethod>
      Parameters:
      id - The id of the payment
      accountId - The id of the entity's account
      contextInfo - the context info
      Returns:
      A payment for the given payment id, account id, and parent accounts
    • readByGatewayReferenceId

      public Optional<P> readByGatewayReferenceId(@NonNull @NonNull String gatewayReferenceId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SavedPaymentMethodService
      Find a saved payment method for the specified gateway reference id.
      Specified by:
      readByGatewayReferenceId in interface SavedPaymentMethodService<P extends SavedPaymentMethod>
      Parameters:
      gatewayReferenceId - the gateway reference id
      contextInfo - context information regarding sandboxing and multitenant state
      Returns:
      a list of saved payments matching the list of originating payment ids.
    • deleteSavedPaymentMethod

      public void deleteSavedPaymentMethod(@NonNull P savedPaymentMethod, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: SavedPaymentMethodService
      Deletes the saved payment method.
      Specified by:
      deleteSavedPaymentMethod in interface SavedPaymentMethodService<P extends SavedPaymentMethod>
      Parameters:
      savedPaymentMethod - the saved payment method id to delete
      contextInfo - the context info
    • resetExistingDefaultPaymentFlags

      protected List<P> resetExistingDefaultPaymentFlags(@Nullable String newDefaultSavedPaymentId, @NonNull @NonNull String owningUserType, @NonNull @NonNull String owningUserId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Retrieves any existing SavedPaymentMethods and set SavedPaymentMethod.isDefaultForOwner() to false.

      This is typically used when creating or updating a SavedPaymentMethod to be the default payment method.

      Parameters:
      newDefaultSavedPaymentId - the id of the new default SavedPaymentMethod. Should be null if the new default SavedPaymentMethod has not yet been created
      owningUserType - the SavedPaymentMethod.getOwningUserType() to identify the payments with
      owningUserId - the SavedPaymentMethod.getOwningUserId() to identify the payments with
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      a list of updated SavedPaymentMethods
    • toUpdates

      protected List<com.broadleafcommerce.data.tracking.core.service.Update<P>> toUpdates(@NonNull @NonNull Collection<P> savedPayments)
    • buildSavedPaymentMethod

      protected P buildSavedPaymentMethod(@NonNull @NonNull CreateSavedPaymentMethodRequest createRequest)
      Parameters:
      createRequest - the CreateSavedPaymentMethodRequest to build the SavedPaymentMethod from
      Returns:
      a built SavedPaymentMethod from the given CreateSavedPaymentMethodRequest
    • 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)
    • modifyPaymentMethodPropertiesForCreate

      protected P modifyPaymentMethodPropertiesForCreate(@NonNull @NonNull CreateSavedPaymentMethodRequest createRequest, @NonNull P savedPayment, @Nullable String tenantId, @Nullable String applicationId)
      A hook method that can be used by a gateway implementation to modify the payment method properties before creation the saved payment method. For example, this can be used to create a multi-use token for future use to execute transactions.
      Parameters:
      createRequest - the CreateSavedPaymentMethodRequest to get a single-use token
      savedPayment - a SavedPaymentMethod
      tenantId - the id for the current tenant
      applicationId - the id for the current application
      Returns:
      the saved payment method with updated payment method properties
    • modifyPaymentMethodPropertiesForUpdate

      protected P modifyPaymentMethodPropertiesForUpdate(@NonNull P originalSavedPaymentMethod, @NonNull P updatedSavedPaymentMethod, @Nullable String applicationId, @Nullable String tenantId)
      A hook method that can be used by a gateway implementation to modify the payment method properties before updating the saved payment method. For example, this can be used to update a multi-use token for future use to execute transactions.
      Parameters:
      originalSavedPaymentMethod - a SavedPaymentMethod
      updatedSavedPaymentMethod - the UpdateSavedPaymentMethodRequest
      applicationId - the id for the current application
      tenantId - the id for the current tenant
      Returns:
    • deleteGatewaySavedPaymentMethod

      protected void deleteGatewaySavedPaymentMethod(@NonNull P savedPaymentMethod, @Nullable String applicationId, @Nullable String tenantId)
      A hook method that can be used by a gateway implementation to modify the payment method properties before deleting the saved payment method. For example, this can be used to delete a multi-use token.
      Parameters:
      savedPaymentMethod - a SavedPaymentMethod
      applicationId - the id for the current application
      tenantId - the id for the current tenant
    • populateSavedPaymentMethodUpdates

      protected P populateSavedPaymentMethodUpdates(@NonNull P savedPayment, @NonNull @NonNull UpdateSavedPaymentMethodRequest updateRequest)
      Populates the updates from UpdateSavedPaymentMethodRequest to the given SavedPaymentMethod.
      Parameters:
      savedPayment - the SavedPaymentMethod to update
      updateRequest - the UpdateSavedPaymentMethodRequest containing all the SavedPaymentMethod updates
      Returns:
      the update SavedPaymentMethod based on the given UpdateSavedPaymentMethodRequest
    • updateStatusAndAction

      protected void updateStatusAndAction(@NonNull P savedPayment, @NonNull @NonNull UpdateSavedPaymentMethodRequest updateRequest)
    • determineSavedPaymentMethodStatus

      @Nullable protected String determineSavedPaymentMethodStatus(@NonNull @NonNull SavedPaymentMethodNextAction nextAction)
    • sendCustomerNotificationIfNeeded

      protected void sendCustomerNotificationIfNeeded(@NonNull P savedPaymentMethod, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Sends the customer notification built by PaymentGatewaySavedPaymentMethodService.buildCustomerNotification(SavedPaymentMethodInfo, String, String) to the notification service.
      Parameters:
      savedPaymentMethod - the saved payment method
      contextInfo - context information around sandbox and multitenant state
    • buildSavedPaymentMethodInfo

      protected com.broadleafcommerce.paymentgateway.domain.SavedPaymentMethodInfo buildSavedPaymentMethodInfo(@NonNull P savedPaymentMethod, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Builds the saved payment info that is needed to build the customer notification.
      Parameters:
      savedPaymentMethod - the saved payment method
      contextInfo - context information around sandbox and multitenant state
      Returns:
      the saved payment method info
    • getSavedPaymentMethodRepository

      protected SavedPaymentMethodRepository<com.broadleafcommerce.data.tracking.core.Trackable> getSavedPaymentMethodRepository()
    • getPaymentGatewayResourceProvider

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

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

      protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils getAuthenticationUtils()
    • setAuthenticationUtils

      @Autowired public void setAuthenticationUtils(com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils)
    • getSavedPaymentMethodVersionValidationService

      protected SavedPaymentMethodVersionValidationService getSavedPaymentMethodVersionValidationService()
    • setSavedPaymentMethodVersionValidationService

      @Autowired public void setSavedPaymentMethodVersionValidationService(SavedPaymentMethodVersionValidationService savedPaymentMethodVersionValidationService)
    • getCustomerNotificationService

      protected PaymentCustomerNotificationService getCustomerNotificationService()
    • setCustomerNotificationService

      @Autowired public void setCustomerNotificationService(PaymentCustomerNotificationService customerNotificationService)