Class SubscriptionOperationUtils
java.lang.Object
com.broadleafcommerce.subscriptionoperation.service.SubscriptionOperationUtils
- Author:
- Nathan Moore (nathandmoore)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbeginningOfNextDay(@NonNull Instant date, String customerTimezone) protected InstantdelayDateBasedOnAdjustmentsForCustomLengthUnits(@NonNull String lengthUnits, int delayLength, ZonedDateTime originalNextBillZonedDateTime, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) determineEndOfTermsDate(@NonNull Instant startOfTermsDate, @NonNull String termDurationType, int termDurationLength, String customerTimeZone) protected InstantdetermineEndOfTermsDateForCustomDurationType(@NonNull Instant startOfTermsDate, String termDurationType, int termDurationLength) protected longdetermineNumberOfDaysInFullPeriod(@NonNull Instant periodStartDate, @NonNull SubscriptionPricingContext pricingContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) determineStartDateOfNextPeriod(@NonNull Instant periodStartDate, String periodType, int periodFrequency, boolean roundToMonthEnd, Instant endOfTermDate, String customerTimezone) Determines theInstantwhen the billing period subsequent to the givenperiodStartDatebegins.getDelayedDateBasedOnFreeTrial(@NonNull Instant originalDate, @NonNull List<com.broadleafcommerce.order.common.domain.Adjustment> adjustments, String timezoneString, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) getEndOfPreviousDay(@NonNull Instant nextDay, String customerTimezone) getFreeTrialEndDate(@NonNull Instant freeTrialStartDate, @NonNull List<com.broadleafcommerce.order.common.domain.Adjustment> adjustments, String customerTimezone, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines the free trial's end date based on the free trial start date & the free trial adjustment.protected intgetMonthsInCustomPeriodType(String periodType, int periodFrequency) Hook point for handling customDefaultSubscriptionPeriodTypevalues.protected longgetMonthsInPeriod(@NonNull String periodType, int periodFrequency) Determines the number of months in a billing period.protected longgetMonthsUntilEndOfTerm(@NonNull Instant periodStartDate, @NonNull Instant termEndDate, String customerTimezone) Determines the number of months until the end of the subscription's term.getNumberOfPeriodsLeftInTerm(SubscriptionPricingContext pricingContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) getNumberOfPeriodsLeftInTerm(String periodType, int periodFrequency, Instant periodStartDate, Instant termStartDate, Instant termEndDate, String customerTimezone) Determines the number of billing periods left after the current that are outstanding.getNumberOfPeriodsLeftInTerm(Instant periodStartDate, SubscriptionPricingContext pricingContext) Determines the number of billing periods left after the current that are outstanding.getPeriodStartDateAfterFreeTrialEnd(@NonNull SubscriptionPricingContext pricingContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets the start date of the next period after the free trial ends.Returns theZoneIdfor the given customer timezone string.booleanisSubscriptionInGracePeriod(@NonNull CancellationPolicyDetail cancellationPolicyDetail, @NonNull Subscription subscription) Determines whether the givenSubscriptionis in itscancellation grace period.booleanisSubscriptionInGracePeriod(@NonNull CancellationPolicyDetail cancellationPolicyDetail, @NonNull SubscriptionWithItems subscription) roundUpToTheEndOfMonth(@NonNull Instant date, String customerTimezone) Rounds the givenInstantto the end of the month.
-
Constructor Details
-
SubscriptionOperationUtils
public SubscriptionOperationUtils()
-
-
Method Details
-
isSubscriptionInGracePeriod
public boolean isSubscriptionInGracePeriod(@NonNull @NonNull CancellationPolicyDetail cancellationPolicyDetail, @NonNull @NonNull Subscription subscription) Determines whether the givenSubscriptionis in itscancellation grace period. This is based on theCancellationPolicyDetailthat matches it.The grace period is calculated from the last auto-renewal period. For subscriptions with terms, this is from the end of the last term. Otherwise, this is from the end of the last billing period.
- Parameters:
cancellationPolicyDetail- TheCancellationPolicyDetaildescribing the grace period, if a grace period is supported.subscription- TheSubscriptionthat may be in the grace period.- Returns:
- Whether the given
subscriptionis in its cancellation policy's grace period.
-
isSubscriptionInGracePeriod
public boolean isSubscriptionInGracePeriod(@NonNull @NonNull CancellationPolicyDetail cancellationPolicyDetail, @NonNull @NonNull SubscriptionWithItems subscription) -
determineEndOfTermsDate
-
getFreeTrialEndDate
@Nullable public Instant getFreeTrialEndDate(@NonNull @NonNull Instant freeTrialStartDate, @NonNull @NonNull List<com.broadleafcommerce.order.common.domain.Adjustment> adjustments, @Nullable String customerTimezone, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines the free trial's end date based on the free trial start date & the free trial adjustment.- Parameters:
freeTrialStartDate- the free trial's start date.adjustments- theAdjustmentscontaining a free trial.customerTimezone- the customer timezone if presentcontextInfo- context surrounding the multi-tenant state- Returns:
- The free trial end date if a free trial adjustment is found, null otherwise.
-
getDelayedDateBasedOnFreeTrial
public Instant getDelayedDateBasedOnFreeTrial(@NonNull @NonNull Instant originalDate, @NonNull @NonNull List<com.broadleafcommerce.order.common.domain.Adjustment> adjustments, @Nullable String timezoneString, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Parameters:
originalDate- the original date to delay.adjustments- theAdjustments to consider for delaying the date.timezoneString- the timezone for the customer if presentcontextInfo- context surrounding the multi-tenant state- Returns:
- the delayed date based on the adjustments.
-
getPeriodStartDateAfterFreeTrialEnd
public Instant getPeriodStartDateAfterFreeTrialEnd(@NonNull @NonNull SubscriptionPricingContext pricingContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets the start date of the next period after the free trial ends. Since the free trial end date is 1 nanosecond before the next day, we need to add 1 nanosecond to get the start date.- Parameters:
pricingContext- the current pricing context- Returns:
- the start date of the next period after the free trial ends
-
determineStartDateOfNextPeriod
public Instant determineStartDateOfNextPeriod(@NonNull @NonNull Instant periodStartDate, String periodType, int periodFrequency, boolean roundToMonthEnd, @Nullable Instant endOfTermDate, @Nullable String customerTimezone) Determines theInstantwhen the billing period subsequent to the givenperiodStartDatebegins. By default, this adds the length of a period inChronoUnit.MONTHSto theperiodStartDatesince that is the smallest typical unit for a billing period.- Parameters:
periodStartDate- A reference period startInstantfrom which to derive the previous period's startInstant.periodType- The type of billing period, e.g.,DefaultSubscriptionPeriodType.periodFrequency- The frequency for billing, e.g., 3 for every 3 months.roundToMonthEnd- Whether to round the day to the end of the month- Returns:
- The
Instantwhen the billing period subsequent to the givenperiodStartDatebegins.
-
roundUpToTheEndOfMonth
public Instant roundUpToTheEndOfMonth(@NonNull @NonNull Instant date, @Nullable String customerTimezone) Rounds the givenInstantto the end of the month. -
getNumberOfPeriodsLeftInTerm
public Optional<Long> getNumberOfPeriodsLeftInTerm(SubscriptionPricingContext pricingContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getNumberOfPeriodsLeftInTerm
public Optional<Long> getNumberOfPeriodsLeftInTerm(Instant periodStartDate, SubscriptionPricingContext pricingContext) Determines the number of billing periods left after the current that are outstanding. It is assumed that the term length is a multiple of the period length in months.- Parameters:
periodStartDate- the period start date truncated to DAYS to start the calculationpricingContext- TheSubscriptionPricingContext- Returns:
- The number billings left after the current that are unbilled.
-
getNumberOfPeriodsLeftInTerm
public Optional<Long> getNumberOfPeriodsLeftInTerm(String periodType, int periodFrequency, Instant periodStartDate, @Nullable Instant termStartDate, @Nullable Instant termEndDate, @Nullable String customerTimezone) Determines the number of billing periods left after the current that are outstanding. It is assumed that the term length is a multiple of the period length in months.- Parameters:
periodType- The type of billing period, e.g.,DefaultSubscriptionPeriodType.periodFrequency- The frequency for billing, e.g., 3 for every 3 months.periodStartDate- the period start date truncated to DAYS to start the calculationtermStartDate- The start of the subscription's term.termEndDate- The end of the subscription's term.customerTimezone- The customer's timezone, if present- Returns:
- The number billings left after the current that are unbilled.
-
beginningOfNextDay
-
getEndOfPreviousDay
-
getZoneId
Returns theZoneIdfor the given customer timezone string. If the timezone is null, it defaults toZoneOffset.UTC.- Parameters:
customerTimezone- the customer's timezone ID- Returns:
- the resolved
ZoneId - Throws:
IllegalArgumentException- if the provided timezone ID is invalid
-
delayDateBasedOnAdjustmentsForCustomLengthUnits
protected Instant delayDateBasedOnAdjustmentsForCustomLengthUnits(@NonNull @NonNull String lengthUnits, int delayLength, ZonedDateTime originalNextBillZonedDateTime, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
determineEndOfTermsDateForCustomDurationType
-
getMonthsUntilEndOfTerm
protected long getMonthsUntilEndOfTerm(@NonNull @NonNull Instant periodStartDate, @NonNull @NonNull Instant termEndDate, @Nullable String customerTimezone) Determines the number of months until the end of the subscription's term.- Parameters:
periodStartDate- The start of the subscription's term.termEndDate- The end of the subscription's term.- Returns:
- The number of days in a subscription's terms.
-
getMonthsInPeriod
Determines the number of months in a billing period.- Parameters:
periodType- The type of billing period, e.g.,DefaultSubscriptionPeriodType.periodFrequency- The frequency for billing, e.g., 3 for every 3 months.- Returns:
- The number of months in a billing period.
- See Also:
-
getMonthsInCustomPeriodType
Hook point for handling customDefaultSubscriptionPeriodTypevalues.- Parameters:
periodType- The type of billing period, e.g.,DefaultSubscriptionPeriodType.periodFrequency- The frequency for billing, e.g., 3 for every 3 months.- Returns:
- The number of months in a billing period.
- See Also:
-
determineNumberOfDaysInFullPeriod
protected long determineNumberOfDaysInFullPeriod(@NonNull @NonNull Instant periodStartDate, @NonNull @NonNull SubscriptionPricingContext pricingContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-