Subscription Management

Pre-requisite:

  • The user has to be signed in to perform the following operations.

Get Subscriptions

To retrieve all active subscriptions for a given space, use the following method:

  • spaceId (required): The unique identifier of the space.
InstaVision.subscriptionServices.getSubscriptions(
  spaceId = "spaceId",
  onSuccess = { subscriptions ->
// Handle the list of subscriptions
  },
  onError = { error ->
    // The error object contains the error code and message
  }
)

Cancel Subscription

To cancel an existing subscription, use the following method:

  • subscriptionId (required): The unique ID of the subscription.
InstaVision.subscriptionServices.cancelSubscription(
  subscriptionId = "subscriptionId",
  onSuccess = {
    // Subscription cancelled successfully
  },
  onError = { error ->
    // The error object contains the error code and message
  }
)

Activate Subscription Preview

To activate a subscription currently in preview mode, use the following method:

  • spaceId (required): The unique identifier of the space.
  • subscriptionPreviewRequest (required): The request object containing preview activation details.
val previewRequest = SubscriptionPreviewRequest(
  skuId = "skuId", // The SKU ID of the subscription
)
InstaVision.subscriptionServices.activateSubscriptionPreview(
  spaceId = "spaceId ",
  subscriptionPreviewRequest = previewRequest,
  onSuccess = {
    // Subscription preview activated successfully
  },
  onError = { error ->
    // The error object contains the error code and message
  }
)

The scope of a subscription

A subscription carries a scope describing what it covers, matching a SubscriptionScope value (Product or Space). The same field is present on the subscription metadata.

when (SubscriptionScope.fromValue(subscription.scope)) {
  SubscriptionScope.Product -> {
    // The subscription covers a single product, read subscription.productId
  }
  SubscriptionScope.Space -> {
    // The subscription covers the whole space
  }
  null -> {
    // A scope this version of the SDK does not know about
  }
}

A subscription’s productId is nullable and is absent when the scope is Space, so read it only after checking the scope. A data pass no longer carries a product id at all.


This site uses Just the Docs, a documentation theme for Jekyll.