Search Unity

[Solved] Android Subscription

Discussion in 'Unity IAP' started by m4ko, Oct 4, 2016.

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

    m4ko

    Joined:
    Feb 8, 2013
    Posts:
    16
    Hi guys,

    We have UnityIAP running on a live app. Seemed to work well and we were happy.

    However now users are reporting: Auto renewing subscriptions don't work. For the first month they have the "full version" and after the auto renewal our app thinks there is no active subscription anymore.

    Could someone please elaborate what to call / listen to catch auto renewing subscriptions? According to a Unity employe from another thread:
    So we thought "PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)" would be called just like a normal purchase on this item. Meaning we suspected that we would get a new receipt with a new "GooglePlayReceipt google.purchaseDate" we could work with to base our "SubscriptionStatus" on.

    But I guess it works in another way. Please advise :)



    Additional information on how we parse our products / receipts:
    At the end of ProcessPurchase we call "UpdateSubscriptionStatus". This will
    Code (CSharp):
    1. for (int i = 0; i < availableProducts.Length; i++)
    iterate through all products and
    Code (CSharp):
    1. if (availableProducts[i].hasReceipt)
    if there is a receipt available will
    Code (CSharp):
    1. IPurchaseReceipt[] receipts = new IPurchaseReceipt[0];
    2. receipts = validator.Validate(receipt);
    3. for (int j = 0; j < receipts.Length; j++)
    4. {
    5.     GooglePlayReceipt google = receipt as GooglePlayReceipt;
    6.     if (google.purchaseDate >= subscriptionExpiryDateTime)
    7.     {
    8.     subscriptionExpiryDateTime = google.purchaseDate;
    9.     }
    10. }
    Find the receipt with the "latest" purchase date. Based on that date we will later calculate the "remaining access time".
     
  2. jacagugle

    jacagugle

    Joined:
    Mar 12, 2015
    Posts:
    15
    From Unity manual (https://docs.unity3d.com/Manual/UnityIAPRestoringTransactions.html):

    "On platforms that support it (e.g. Google Play and Universal Windows Applications) Unity IAP automatically restores any products the user owns during the first initialization following reinstallation; the ProcessPurchase method of your IStoreListener will be called for each owned item."

    That's mean that ProcessPurchase is called on every bought item, but only if it is a first application launch after REINSTALLATION.

    Just run it somewhere else after initialization, because ProcessPurchase is not run after app launch.

    @Edit: I don't get your code, but if you're sure it works ok, than the solution I wrote above should fix your problem.

    P.S. I hope you validate subscriptions with remote server...
     
    Last edited: Oct 5, 2016
  3. m4ko

    m4ko

    Joined:
    Feb 8, 2013
    Posts:
    16
    We actually call UpdateSubscriptionStatus after Init. So that is not the problem.

    The code validates if the subscription is still running. You get the DateTime of when the subscription was bought and from there on you can calculate the expiry date by adding the subscription length. The code above goes through the receipts and gets the "latest" DateTime.

    But after the "renewal" of a subscription there is no new "receipt" available. Therefore doing something like:
    purchaseDate + subscriptionLength -> ExpiryDate
    doesn't work.

    My main question is:
    If not based on the purchase date (it doesn't change / we don't get a new receipt after auto renewal) - how can we check if a subscription was actually renewed?
     
  4. jacagugle

    jacagugle

    Joined:
    Mar 12, 2015
    Posts:
    15
    erika_d likes this.
  5. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,198
    Hi @m4ko,

    We are currently working on better documentation about our support of subscriptions.

    Did @jacagugle suggestions work for you?
     
    CrandellWS likes this.
Thread Status:
Not open for further replies.