Class SubscriptionUtils
java.lang.Object
com.broadleafcommerce.subscription.service.SubscriptionUtils
Utility methods related to subscription handling.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic InstantgetBeginningOfNextDay(@NonNull Instant startDate, String timezone) Gets the beginning of the next day from the givenInstant.static DategetBeginningOfNextDay(@NonNull Date startDate, String timezone) Gets the beginning of the next day from the givenInstant.protected static longgetCurrentPeriod(@NonNull Instant termStartDate, long monthsInPeriod, String customerTimezone) Determines which billing period the subscription is currently in given theSubscription.getStartOfTermDate().protected static longgetMonthsUntilEndOfTerm(@NonNull Instant termStartDate, @NonNull Instant termEndDate, String customerTimezone) Determines the number of months in a subscription's terms.getNumberOfPeriodsLeftInTerm(String periodType, int periodFrequency, Instant termStartDate, Instant termEndDate, String customerTimezone) Determines the number of billing periods left after the current that are outstanding.protected static intgetUnitsInCustomPeriodType(String periodType, int periodFrequency, @NonNull ChronoUnit units, Instant periodStartDate, String customerTimezone) Hook point for handling customDefaultSubscriptionPeriodTypevalues.protected static longgetUnitsInPeriodStartingOn(String periodType, int periodFrequency, @NonNull ChronoUnit units, Instant periodStartDate, String customerTimezone) Determines the number of the specifiedChronoUnitsin a billing period.static ZoneIdReturns theZoneIdfor the given customer timezone string.static <T> TsetupRead(Supplier<T> doWith, boolean isSandboxAware, boolean isApplicationAware, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Prepare the context for optional sandbox handling for a read operation.static voidsetupTenantOnlyRead(boolean isSandboxAware, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Prepare the context for optional sandbox handling for a read operation.static voidsetupWrite(boolean isSandboxAware, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Prepare the context for optional sandbox handling for a write operation.
-
Field Details
-
SANDBOX_NAME
- See Also:
-
AUTHOR_NAME
- See Also:
-
-
Constructor Details
-
SubscriptionUtils
public SubscriptionUtils()
-
-
Method Details
-
setupTenantOnlyRead
public static void setupTenantOnlyRead(boolean isSandboxAware, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Prepare the context for optional sandbox handling for a read operation. This only facilitates tenant discrimination with optional sandbox support. To indicate application discrimination, usesetupRead(Supplier, boolean, boolean, ContextInfo).- Parameters:
isSandboxAware- Whether sandboxing should be enabled for the scope of the operationcontext- The context to prepare with sandbox information
-
setupRead
public static <T> T setupRead(Supplier<T> doWith, boolean isSandboxAware, boolean isApplicationAware, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Prepare the context for optional sandbox handling for a read operation.- Parameters:
doWith- The operation to perform within the possible scope of trackable behavior alterations. SeeTrackableBehaviorContext.doWith(java.lang.Runnable, com.broadleafcommerce.data.tracking.core.TrackableBehaviorOverride...).isSandboxAware- Whether sandboxing should be enabled for the scope of the operationisApplicationAware- Whether the operation should be aware of application context for discriminationcontext- The context to prepare with sandbox information
-
setupWrite
public static void setupWrite(boolean isSandboxAware, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Prepare the context for optional sandbox handling for a write operation.- Parameters:
isSandboxAware- Whether sandboxing should be enabled for the scope of the operationcontext- The context to prepare with sandbox information
-
getBeginningOfNextDay
public static Instant getBeginningOfNextDay(@NonNull @NonNull Instant startDate, @Nullable String timezone) Gets the beginning of the next day from the givenInstant.- Parameters:
startDate- the start date- Returns:
- the beginning of the next day
-
getBeginningOfNextDay
public static Date getBeginningOfNextDay(@NonNull @NonNull Date startDate, @Nullable String timezone) Gets the beginning of the next day from the givenInstant.- Parameters:
startDate- the start date- Returns:
- the beginning of the next day
-
getNumberOfPeriodsLeftInTerm
public static Optional<Long> getNumberOfPeriodsLeftInTerm(String periodType, int periodFrequency, @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.termStartDate- The start of the subscription's term.termEndDate- The end of the subscription's term.customerTimezone- The customer's timezone ID- Returns:
- The number billings left after the current that are unbilled.
-
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
-
getUnitsInPeriodStartingOn
protected static long getUnitsInPeriodStartingOn(String periodType, int periodFrequency, @NonNull @NonNull ChronoUnit units, @Nullable Instant periodStartDate, @Nullable String customerTimezone) Determines the number of the specifiedChronoUnitsin 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.units- TheChronoUnitsfor which to return the number per period.periodStartDate- The start date of the period for which the number of days is needed.customerTimezone- The customer's timezone ID- Returns:
- The number of days in a billing period.
- See Also:
-
getUnitsInCustomPeriodType
protected static int getUnitsInCustomPeriodType(String periodType, int periodFrequency, @NonNull @NonNull ChronoUnit units, @Nullable Instant periodStartDate, @Nullable String customerTimezone) 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.units- TheChronoUnitsfor which to return the number per period.periodStartDate- The start date of the period for which the number of days is needed.customerTimezone- The customer's timezone ID- Returns:
- The number of days in a billing period.
- See Also:
-
getMonthsUntilEndOfTerm
protected static long getMonthsUntilEndOfTerm(@NonNull @NonNull Instant termStartDate, @NonNull @NonNull Instant termEndDate, @Nullable String customerTimezone) Determines the number of months in a subscription's terms.- Parameters:
termStartDate- The start of the subscription's term.termEndDate- The end of the subscription's term.customerTimezone- The customer's timezone ID- Returns:
- The number of months in a subscription's terms.
-
getCurrentPeriod
protected static long getCurrentPeriod(@NonNull @NonNull Instant termStartDate, long monthsInPeriod, @Nullable String customerTimezone) Determines which billing period the subscription is currently in given theSubscription.getStartOfTermDate(). This will determine the number of months between now and the term's start and the number of months in a period to make the determination.- Parameters:
termStartDate- Date the subscription's term began.monthsInPeriod- Number of days in a period.customerTimezone- The customer's timezone ID- Returns:
- The billing period the subscription is currently in
-