Search Unity

Official Improved Support for Subscription Products

Discussion in 'Unity IAP' started by ap-unity, May 23, 2018.

Thread Status:
Not open for further replies.
  1. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    This documentation will eventually live in the manual, but for the time being, here is some details about the SubscriptionManager class.

    Unity IAP supports Product subscription information queries through the SubscriptionManager class. For example code, please review the IAPDemo.cs script included in the Unity IAP SDK (1.19+).

    SubscriptionManager class methods
    This class supports the Apple store and Google Play store. For Google Play, this class only supports Products purchased using IAP SDK 1.19+.

    public SubscriptionInfo getSubscriptionInfo() Returns a `SubscriptionInfo` object (see below)

    SubscriptionInfo class methods
    The SubscriptionInfo class is a container for a Product’s subscription-related information.

    • public string getProductId()
      • Returns a Product’s store ID
    • public DateTime getPurchaseDate()
      • Returns the Product’s purchase date.
      • For Apple, the purchase date is the date when the subscription was either purchased or renewed.
      • For Google, the purchase date is the date when the subscription was originally purchased.
    • public Result isSubscribed()
      • Returns a `Result` enum to indicate whether this Product is currently subscribed or not.
      • Non-renewable Products in the Apple store return a `Result.Unsupported` value.
      • Auto-renewable Products in the Apple store and subscription products in the Google Play store return a `Result.True` or `Result.False` value.
    • public Result isExpired()
      • Returns a Result enum to indicate whether this Product has expired or not.
      • Non-renewable Products in the Apple store return a `Result.Unsupported` value.
      • Auto-renewable Products in the Apple store and subscription products in the Google Play store return a `Result.True` or `Result.False` value.
    • public Result isCancelled()
      • Returns a `Result` enum to indicate whether this Product has been cancelled.
      • A cancelled subscription means the Product is currently subscribed, but will not renew on the next billing date.
      • Non-renewable Products in the Apple store return a `Result.Unsupported` value.
      • Auto-renewable Products in the Apple store and subscription products in the Google Play store return a `Result.True` or `Result.False` value.
    • public Result isFreeTrial()
      • Returns a `Result` enum to indicate whether this Product is a free trial.
      • Products in the Google Play store return Result.Unsupported if the application does not support version 6+ of the Android in-app billing API.
      • Non-renewable Products in the Apple store return a `Result.Unsupported` value.
      • Auto-renewable Products in the Apple store and subscription products in the Google Play store return a `Result.True` or `Result.False` value.
    • public Result isAutoRenewing()
      • Returns a `Result` enum to indicate whether this Product is auto-renewable.
      • Non-renewable Products in the Apple store return a `Result.Unsupported` value.
      • Auto-renewable Products in the Apple store and subscription products in the Google Play store return a `Result.True` or `Result.False` value.
    • public TimeSpan getRemainingTime()
      • Returns a `TimeSpan` to indicate how much time remains until the next billing date.
      • Products in the Google Play store return TimeSpan.MaxValue if the application does not support version 6+ of the Android in-app billing API.
    • `public Result isIntroductoryPricePeriod()
      • Returns a `Result` enum to indicate whether this Product is within an introductory price period.
      • Non-renewable Products in the Apple store return a `Result.Unsupported` value.
      • Auto-renewable Products in the Apple store and subscription products in the Google Play store return a `Result.True` or `Result.False` value.
      • Products in the Google Play store return Result.Unsupported if the application does not support version 6+ of the Android in-app billing API.
    • public TimeSpan getIntroductoryPricePeriod()`
      • Returns a `TimeSpan` to indicate how much time remains for the introductory price period.
      • Subscription products with no introductory price period return `TimeSpan.Zero`.
      • Products in the Apple store return TimeSpan.Zero if the application does not support iOS version 11.2+, macOS 10.13.2+, or tvOS 11.2+.
    • public long getIntroductoryPricePeriodCycles()
      • Returns the number of introductory price periods that can be applied to this Product.
      • Products in the Apple store return 0 if the application does not support iOS version 11.2+, macOS 10.13.2+, or tvOS 11.2+
    • public string getIntroductoryPrice()
      • Returns a string to indicate the introductory price of the Product.
      • Products with no introductory price return a `"not available"` value.
      • Apple store Products with an introductory price return a value formatted as `“0.99USD”`.
      • Google Play Products with an introductory price return a value formatted as `“$0.99”`.
      • Products in the Apple store return `“not available”` if the application does not support iOS version 11.2+, macOS 10.13.2+, or tvOS 11.2+.
    • public DateTime getExpireDate()
      • Returns the date of the Product’s next auto-renew or expiration (for a cancelled auto-renewing subscription).
      • Products in the Google Play store return TimeSpan.MaxValue if the application does not support version 6+ of the Android in-app billing API
    Result
    enumeration

    Properties
    • True indicate a bool value true
    • False indicate a bool value false
    • Unsupported indicate this is a unsupported property for this subscription product
    For more complete example code, please view the IAPDemo.cs within Plugins/Purchasing/script.

    Code (csharp):
    1. #if SUBSCRIPTION_MANAGER
    2.        Dictionary<string, string> dict = m_AppleExtensions.GetIntroductoryPriceDictionary();
    3. #endif
    Code (csharp):
    1. foreach (Product item in controller.products.all)
    2. {
    3. #if SUBSCRIPTION_MANAGER
    4.    // this is the usage of SubscriptionManager class
    5.    if (item.receipt != null) {
    6.        if (item.definition.type == ProductType.Subscription) {
    7.           string intro_json = (dict == null || !dict.ContainsKey(item.definition.storeSpecificId)) ? null :  dict[item.definition.storeSpecificId];
    8.            SubscriptionManager p = new SubscriptionManager(item, intro_json);
    9.            SubscriptionInfo info = p.getSubscriptionInfo();
    10.            Debug.Log(info.getProductId());
    11.            Debug.Log(info.getPurchaseDate());
    12.            Debug.Log(info.getExpireDate());
    13.            Debug.Log(info.isSubscribed());
    14.            Debug.Log(info.isExpired());
    15.            Debug.Log(info.isCancelled());
    16.            Debug.Log(info.isFreeTrial());
    17.            Debug.Log(info.isAutoRenewing());
    18.            Debug.Log(info.getRemainingTime());
    19.            Debug.Log(info.isIntroductoryPricePeriod());
    20.            Debug.Log(info.getIntroductoryPrice());
    21.            Debug.Log(info.getIntroductoryPricePeriod());
    22.            Debug.Log(info.getIntroductoryPricePeriodCycles());
    23.        } else {
    24.            Debug.Log("the product is not a subscription product");
    25.        }
    26.    } else {
    27.        Debug.Log("the product should have a valid receipt");
    28.    }
    29. #endif
    30. }
     
    Last edited: May 24, 2018
Thread Status:
Not open for further replies.