Class DefaultBillingEventService<P extends BillingEvent,Q extends BillingEventDTO,R extends CreateBillingEventRequest>
java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.billing.service.impl.DefaultBillingEventService<P,Q,R>
- All Implemented Interfaces:
BillingEventService<P,,Q, R> com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>
public class DefaultBillingEventService<P extends BillingEvent,Q extends BillingEventDTO,R extends CreateBillingEventRequest>
extends com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
implements BillingEventService<P,Q,R>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BillingEventAddressService<BillingEventAddress>protected BillingEventPaymentService<BillingEventPayment,BillingEventPaymentWithEvent, BillingEventDTO, BillingEventPaymentWithTransaction> protected BillingTaxDetailService<BillingTaxDetail>protected BillingPropertiesprotected com.broadleafcommerce.common.extension.TypeFactory -
Constructor Summary
ConstructorsConstructorDescriptionDefaultBillingEventService(BillingEventRepository<com.broadleafcommerce.data.tracking.core.Trackable> repo, com.broadleafcommerce.data.tracking.core.service.CrudEntityHelper helper) -
Method Summary
Modifier and TypeMethodDescriptionprotected longapplyDifferenceToAdjustAmount(BillingEventItem billingEventItem, long numApplicationsNeeded, BigDecimal unitAmount, BillingEventItemAdjustment billingEventItemAdjustment) protected QbuildBillingEventDTO(P billingEvent, boolean deepFind, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected BillingEventItemAdjustmentbuildProratedEventItemAdjustment(BillingEventItem billingEventItem, BigDecimal proratedAdjustmentAmount, BillingEventAdjustment billingEventAdjustment) Create the BillingEventItemAdjustment for the prorated BillingEventAdjustmentsprotected BigDecimalcalculateItemsTotalUnitPrice(List<BillingEventItemWithTaxDetails> billingEventItemWithTransaction) convertToCreateBillingEventRequest(Q billingEventDTO) Converts aBillingEventServiceinto a more appropriate for creationcreation requestprotected longcountNumberOfUnits(BigDecimal difference) Creates aBillingEventand related objectsprotected PcreateBillingEventAddress(R request, P billingEvent, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Creates aBillingEventAddressfrom the given requestprotected List<BillingEventAdjustment>createBillingEventAdjustments(R request, P createdBillingEvent, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Creates a list ofBillingEventAdjustmentfrom the given requestprotected voidcreateBillingEventItems(R request, P createdBillingEvent, List<BillingEventAdjustment> billingEventAdjustments, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Creates a list ofBillingEventItemfrom the given request.protected voidcreateBillingEventPayments(R request, P billingEventDomain, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Creates a list ofBillingEventPaymentfrom the given requestcreateFromExternalRequest(@NonNull List<R> createRequests, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Accepts a list ofcreate requeststhat came from an external source, performs validation and then delegates toCrudEntityService.createAll(List, ContextInfo)to create billing events and related objectscreateFromExternalRequest(R createRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Accepts acreate requestthat came from an external source, performs validation and then delegates toBillingEventService.create(CreateBillingEventRequest, ContextInfo)to create a billing event and related objectsfindBySubscriptionRefIn(List<String> subscriptionIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads allBillingEvententities by subscription reference IDsprotected voidfixRoundingIssueWithAdjustments(List<BillingEventItemWithTaxDetails> billingEventItemWithTaxDetailsList, BigDecimal totalProratedAdjustmentAmount, BigDecimal totalBillingEventAdjustmentsAmount) Fix the adding or removing of the pennies from the Item unit price if the prorated adjustment doesn't match the total adjustment amountprotected BigDecimalgenerateProratedEventItemAdjustments(List<BillingEventAdjustment> billingEventAdjustments, List<BillingEventItemWithTaxDetails> billingEventItemWithTaxDetailsList) Calculate the prorated adjustment amount by multiplying from BillingEventAdjustment#adjustmentAmount with BillingEventItem#itemUnitPrice and divide by total BillingEventItems * quantity and sum all the prorated adjustment amountsprotected List<BillingEventItemWithTaxDetails>getBillingEventItemsWithTaxDetails(P billingEvent, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected List<BillingEventPaymentWithTransaction>getBillingEventsPaymentWithTransactions(P billingEvent, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected BigDecimalgetUnitAmount(BigDecimal difference) Returns the unit amount (e.g.readAllByContextId(Iterable<String> ids, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) readBillingEventDTOByUserRef(String userRef, boolean deepFind, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Readbilling eventsby userId.readBillingEventDTOsByIds(Set<String> ids, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds billing events containing an ID inids.readBillingEventDTOsBySubscriptionRef(String subscriptionRef, boolean deepFind, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) ReadsBillingEvententities by subscription id.readBillingEventDTOsBySubscriptionRefs(Set<String> subscriptionRefs, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads container objects,BillingEventDTO, by subscription idorg.springframework.data.domain.Page<Q>readBillingEventsForSubscriptionRefAndPeriodGreaterThanEqual(@NonNull String subscriptionRef, @NonNull Integer requestedPeriod, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads all theBillingEventby subscription Id, where theBillingEvent.getSubscriptionPeriod()is greater than or equals to the provided period.readByIdWithDetails(String id, boolean deepFind, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns abilling event details containerfor aBillingEventwith the given id.readByOrderRef(String orderRef, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds billing events by order reference.readBySubscriptionRef(String subscriptionRef, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads allBillingEvententities by subscription referencereadByUserRef(String userRef, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) ReadBillingEvententities by userRefprotected RsanitizeExternalCreateRequest(R createRequest) updateBillingDetails(List<Q> billingEventDTOs, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) updateBillingDetails(Q billingEventDTO, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService
convertFromPersistentDomain, convertToPersistentDomain, create, createAll, createAllAllowingPartialSuccess, delete, getHelper, getRepository, getSortPositionStrategy, readAll, readAll, readAll, readByContextId, replace, replaceAll, replaceAllAllowingPartialSuccess, setSortPositionStrategy, update, updateAll, updateAllAllowingPartialSuccess, updateSortMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.billing.service.BillingEventService
createBillingEvent, findBillingEventByUserId, findBillingEventByUserId, findBillingEventsByIds, findBillingEventsBySubscriptionId, findBillingEventsBySubscriptionId, findBillingEventsBySubscriptionIds, findById, findById, findByOrderReference, updateAllBillingDetails, updateBillingDetailsFromBillingEvent, updateBillingEventMethods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService
create, createAll, createAllAllowingPartialSuccess, delete, readAll, readAll, readAll, readByContextId, replace, replaceAll, replaceAllAllowingPartialSuccess, update, updateAll, updateAllAllowingPartialSuccess, updateSort
-
Field Details
-
paymentTransactionService
@Autowired protected PaymentTransactionDetailService<PaymentTransactionDetail> paymentTransactionService -
billingEventItemService
@Autowired protected BillingEventItemService<BillingEventItem,BillingEventItemWithTaxDetails> billingEventItemService -
billingEventAddressService
-
billingTaxDetailService
-
billingEventPaymentService
@Autowired protected BillingEventPaymentService<BillingEventPayment,BillingEventPaymentWithEvent, billingEventPaymentServiceBillingEventDTO, BillingEventPaymentWithTransaction> -
billingEventAdjustmentService
@Autowired protected BillingEventAdjustmentService<BillingEventAdjustment> billingEventAdjustmentService -
billingEventItemAdjustmentService
@Autowired protected BillingEventItemAdjustmentService<BillingEventItemAdjustment> billingEventItemAdjustmentService -
typeFactory
@Autowired protected com.broadleafcommerce.common.extension.TypeFactory typeFactory -
properties
-
-
Constructor Details
-
DefaultBillingEventService
public DefaultBillingEventService(BillingEventRepository<com.broadleafcommerce.data.tracking.core.Trackable> repo, com.broadleafcommerce.data.tracking.core.service.CrudEntityHelper helper)
-
-
Method Details
-
readAllByContextId
public Iterable<P> readAllByContextId(Iterable<String> ids, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
readAllByContextIdin interfacecom.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends BillingEvent>- Overrides:
readAllByContextIdin classcom.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends BillingEvent>
-
readByIdWithDetails
public Optional<Q> readByIdWithDetails(String id, boolean deepFind, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:BillingEventServiceReturns abilling event details containerfor aBillingEventwith the given id. The 'deepFind' param of true will also obtain:- BillingEventDTO.billingEventPaymentWithTransactions
- BillingEventDTO.billingEventItemWithTaxDetails
- BillingEventDTO.billingEventAddress
- Specified by:
readByIdWithDetailsin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest>
-
readBillingEventDTOsByIds
public List<Q> readBillingEventDTOsByIds(Set<String> ids, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:BillingEventServiceFinds billing events containing an ID inids. Returns them in container objects -BillingEventDTO- Specified by:
readBillingEventDTOsByIdsin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest>
-
readByUserRef
public List<P> readByUserRef(String userRef, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:BillingEventServiceReadBillingEvententities by userRef- Specified by:
readByUserRefin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest>
-
readBillingEventDTOByUserRef
public List<Q> readBillingEventDTOByUserRef(String userRef, boolean deepFind, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:BillingEventServiceReadbilling eventsby userId. The 'deepFind' param of true will also obtain:- BillingEventDTO.billingEventPaymentWithTransactions
- BillingEventDTO.billingEventItemWithTaxDetails
- BillingEventDTO.billingEventAddress
Regardless, it returns container objects -
BillingEventDTO.
- Specified by:
readBillingEventDTOByUserRefin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest>
-
create
@Transactional public P create(Q billingEventDTO, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:BillingEventService- Specified by:
createin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest> - Parameters:
billingEventDTO- a DTO that holds objects related to a billing eventcontextInfo- context information around multi-tenant state- Returns:
- a created billing event
-
createFromExternalRequest
@Transactional public P createFromExternalRequest(R createRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:BillingEventServiceAccepts acreate requestthat came from an external source, performs validation and then delegates toBillingEventService.create(CreateBillingEventRequest, ContextInfo)to create a billing event and related objects- Specified by:
createFromExternalRequestin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest> - Parameters:
createRequest- a request to create a billing event and related objectscontextInfo- context information around multi-tenant state- Returns:
- a created billing event
-
createFromExternalRequest
@Transactional public List<P> createFromExternalRequest(@NonNull @NonNull List<R> createRequests, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:BillingEventServiceAccepts a list ofcreate requeststhat came from an external source, performs validation and then delegates toCrudEntityService.createAll(List, ContextInfo)to create billing events and related objects- Specified by:
createFromExternalRequestin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest> - Parameters:
createRequests- a list of requests to create billing events and related objectscontextInfo- context information around multi-tenant state- Returns:
- a list of created billing events
-
create
@Transactional public P create(R createRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:BillingEventServiceCreates aBillingEventand related objects- Specified by:
createin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest> - Parameters:
createRequest- a request to create a billing event and related objectscontextInfo- context information around multi-tenant state- Returns:
- a created billing event
-
sanitizeExternalCreateRequest
-
updateBillingDetails
@Transactional public List<Q> updateBillingDetails(List<Q> billingEventDTOs, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
updateBillingDetailsin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest>
-
updateBillingDetails
@Transactional public Q updateBillingDetails(Q billingEventDTO, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
updateBillingDetailsin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest>
-
readBySubscriptionRef
public List<P> readBySubscriptionRef(String subscriptionRef, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:BillingEventServiceReads allBillingEvententities by subscription reference- Specified by:
readBySubscriptionRefin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest>
-
findBySubscriptionRefIn
public List<P> findBySubscriptionRefIn(List<String> subscriptionIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:BillingEventServiceReads allBillingEvententities by subscription reference IDs- Specified by:
findBySubscriptionRefInin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest>
-
readBillingEventDTOsBySubscriptionRef
public List<Q> readBillingEventDTOsBySubscriptionRef(String subscriptionRef, boolean deepFind, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:BillingEventServiceReadsBillingEvententities by subscription id. If 'deepFind' is true, it will also obtain:- BillingEventDTO.billingEventPaymentWithTransactions
- BillingEventDTO.billingEventItemWithTaxDetails
- BillingEventDTO.billingEventAddress
BillingEventDTO.- Specified by:
readBillingEventDTOsBySubscriptionRefin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest>
-
readBillingEventsForSubscriptionRefAndPeriodGreaterThanEqual
public org.springframework.data.domain.Page<Q> readBillingEventsForSubscriptionRefAndPeriodGreaterThanEqual(@NonNull @NonNull String subscriptionRef, @NonNull @NonNull Integer requestedPeriod, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:BillingEventServiceReads all theBillingEventby subscription Id, where theBillingEvent.getSubscriptionPeriod()is greater than or equals to the provided period.- Specified by:
readBillingEventsForSubscriptionRefAndPeriodGreaterThanEqualin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest> - Parameters:
subscriptionRef- the subscription idrequestedPeriod- theSubscription'speriod that correlates to thisBillingEventpage- information about which page of results to return from the databasecontextInfo- Context information for data tracking.- Returns:
- a page container objects -
BillingEventDTOwith additional details
-
readBillingEventDTOsBySubscriptionRefs
public List<Q> readBillingEventDTOsBySubscriptionRefs(Set<String> subscriptionRefs, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:BillingEventServiceReads container objects,BillingEventDTO, by subscription id- Specified by:
readBillingEventDTOsBySubscriptionRefsin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest>
-
readByOrderRef
public List<P> readByOrderRef(String orderRef, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:BillingEventServiceFinds billing events by order reference.- Specified by:
readByOrderRefin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest>
-
convertToCreateBillingEventRequest
Description copied from interface:BillingEventServiceConverts aBillingEventServiceinto a more appropriate for creationcreation request- Specified by:
convertToCreateBillingEventRequestin interfaceBillingEventService<P extends BillingEvent,Q extends BillingEventDTO, R extends CreateBillingEventRequest> - Parameters:
billingEventDTO- a DTO that holds objects related to a billing event- Returns:
- built creation request
-
buildBillingEventDTO
-
getBillingEventsPaymentWithTransactions
protected List<BillingEventPaymentWithTransaction> getBillingEventsPaymentWithTransactions(P billingEvent, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getBillingEventItemsWithTaxDetails
protected List<BillingEventItemWithTaxDetails> getBillingEventItemsWithTaxDetails(P billingEvent, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
generateProratedEventItemAdjustments
protected BigDecimal generateProratedEventItemAdjustments(List<BillingEventAdjustment> billingEventAdjustments, List<BillingEventItemWithTaxDetails> billingEventItemWithTaxDetailsList) Calculate the prorated adjustment amount by multiplying from BillingEventAdjustment#adjustmentAmount with BillingEventItem#itemUnitPrice and divide by total BillingEventItems * quantity and sum all the prorated adjustment amounts -
calculateItemsTotalUnitPrice
protected BigDecimal calculateItemsTotalUnitPrice(List<BillingEventItemWithTaxDetails> billingEventItemWithTransaction) -
fixRoundingIssueWithAdjustments
protected void fixRoundingIssueWithAdjustments(List<BillingEventItemWithTaxDetails> billingEventItemWithTaxDetailsList, BigDecimal totalProratedAdjustmentAmount, BigDecimal totalBillingEventAdjustmentsAmount) Fix the adding or removing of the pennies from the Item unit price if the prorated adjustment doesn't match the total adjustment amount -
buildProratedEventItemAdjustment
protected BillingEventItemAdjustment buildProratedEventItemAdjustment(BillingEventItem billingEventItem, BigDecimal proratedAdjustmentAmount, BillingEventAdjustment billingEventAdjustment) Create the BillingEventItemAdjustment for the prorated BillingEventAdjustments -
applyDifferenceToAdjustAmount
protected long applyDifferenceToAdjustAmount(BillingEventItem billingEventItem, long numApplicationsNeeded, BigDecimal unitAmount, BillingEventItemAdjustment billingEventItemAdjustment) -
createBillingEventAddress
protected P createBillingEventAddress(R request, P billingEvent, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Creates aBillingEventAddressfrom the given request -
createBillingEventItems
protected void createBillingEventItems(R request, P createdBillingEvent, @Nullable List<BillingEventAdjustment> billingEventAdjustments, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Creates a list ofBillingEventItemfrom the given request. Possibly will createtax detailsrelated to the items. -
createBillingEventAdjustments
@Nullable protected List<BillingEventAdjustment> createBillingEventAdjustments(R request, P createdBillingEvent, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Creates a list ofBillingEventAdjustmentfrom the given request -
createBillingEventPayments
protected void createBillingEventPayments(R request, P billingEventDomain, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Creates a list ofBillingEventPaymentfrom the given request -
countNumberOfUnits
-
getUnitAmount
Returns the unit amount (e.g. .01 for US)
-