Class Subscription

java.lang.Object
com.broadleafcommerce.subscription.domain.Subscription
All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.ContextStateAware, com.broadleafcommerce.money.CurrencyConsumer, Serializable, javax.money.CurrencySupplier

public class Subscription extends Object implements com.broadleafcommerce.data.tracking.core.ContextStateAware, javax.money.CurrencySupplier, com.broadleafcommerce.money.CurrencyConsumer, Serializable
This is a domain representing a user's subscription to a service or a good. It will be billed according to the billingFrequency by the billing job. The particular line items of the subscription are contained in SubscriptionItem objects, while any price changes would be held by adjustments. Changes to a subscription's status should be followed by a SubscriptionStatusAudit to track them.
See Also:
  • Constructor Details

  • Method Details

    • inGracePeriod

      public boolean inGracePeriod()
    • setCurrencyCode

      public void setCurrencyCode(String currencyCode)
    • setCurrency

      public void setCurrency(javax.money.CurrencyUnit currency)
      Specified by:
      setCurrency in interface com.broadleafcommerce.money.CurrencyConsumer
    • setSubscriptionId

      public void setSubscriptionId(String subscriptionId)
    • setId

      public void setId(String id)
    • getCurrentPeriod

      public Integer getCurrentPeriod()
      Gets the current period for this subscription by comparing Instant.now() and each SubscriptionPeriod's timeframe. If none are found, nextPeriod - 1 is returned.

      In the case where there are two periods both fitting the current time, which can happen if the subscription had just lost a free trial causing the free trial period to be shortened, the period that is not shortened is used.

      Returns:
      The SubscriptionPeriod matching the given Instant, or null if none
    • getPeriodDefinition

      @Nullable public SubscriptionPeriod getPeriodDefinition(int requestedPeriod)
    • getFreeTrialStartDate

      @Nullable public Instant getFreeTrialStartDate()
      Gets the start date of the free trial.

      JsonIgnore is intentionally not applied here to drive Billing Metadata display.

    • getFreeTrialEndDate

      @Nullable public Instant getFreeTrialEndDate()
      Gets the end date of the free trial.

      JsonIgnore is intentionally not applied here to drive Billing Metadata display.

    • isInFreeTrialPeriod

      public boolean isInFreeTrialPeriod()
    • getSubscriptionId

      @Deprecated public String getSubscriptionId()
      Deprecated.
      Use getId() field instead
    • getId

      public String getId()
    • getName

      public String getName()
      Name of this subscription
    • getSubscriptionStatus

      public String getSubscriptionStatus()
      Current status of this subscription
      See Also:
    • getSubscriptionNextStatus

      public String getSubscriptionNextStatus()
      Next status for this subscription
      See Also:
    • getNextStatusChangeDate

      public Date getNextStatusChangeDate()
      Date when the next status should begin
      See Also:
      • subscriptionNextStatus
    • getNextStatusChangeReason

      public String getNextStatusChangeReason()
      Reason for the update to the next status
      See Also:
      • subscriptionNextStatus
    • getResumeDate

      public Date getResumeDate()
      Date this subscription will or did continue. This is likely to be used only after a subscription was paused or stopped.
    • getRootItemRefType

      public String getRootItemRefType()
      Type of the item for which this subscription was provisioned.
      See Also:
    • getRootItemRef

      public String getRootItemRef()
      Reference to the item id for which this subscription was provision
    • getUserRefType

      public String getUserRefType()
      Type of user owning this subscription
      See Also:
    • getUserRef

      public String getUserRef()
      Reference to the user to whom this subscription belongs
    • getAlternateUserRefType

      public String getAlternateUserRefType()
      Type of alternative reference to the subscription owner
    • getAlternateUserRef

      public String getAlternateUserRef()
      Alternate reference to the user. Useful for third-party authentication system identifiers
    • getSubscriptionSource

      public String getSubscriptionSource()
      This field shows from which process or user action this subscription originated.
      See Also:
    • getSubscriptionSourceRef

      public String getSubscriptionSourceRef()
      This field shows the identifier of the process or user action this subscription originated.
      See Also:
      • subscriptionSource
    • getSecondarySourceType

      public String getSecondarySourceType()
      The type of the secondary source to reference, e.g, an Order Item on an Order. Optional.
      See Also:
    • getSecondarySourceRef

      public String getSecondarySourceRef()
      The secondary source to reference, e.g, an Order Item on an Order. Optional.
      See Also:
      • secondarySourceType
    • getSiteIdentifier

      public String getSiteIdentifier()
      Multi-tenancy support
    • getBillingFrequency

      @Deprecated public String getBillingFrequency()
      Deprecated.
      in favor of periodType & periodFrequency
      Frequency of billing for this subscription
      See Also:
    • getPeriodFrequency

      public Integer getPeriodFrequency()
      The frequency with which the recurring price should be charged., e.g., a value of 1 combined with periodType of MONTH would indicate to a subscription service that the price should be charged every 1 month.
      See Also:
      • periodType
    • getPeriodType

      public String getPeriodType()
      The period type for the price, e.g. MONTHLY, QUARTERLY, ANNUALLY
      See Also:
    • getPaymentStrategy

      public String getPaymentStrategy()
      Declares that payments made against a subscription are going towards the goods/services rendered in the previous vs current period.
      See Also:
    • getPriorBillDate

      public Date getPriorBillDate()
      The bill date for the previous period
    • getNextBillDate

      public Date getNextBillDate()
      Next date this subscription will be billed
    • getPreferredPaymentAccountId

      public String getPreferredPaymentAccountId()
      References an identifier of a PaymentAccount that is considered preferred for this subscription. Overrides the ordering of accounts as provided by SavedPaymentMethodProvider
    • getCurrencyCode

      @Deprecated public String getCurrencyCode()
      Deprecated.
      use getCurrency() field instead
    • getCurrency

      public javax.money.CurrencyUnit getCurrency()
      Currency of this subscription
      Specified by:
      getCurrency in interface javax.money.CurrencySupplier
    • getNextSubscription

      public String getNextSubscription()
      If this subscription was upgraded or downgraded, holds the reference to the subscription replacing this one
    • getLastBillingBatchId

      public String getLastBillingBatchId()
      The batch id of the last billing job run for this subscription
    • getLastBillingOperationStatus

      public String getLastBillingOperationStatus()
      The most current status of the last BillingEvent for this subscription
      See Also:
    • getLastBillingSuccessDate

      public Date getLastBillingSuccessDate()
      Last date this that the Billing Job succeeded billing this subscription
    • getCreatedDate

      public Date getCreatedDate()
      Date this subscription was created. This field should not be updated or set by a request.
    • getSubscriptionAdjustments

      public List<SubscriptionAdjustment> getSubscriptionAdjustments()
      Adjustments for this subscription. This may be present on incoming API requests such as when creating a subscription with its items, but otherwise is only populated in responses when part of a SubscriptionWithItems.
    • getUpdatedBy

      @Deprecated public String getUpdatedBy()
      Deprecated.
      Use ContextInfo.setAuthor(String) instead
    • getChargeback

      public Boolean getChargeback()
      Whether this subscription is being cancelled due to a chargeback
    • isAutoRenewalEnabled

      public boolean isAutoRenewalEnabled()
      Whether this subscription automatically renews at the end of the current subscription term.
    • isAllowAutoRenewalModification

      public boolean isAllowAutoRenewalModification()
      This flag indicates whether this subscription's auto-renewability can be modified after declaration on the subscription.
    • getStartOfTermDate

      public Instant getStartOfTermDate()
      The start of term date for this subscription.
    • getEndOfTermDate

      public Instant getEndOfTermDate()
      The end of term date for this subscription.
    • getTermDurationLength

      public Integer getTermDurationLength()
      The length of the terms, e.g., if this is 36 and termDurationType is MONTHS, then the user should be billed for 36 months.
      See Also:
      • termDurationType
    • getTermDurationType

      public String getTermDurationType()
      The term duration type, e.g. DAYS, WEEKS, MONTHS, YEARS.
      See Also:
      • termDurationLength
    • getNextPeriod

      public Integer getNextPeriod()
      The next period this subscription will cover. This value is related to 'beginPeriod' and 'endPeriod' fields of SubscriptionAdjustment and SubscriptionItemAdjustment
    • getPeriods

      public List<SubscriptionPeriod> getPeriods()
      List tracking the Subscription's periods. Typically, this correlates to the set of periods for which a BillingEvent has been created.
    • getPriceDataChanges

      public List<PriceDataChange> getPriceDataChanges()
      List of price data changes for this subscription
    • getDelayedActions

      public List<DelayedSubscriptionAction> getDelayedActions()
      List of delayed actions for this subscription.

      Often, these delayed actions are related to requested actions against a subscription with a DefaultSubscriptionPaymentStrategy.PREPAID getPaymentStrategy() where instead of refunding the customer, the action is delayed until the end of the period, causing the next period to naturally identify the updated price.

    • isNeedGrantEntitlements

      public boolean isNeedGrantEntitlements()
      Whether the system has outstanding entitlements to grant on this subscription

      Note that this field does not have any effects if Entitlements are disabled in {@link BillingJobProperties#getEntitlements()#isEnabled()}

    • getCancellationPolicyRef

      public String getCancellationPolicyRef()
      A reference (typically the Id) of the CancellationPolicy for this subscription that governs how this subscription would be cancelled.
    • getFulfillmentWorkflow

      public String getFulfillmentWorkflow()
      A reference to the workflow used to fulfill the creation of, & modifications to, this subscription.
    • getCustomerTimezone

      @Nullable public String getCustomerTimezone()
      The customer's timezone. It's an optional field used to truncate the dates to the beginning of the day in customer's timezone. If null, UTC time is used.
    • getAttributes

      public Map<String,Object> getAttributes()
      Miscellaneous attributes for this subscription.
    • getInternalAttributes

      public Map<String,Object> getInternalAttributes()
      Miscellaneous internal attributes for this subscription. Distinguished from getAttributes() in that this map is used for attributes that assist in the internal working of Broadleaf.
    • getVersion

      public Integer getVersion()
      The version of this subscription. Used for checking if the requested version of the subscription is up-to-date before saving changes. This should never be manually decremented/incremented.
    • getContextState

      public com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState getContextState()
      A subset of Tracking information to expose the context state for this object.
      Specified by:
      getContextState in interface com.broadleafcommerce.data.tracking.core.ContextStateAware
    • setName

      public void setName(String name)
      Name of this subscription
    • setSubscriptionStatus

      public void setSubscriptionStatus(String subscriptionStatus)
      Current status of this subscription
      See Also:
    • setSubscriptionNextStatus

      public void setSubscriptionNextStatus(String subscriptionNextStatus)
      Next status for this subscription
      See Also:
    • setNextStatusChangeDate

      public void setNextStatusChangeDate(Date nextStatusChangeDate)
      Date when the next status should begin
      See Also:
      • subscriptionNextStatus
    • setNextStatusChangeReason

      public void setNextStatusChangeReason(String nextStatusChangeReason)
      Reason for the update to the next status
      See Also:
      • subscriptionNextStatus
    • setResumeDate

      public void setResumeDate(Date resumeDate)
      Date this subscription will or did continue. This is likely to be used only after a subscription was paused or stopped.
    • setRootItemRefType

      public void setRootItemRefType(String rootItemRefType)
      Type of the item for which this subscription was provisioned.
      See Also:
    • setRootItemRef

      public void setRootItemRef(String rootItemRef)
      Reference to the item id for which this subscription was provision
    • setUserRefType

      public void setUserRefType(String userRefType)
      Type of user owning this subscription
      See Also:
    • setUserRef

      public void setUserRef(String userRef)
      Reference to the user to whom this subscription belongs
    • setAlternateUserRefType

      public void setAlternateUserRefType(String alternateUserRefType)
      Type of alternative reference to the subscription owner
    • setAlternateUserRef

      public void setAlternateUserRef(String alternateUserRef)
      Alternate reference to the user. Useful for third-party authentication system identifiers
    • setSubscriptionSource

      public void setSubscriptionSource(String subscriptionSource)
      This field shows from which process or user action this subscription originated.
      See Also:
    • setSubscriptionSourceRef

      public void setSubscriptionSourceRef(String subscriptionSourceRef)
      This field shows the identifier of the process or user action this subscription originated.
      See Also:
      • subscriptionSource
    • setSecondarySourceType

      public void setSecondarySourceType(String secondarySourceType)
      The type of the secondary source to reference, e.g, an Order Item on an Order. Optional.
      See Also:
    • setSecondarySourceRef

      public void setSecondarySourceRef(String secondarySourceRef)
      The secondary source to reference, e.g, an Order Item on an Order. Optional.
      See Also:
      • secondarySourceType
    • setSiteIdentifier

      public void setSiteIdentifier(String siteIdentifier)
      Multi-tenancy support
    • setBillingFrequency

      @Deprecated public void setBillingFrequency(String billingFrequency)
      Deprecated.
      in favor of periodType & periodFrequency
      Frequency of billing for this subscription
      See Also:
    • setPeriodFrequency

      public void setPeriodFrequency(Integer periodFrequency)
      The frequency with which the recurring price should be charged., e.g., a value of 1 combined with periodType of MONTH would indicate to a subscription service that the price should be charged every 1 month.
      See Also:
      • periodType
    • setPeriodType

      public void setPeriodType(String periodType)
      The period type for the price, e.g. MONTHLY, QUARTERLY, ANNUALLY
      See Also:
    • setPaymentStrategy

      public void setPaymentStrategy(String paymentStrategy)
      Declares that payments made against a subscription are going towards the goods/services rendered in the previous vs current period.
      See Also:
    • setPriorBillDate

      public void setPriorBillDate(Date priorBillDate)
      The bill date for the previous period
    • setNextBillDate

      public void setNextBillDate(Date nextBillDate)
      Next date this subscription will be billed
    • setPreferredPaymentAccountId

      public void setPreferredPaymentAccountId(String preferredPaymentAccountId)
      References an identifier of a PaymentAccount that is considered preferred for this subscription. Overrides the ordering of accounts as provided by SavedPaymentMethodProvider
    • setNextSubscription

      public void setNextSubscription(String nextSubscription)
      If this subscription was upgraded or downgraded, holds the reference to the subscription replacing this one
    • setLastBillingBatchId

      public void setLastBillingBatchId(String lastBillingBatchId)
      The batch id of the last billing job run for this subscription
    • setLastBillingOperationStatus

      public void setLastBillingOperationStatus(String lastBillingOperationStatus)
      The most current status of the last BillingEvent for this subscription
      See Also:
    • setLastBillingSuccessDate

      public void setLastBillingSuccessDate(Date lastBillingSuccessDate)
      Last date this that the Billing Job succeeded billing this subscription
    • setCreatedDate

      public void setCreatedDate(Date createdDate)
      Date this subscription was created. This field should not be updated or set by a request.
    • setSubscriptionAdjustments

      public void setSubscriptionAdjustments(List<SubscriptionAdjustment> subscriptionAdjustments)
      Adjustments for this subscription. This may be present on incoming API requests such as when creating a subscription with its items, but otherwise is only populated in responses when part of a SubscriptionWithItems.
    • setUpdatedBy

      @Deprecated public void setUpdatedBy(String updatedBy)
      Deprecated.
      Use ContextInfo.setAuthor(String) instead
    • setChargeback

      public void setChargeback(Boolean chargeback)
      Whether this subscription is being cancelled due to a chargeback
    • setAutoRenewalEnabled

      public void setAutoRenewalEnabled(boolean autoRenewalEnabled)
      Whether this subscription automatically renews at the end of the current subscription term.
    • setAllowAutoRenewalModification

      public void setAllowAutoRenewalModification(boolean allowAutoRenewalModification)
      This flag indicates whether this subscription's auto-renewability can be modified after declaration on the subscription.
    • setStartOfTermDate

      public void setStartOfTermDate(Instant startOfTermDate)
      The start of term date for this subscription.
    • setEndOfTermDate

      public void setEndOfTermDate(Instant endOfTermDate)
      The end of term date for this subscription.
    • setTermDurationLength

      public void setTermDurationLength(Integer termDurationLength)
      The length of the terms, e.g., if this is 36 and termDurationType is MONTHS, then the user should be billed for 36 months.
      See Also:
      • termDurationType
    • setTermDurationType

      public void setTermDurationType(String termDurationType)
      The term duration type, e.g. DAYS, WEEKS, MONTHS, YEARS.
      See Also:
      • termDurationLength
    • setNextPeriod

      public void setNextPeriod(Integer nextPeriod)
      The next period this subscription will cover. This value is related to 'beginPeriod' and 'endPeriod' fields of SubscriptionAdjustment and SubscriptionItemAdjustment
    • setPeriods

      public void setPeriods(List<SubscriptionPeriod> periods)
      List tracking the Subscription's periods. Typically, this correlates to the set of periods for which a BillingEvent has been created.
    • setPriceDataChanges

      public void setPriceDataChanges(List<PriceDataChange> priceDataChanges)
      List of price data changes for this subscription
    • setDelayedActions

      public void setDelayedActions(List<DelayedSubscriptionAction> delayedActions)
      List of delayed actions for this subscription.

      Often, these delayed actions are related to requested actions against a subscription with a DefaultSubscriptionPaymentStrategy.PREPAID getPaymentStrategy() where instead of refunding the customer, the action is delayed until the end of the period, causing the next period to naturally identify the updated price.

    • setNeedGrantEntitlements

      public void setNeedGrantEntitlements(boolean needGrantEntitlements)
      Whether the system has outstanding entitlements to grant on this subscription

      Note that this field does not have any effects if Entitlements are disabled in {@link BillingJobProperties#getEntitlements()#isEnabled()}

    • setCancellationPolicyRef

      public void setCancellationPolicyRef(String cancellationPolicyRef)
      A reference (typically the Id) of the CancellationPolicy for this subscription that governs how this subscription would be cancelled.
    • setFulfillmentWorkflow

      public void setFulfillmentWorkflow(String fulfillmentWorkflow)
      A reference to the workflow used to fulfill the creation of, & modifications to, this subscription.
    • setCustomerTimezone

      public void setCustomerTimezone(@Nullable String customerTimezone)
      The customer's timezone. It's an optional field used to truncate the dates to the beginning of the day in customer's timezone. If null, UTC time is used.
    • setAttributes

      public void setAttributes(Map<String,Object> attributes)
      Miscellaneous attributes for this subscription.
    • setInternalAttributes

      public void setInternalAttributes(Map<String,Object> internalAttributes)
      Miscellaneous internal attributes for this subscription. Distinguished from getAttributes() in that this map is used for attributes that assist in the internal working of Broadleaf.
    • setVersion

      public void setVersion(Integer version)
      The version of this subscription. Used for checking if the requested version of the subscription is up-to-date before saving changes. This should never be manually decremented/incremented.
    • setContextState

      public void setContextState(com.broadleafcommerce.data.tracking.core.filtering.business.domain.ContextState contextState)
      A subset of Tracking information to expose the context state for this object.
      Specified by:
      setContextState in interface com.broadleafcommerce.data.tracking.core.ContextStateAware
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • canEqual

      protected boolean canEqual(Object other)
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object