Class BillingService

java.lang.Object
io.meeds.billing.service.BillingService

@Service public class BillingService extends Object
  • Constructor Details

    • BillingService

      public BillingService(HubBilling hubBilling, SubscriptionEmailReminderService subscriptionEmailReminderService, org.exoplatform.social.core.space.spi.SpaceService spaceService, HubSettingService hubSettingService, org.exoplatform.social.core.manager.IdentityManager identityManager, org.exoplatform.portal.mop.service.LayoutService layoutService)
  • Method Details

    • createCustomer

      public String createCustomer(org.exoplatform.social.core.space.model.Space space, org.exoplatform.social.core.identity.model.Identity identity) throws com.stripe.exception.StripeException
      Creates a new Stripe customer for the given space
      Parameters:
      space -
      identity -
      Returns:
      stripe customer ID
      Throws:
      com.stripe.exception.StripeException
    • subscribe

      public com.stripe.model.Subscription subscribe(org.exoplatform.social.core.space.model.Space space, String customerId, String priceId) throws com.stripe.exception.StripeException
      Creates a new Stripe subscription for the given customer (space).
      Parameters:
      space -
      customerId -
      Returns:
      the created Stripe Subscription
      Throws:
      com.stripe.exception.StripeException
    • createCustomerPortalSession

      public String createCustomerPortalSession(long spaceId, String userName) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Creates a Stripe Billing Portal session for the given customer.
      Parameters:
      spaceId -
      userName -
      Returns:
      the stripe customer portal url
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException
      IllegalAccessException
    • createCustomerPortalSession

      public String createCustomerPortalSession(String customerId)
      Creates a Stripe Billing Portal session for the given customer.
      Parameters:
      customerId -
      Returns:
      the stripe customer portal url
    • cancelSubscription

      public void cancelSubscription(long spaceId, String userName) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Cancels an active Stripe subscription.
      Parameters:
      spaceId -
      userName -
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException
      IllegalAccessException
    • cancelSubscription

      public void cancelSubscription(String subscriptionId)
      Cancels an active Stripe subscription.
      Parameters:
      subscriptionId -
    • getSubscription

      public com.stripe.model.Subscription getSubscription(String subscriptionId) throws Exception
      Throws:
      Exception
    • notifyOnSubscriptionStatus

      public void notifyOnSubscriptionStatus(long spaceId, String authenticatedUser, boolean maxOfUsersExceeded) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Sends an email about the current subscription status.
      Parameters:
      spaceId -
      authenticatedUser -
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • notifyHubAdminsOnSubscriptionStatus

      public void notifyHubAdminsOnSubscriptionStatus(HubBillingSettings hubBillingSettings, String authenticatedUser)
      Sends an email to the hub administrator about the current subscription status.
      Parameters:
      hubBillingSettings -
      authenticatedUser -
    • notifyHubAdminsOnUsersLimitExceeded

      public void notifyHubAdminsOnUsersLimitExceeded(String authenticatedUser, long spaceId)
      Sends an email to the administrator about the max of users exceeded.
      Parameters:
      authenticatedUser -
    • notifyAdminsOnPlanChange

      public void notifyAdminsOnPlanChange(long spaceId)
      Sends an email to the administrators about the hub plan change.
      Parameters:
      spaceId -
    • notifyAdminsOnSubscriptionCancellation

      public void notifyAdminsOnSubscriptionCancellation(String authenticatedUser, long spaceId)
    • getPriceById

      public com.stripe.model.Price getPriceById(String id) throws com.stripe.exception.StripeException
      Retrieves a Stripe Price object by its unique identifier.
      Parameters:
      id - the unique identifier of the Stripe price to retrieve
      Returns:
      the Price object if found; null if an error occurs or the price cannot be retrieved
      Throws:
      com.stripe.exception.StripeException
    • reportMembersCount

      public void reportMembersCount(HubBillingSettings hubBillingSettings) throws Exception
      Reports the current number of members in a space to Stripe as a metered event.

      This method retrieves the associated Stripe meter event name from the configured meter ID, counts the members in the corresponding space, and sends a metered usage event to Stripe with the count value.

      Parameters:
      hubBillingSettings - the billing settings containing the meter ID, customer ID, and space ID
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException - if the space corresponding to the given space ID is not found
      Exception - if an error occurs while communicating with Stripe or retrieving meter details
    • updateTieredBillingQuantities

      public void updateTieredBillingQuantities(HubBillingSettings hubBillingSettings) throws org.exoplatform.commons.exception.ObjectNotFoundException, com.stripe.exception.StripeException
      Updates the subscription quantity for subscription item in Stripe if the number of active members in the associated space exceeds the current subscription quantity.
      Parameters:
      hubBillingSettings - the hub billing settings
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException - if the associated space is not found
      com.stripe.exception.StripeException - if updating the subscription in Stripe fails
    • updateSubscriptionQuantity

      public void updateSubscriptionQuantity(String subscriptionId, long subscriptionQuantity) throws com.stripe.exception.StripeException, org.exoplatform.commons.exception.ObjectNotFoundException
      Updates the quantity of a subscription item in Stripe.
      Parameters:
      subscriptionId - the Stripe subscription ID
      subscriptionQuantity - the new subscription quantity
      Throws:
      com.stripe.exception.StripeException - if the Stripe API call fails
      org.exoplatform.commons.exception.ObjectNotFoundException - if no subscription items are found for the given subscription
    • enableExistingSpaceBilling

      public void enableExistingSpaceBilling(long spaceId, String priceId, String spaceManager) throws org.exoplatform.commons.exception.ObjectNotFoundException, org.exoplatform.commons.ObjectAlreadyExistsException, IllegalAccessException
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException
      org.exoplatform.commons.ObjectAlreadyExistsException
      IllegalAccessException
    • updateBillableSpaceLayout

      public void updateBillableSpaceLayout(org.exoplatform.portal.mop.SiteKey siteKey)