Search Unity

Checking a subscription expiration - Google Play Store

Discussion in 'Unity Analytics' started by VoxStudio, Apr 12, 2016.

  1. VoxStudio

    VoxStudio

    Joined:
    Jan 12, 2016
    Posts:
    16
    Hi!
    I've searched the forums and did not find an answer for this... How do I check if the user's subscription is still active? There's no expiration date field in the GooglePlayReceipt class (I'm using the GooglePlayTangle class for receipt validation), only the purchase date and the purchase state (Cancelled, Refunded and Purchased). According to Google Play Store documentation of subscriptions (http://developer.android.com/intl/ru/google/play/billing/billing_subscriptions.html#cancellation), when the user cancels a subscription, I still need to offer to him the subscription products until the subscription expires (today > expiration date).
    I know that I can use the Google Play API (http://developer.android.com/intl/ru/google/play/developer-api.html#subscriptions_api_overview) and check this for the expiration date field and others, but I really don't want to mess with OAuth protocols and things like that.
    So, I have no idea on how to check if the subscription is still active or not for Google Play Store. Any ideas??? Am I missing something?
     
  2. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    Do you have a server dispensing the subscribed to content? If so then you should put the expiration logic there. Using Google's API is advisable since it gives you the latest state of the purchase.
     
  3. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    354
    I will dispense from the application itself. How do I approach this?
     
  4. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    You could implement date checking on GooglePlayReceipt.purchaseDate to decide if the subscription in date.

    It would be very easy for a user to change the date of their device to make the receipt appear in date though.
     
    nicholasr likes this.
  5. hakankaraduman

    hakankaraduman

    Joined:
    Aug 27, 2012
    Posts:
    354
    From what I tested, purchaseState = Purchased is enough to check, to let know if anyone else is looking for this.

    It does not return Purchased when the subscription expired
     
  6. traunay

    traunay

    Joined:
    Oct 24, 2013
    Posts:
    16
    hi @hakandaruma,
    how do you test for subscription ended event in Google Play Store? I just added a subscription and tested a purchase but now I'm trying to see/debug if the subscription ended.
    It seems a waste of time if I have to wait a week just to see my code works or not :)
     
  7. Banderous

    Banderous

    Joined:
    Dec 25, 2011
    Posts:
    669
    @traunay you should validate the receipt and check that it has not expired, ie that the end date is not less than the current date and time.

    You can validate either on your server using Google's subscriptions API or locally using our validation library, though a local check is trivially defeated by changing the device's clock.
     
    erika_d likes this.