Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved Question About Codeless IAP Subscription Function

Discussion in 'Unity IAP' started by DanielKazoo, Nov 22, 2022.

Thread Status:
Not open for further replies.
  1. DanielKazoo

    DanielKazoo

    Joined:
    Aug 9, 2022
    Posts:
    4
    Hi, I am using codeless IAP button to purchase a subsrciption content in an ios game. How to check if the subscription is being purchased and its expired date? (is there a function similar to onPurchaseCompleted and onPurchaseFailed to check the subscription status)

    Thank you!
     
  2. glenhunter

    glenhunter

    Unity Technologies

    Joined:
    Apr 2, 2019
    Posts:
    92
    The IAP package manager has a BuyingSubscription example. In the example BuyingSubscription script there is this function.

    Code (CSharp):
    1. bool IsSubscribedTo(Product subscription)
    2.         {
    3.             // If the product doesn't have a receipt, then it wasn't purchased and the user is therefore not subscribed.
    4.             if (subscription.receipt == null)
    5.             {
    6.                 return false;
    7.             }
    8.  
    9.             //The intro_json parameter is optional and is only used for the App Store to get introductory information.
    10.             var subscriptionManager = new SubscriptionManager(subscription, null);
    11.  
    12.             // The SubscriptionInfo contains all of the information about the subscription.
    13.             // Find out more: https://docs.unity3d.com/Packages/com.unity.purchasing@3.1/manual/UnityIAPSubscriptionProducts.html
    14.             var info = subscriptionManager.getSubscriptionInfo();
    15.  
    16.             return info.isSubscribed() == Result.True;
    17.         }
    You should be able to feed the product data from onPurchaseCompleted(Product product) into this IsSubscribedTo function and get additional subscription data such as expiration info for example info.getExpireDate()

    Unity codeless IAP invokes the On Purchase Complete (Product) for restoring so you can follow the same process for restoring https://docs.unity3d.com/Packages/com.unity.purchasing@4.5/manual/IAPButton.html
     
    Arnaud_Gorain likes this.
  3. DanielKazoo

    DanielKazoo

    Joined:
    Aug 9, 2022
    Posts:
    4
    Thank you! It helps a lot !
    I tried BuyingSubscription example and the Text is displaying:
    Code (CSharp):
    1. Couldn't retrieve subscription information because your current store is not supported.
    2. Your store: "fake"
    3.  
    4. You must use the App Store, Google Play Store or Amazon Store to be able to retrieve subscription information.
    Do I need to build the app on the ios device in order to test it?
     
  4. DanielKazoo

    DanielKazoo

    Joined:
    Aug 9, 2022
    Posts:
    4
    Also, is there a way to invoke the restore api whenever the gameobject is initialized?
     
  5. glenhunter

    glenhunter

    Unity Technologies

    Joined:
    Apr 2, 2019
    Posts:
    92

    Correct first you will need to register your application and add In-App Purchases on the app store then run a build on the device. We have some guides for Google and Apple that can be useful see

    https://docs.unity3d.com/Packages/com.unity.purchasing@4.5/manual/UnityIAPGoogleConfiguration.html
    https://docs.unity3d.com/Packages/com.unity.purchasing@4.5/manual/UnityIAPAppleConfiguration.html
    It's worth noting that the codeless IAP restore button works for Apple, not Google. With this in mind, I recommend taking a more hands-on approach and interacting with our IAP APIs for all things IAP related through code - it will give you more control specifically when restoring transactions. We have lots of examples (downloaded additionally through package manager when IAP is installed) for different use cases which also include restoring transactions/getting additional subscription info you seek for both Apple and Google.
     
    Last edited: Nov 23, 2022
    Arnaud_Gorain likes this.
  6. DanielKazoo

    DanielKazoo

    Joined:
    Aug 9, 2022
    Posts:
    4
    Thank you! It's really useful!
     
    Arnaud_Gorain likes this.
  7. Arnaud_Gorain

    Arnaud_Gorain

    Unity Technologies

    Joined:
    Jun 28, 2022
    Posts:
    172
    This thread is now closed. Feel free to reach out via a new thread if you encounter further issues.
    Thanks!
     
Thread Status:
Not open for further replies.