SubscriptionInfo returns incorrect Expiry Date (Android Internal Testing)

Hi,
in our app we would like to make certain features only available, when a monthly subscription was paid. I have followed the code samples provided with the Unity IAP package in order to locally validate the subscription purchase and its expiry (let’s assume local validation will suffice for our purposes). However, I have encountered multiple issues during internal testing.

As expected during internal testing on the Google Play Store, our monthly subscription is renewed every 5 minutes instead of 1 month. I am using the SubscriptionManager in order to get the SubscriptionInfo once the ProcessPurchase callback is called with the following code snippet:

SubscriptionManager p = new SubscriptionManager(product, intro_json);
SubscriptionInfo info = p.getSubscriptionInfo();
Debug.Log($"Subscription info: \n" +
          $"id: {info.getProductId()} \n" +
          $"Purchase date: {info.getPurchaseDate()} \n" +
          $"IsSubscribed: {info.isSubscribed()} \n" +
          $"IsExpired: {info.isExpired()} \n" +
          $"IsCancelled: {info.isCancelled()} \n" +
          $"ExpireDate: {info.getExpireDate()} \n" +
          $"FreeTrialPeriod: {info.getFreeTrialPeriod()} \n" +
          $"FreeTrialPeriodString: {info.getFreeTrialPeriodString()} \n");

Where product is the product returned by the ProcessPurchase callback and intro_json was populated in the same manner as the IAP Demo.

My first issue is, that info.getExpireDate() will return a date 1 month in the future, even though the subscription will expire in 5 minutes. Is this behaviour intended?

Furthermore, I noticed that when I forward my local device time by one month, the purchase date will stay the original date, while the expiry date will be adjusted accordingly, i.e. now 2 months in the future relative to the date returned by getPurchaseDate().

Finally, we would like to implement a check for whether the subscription has expired in the app’s OnApplicationFocus method. I tried to get an updated subscription info when OnApplicationFocus is triggered by calling the same code as pasted above with the product returned by storeController.products.all. However, when I cancel my subscription during internal testing and return to the app, getSubscriptionInfo will still return an object where getExpireDate is 1 month in the future and IsSubscribed will return true even long after the 5 minute subscription is expired, thus my subscription prompt is not triggered. Once I restart the app, the product returned by storeController.products.all will have a null receipt again and my subscription logic will correctly trigger a purchase prompt.
Do I somehow have to update the storeController in order to receive an updated receipt, or am I using the SubscriptionManager incorrectly? Or am I encountering these issues simply because I am still in internal testing?

Thank you very much for your help!

The getExpireDate is expected. We have not yet found a reliable way to refresh the receipts as you mention, it is something we are looking into. In the meantime, you’ll want to check once, when the app starts and IAP is initialized.

I understand. Thank you for the quick reply!

Hello @JeffDUnity3D
I want Details from play store about subscription on have purchased in game.
how can i get this in unity?

I have already implement this code:

SubscriptionInfo subscriptionInfo = new SubscriptionInfo(_productId);

Debug.Log("Product ID: " + subscriptionInfo.getProductId());
Debug.Log("Purchase Date: " + subscriptionInfo.getPurchaseDate());
Debug.Log("Is Subscribed: " + subscriptionInfo.isSubscribed());
Debug.Log("Is Expired: " + subscriptionInfo.isExpired());
Debug.Log("Is Cancelled: " + subscriptionInfo.isCancelled());
Debug.Log("Is FreeTrial: " + subscriptionInfo.isFreeTrial());
Debug.Log("Is Auto Renewing: " + subscriptionInfo.isAutoRenewing());
Debug.Log("Remaining Time: " + subscriptionInfo.getRemainingTime().ToString());
Debug.Log("Is Introductory Price Period: " + subscriptionInfo.isIntroductoryPricePeriod());
Debug.Log("Introductory Price Period: " + subscriptionInfo.getIntroductoryPricePeriod().ToString());
Debug.Log("Introductory Price Period Cycles: " + subscriptionInfo.getIntroductoryPricePeriodCycles());
Debug.Log("Introductory Price: " + subscriptionInfo.getIntroductoryPrice());
Debug.Log("Expire Date: " + subscriptionInfo.getExpireDate());
Debug.Log("SKU Details: " + subscriptionInfo.getSkuDetails());
Debug.Log("Current Date > " + DateTime.Now);

But its shows me wrong Details like:

Product Id: < product id >
Purchase Date: 01-01-0001 00:00:00
Subscribed or not: True
Expired or Not: False
Cancelled or Not: Unsupported
Free Trial: Unsupported
Remaining Time: 10675199.02:48:05.4775807
Expire Date: 01-01-0001 00:00:00

i have to just check is subscribed or not and if subscribed true then expired or not using SubscriptionInfo IAP unity.

unity version is : 2020.3.20f1
IAP version is : 4.1.2

Do you have a subscription? Was the purchase successful? Was this a test purchase? And it actually shows “< product id >” ?

@JeffDUnity3D
No i don’t have purchased anything , i just add these things after initialise,
Yes product id is shows correct.

Correct, you won’t have the subscription info in the receipt until you purchase the product and generate the receipt.

Yes i understood @JeffDUnity3D .
But i want to check information of yearly or monthly IAP subscription when user open the application.
Because i want check that if user purchased yearly or monthly IAP subscription then i want to disable particular button.
Currently when user click purchase button and if user already purchase yearly or monthly subscription then error “subscription is already purchased” occurs from play store side but i need to check it when application start so i can disable purchase button.

So please let me know how to check is user already purchased IAP subscription or not in application start.

Thank You for quick response.

If a user has an active subscription, they will have a receipt. Please confirm in your testing.

@JeffDUnity3D
Yes i got the receipt.
Are you trying to say that i have to check receipt in application start?
if yes then please tell me how may i check receipt validation in application start without store receipt in player prefs or local space.
But i don’t want to store receipt in player prefs or local space because if user clear apps data then receipt also cleared.
So can you help me how can i manage or validate subscription because i have no idea how to do receipt validation and all things in application start.

IAP version : 4.2.1

You check the receipt at app start when you initialize IAP. You go through your product controller and check the receipts. See the Sample IAP Project for an example. No need to store receipts for non-consumables or subscriptions, we do that for you. https://discussions.unity.com/t/700293/3

Thank You @JeffDUnity3D it’s working for me.