Hello,
Welcome to our Microsoft Q&A platform!
You can check one issue in github here Subscription lifecycle .
It depends on the platform.
Google Play
Not beautiful, but simple. Since Google recommends restoring purchases every time you launch and resume the app, and the plugin only returns your currently active subscriptions, you just need to check that your subscription is in the list.App Store
1st way - Apple recommended
Every time you want to check if your subscription is active, you'll need to validate receipt with Apple. This way you will get all the necessary information. There is no support in the plugin for this way and to get it right and safe without revealing your secrets you need to use a proxy server.2nd way - without validating receipt
It may be easier to implement and works ok as long as subscription status is not a life changer. You need to remember user subscriptions yourself (you can get the list restoring purchases, it returns all active and not active subscriptions, but there is no info about current auto-renewal status). From the token you can decode subscription expiration date and compare it with the system date to check if it is active. Important thing (Apple's advice), you are not spouse of restoring purchases on every start because it may show the store login popup and disturb the user, so it's a better idea to check the current status (restore purchases) only if the user has expired subscription to see if there is a new renewal.
To decode data from token you may use this code:
public static IDictionary<string, object> DecodeTokenAppStore(string token)
{
if (Device.RuntimePlatform == Device.Android)
{
return null;
}
if (String.IsNullOrWhiteSpace(token))
{
return null;
}
var data1 = System.Convert.FromBase64String(token);
if (!data1.Any())
{
return null;
}
var receiptDic = (NSDictionary)PropertyListParser.Parse(data1);
if (receiptDic == null)
{
return null;
}
var purchaseInfoContent = receiptDic.ObjectForKey("purchase-info")?.ToString();
if (string.IsNullOrEmpty(purchaseInfoContent))
{
return null;
}
byte[] data2 = System.Convert.FromBase64String(purchaseInfoContent);
var purchaseInfoDic = (NSDictionary)PropertyListParser.Parse(data2);
if (purchaseInfoDic == null)
{
return null;
}
var result = new Dictionary<string, object>();
foreach (var item in purchaseInfoDic)
{
result.Add(item.Key, item.Value.ToObject());
}
return result;
}
Hope it can help you.
Best Regards,
Jessie Zhang
---
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.