Class BillingService

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

@Service public class BillingService extends Object
  • Constructor Details

  • 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