I have a Unity3D Game for Android, in this game I'm using the Unity IAP System, all works fine, but I'm not able to get if the player doesn't have any of the three subscriptions that I have available. My current code is this:
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
// Purchasing has succeeded initializing. Collect our Purchasing references.
Debug.Log("OnInitialized: PASS");
m_GooglePlayExtensions = extensions.GetExtension<IGooglePlayStoreExtensions>();
// Overall Purchasing system, configured with products for this application.
m_StoreController = controller;
// Store specific subsystem, for accessing device-specific store features.
m_StoreExtensionProvider = extensions;
Dictionary<string, string> Dict = m_GooglePlayExtensions.GetProductJSONDictionary();
foreach ( Product item in controller.products.all)
{
if (item.receipt != null)
{
if (item.definition.type == ProductType.Subscription)
{
print("Subscription");
string json = (Dict == null || !Dict.ContainsKey(item.definition.storeSpecificId)) ? null : Dict[item.definition.storeSpecificId];
SubscriptionManager s = new SubscriptionManager(item, json);
SubscriptionInfo info = s.getSubscriptionInfo();
if (PlayerPrefs.GetInt("VIP") == 1)
{
if (info.getProductId() == ProductVIP)
{
if (info.isSubscribed() == Result.False)
{
PlayerPrefs.SetInt("VIP", 0);
}
}
}
else if (PlayerPrefs.GetInt("VIP") == 2)
{
if (info.getProductId() == ProductGVIP)
{
if (info.isSubscribed() == Result.False)
{
PlayerPrefs.SetInt("VIP", 0);
}
}
}
else if (PlayerPrefs.GetInt("VIP") == 3)
{
if (info.getProductId() == ProductDVIP)
{
if (info.isSubscribed() == Result.False)
{
PlayerPrefs.SetInt("VIP", 0);
}
}
}
}
}
When a player buy any subscription, I change the value of the Int "VIP" That is saved in the PlayerPrefs, so the game can know if has a subscription and which one. The code its supposed to get if is not subscribed, if yes, changes the VIP value to 0, indicating that has not active subscription