- Home /
Problem with IAP restore google play
Hi,
I have a problem with restoring already purchase a nonconsumabe product with Unity IAP on Android. They say in the documentation that it suppose to happen during initialization. But when I check if it has a Receipt, I get return false.
Here is code:
using System;
using UnityEngine;
using UnityEngine.Purchasing;
public class IAPmanager : MonoBehaviour, IStoreListener
{
private static IStoreController m_StoreController;
private static IExtensionProvider m_StoreExtensionProvider;
//private static string AppleNonConsumable = "";
private static string GooglePlayNonConsumable = "noADS";
void Start()
{
if (m_StoreController == null)
{
InitializePurchasing();
}
}
public bool isBought(){
bool status = m_StoreController.products.WithID(GooglePlayNonConsumable).hasReceipt;
return status;
}
public void InitializePurchasing()
{
if (IsInitialized())
{
return;
}
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
builder.AddProduct(GooglePlayNonConsumable, ProductType.NonConsumable);
UnityPurchasing.Initialize(this, builder);
}
private bool IsInitialized()
{
return m_StoreController != null && m_StoreExtensionProvider != null;
}
public void BuyNonConsumable()
{
BuyProductID(GooglePlayNonConsumable);
}
void BuyProductID(string productId)
{
if (IsInitialized())
{
Product product = m_StoreController.products.WithID(productId);
if (product != null && product.availableToPurchase)
{
Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
m_StoreController.InitiatePurchase(product);
}
else
{
Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
}
}
else
{
Debug.Log("BuyProductID FAIL. Not initialized.");
}
}
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
Debug.Log("OnInitialized: PASS");
m_StoreController = controller;
m_StoreExtensionProvider = extensions;
}
public void OnInitializeFailed(InitializationFailureReason error)
{
Debug.Log("OnInitializeFailed InitializationFailureReason:" + error);
}
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
if (String.Equals(args.purchasedProduct.definition.id, GooglePlayNonConsumable, StringComparison.Ordinal))
{
Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
PlayerPrefs.SetInt("IAP",1);
}
else
{
Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id));
}
return PurchaseProcessingResult.Complete;
}
public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
{
Debug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));
}
}
Answer by Marcos-Elias · Mar 12, 2017 at 05:10 PM
Same here! Certainly there is a bug, the function that process purchases are not being called at startup in my app. Need an urgent solution to this :(
Answer by stereoinmotion · Mar 16, 2017 at 08:28 PM
Same for us. Restore purchases is not working in Android, neither in iOS. In Android RestoreTransactions is not being called in app start. In iOS, calling
m_AppleExtensions.RestoreTransactions(OnTransactionsRestored);
through a restorepurchase button, does not prompt the user password dialog and always returns false.
Your answer
Follow this Question
Related Questions
Google Play Service LogIn Problem 0 Answers
Why am I receiving AnalyticsResult.TooManyRequests for any analytics custom event? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Unity 5 workaround for concave colliders 3 Answers