- Home /
Unity IAP doesn't work on Android
Hello guys, I am trying implement Unity IAP in my mobile game .In editor everything works. I have tested it just on my Android yet. So I have imported IAP from services, used script from Unity IAP implementation and attached it on GameObject in my first scene, made Alfa version with purchase product then when I downloaded game as tester and played it popup didn't show up. So I checked logCat which says there is no available product. Please do you have any ideas? Thanks for answers. In editor:
LogCat: I/UnityIAP(15348): IAB helper created.
I/UnityIAP(15348): Starting in-app billing setup.
I/Unity(15348): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
I/UnityIAP(15348): Billing service connected.
I/UnityIAP(15348): invoking callback
I/UnityIAP(15348): Checking for in-app billing 3 support.
I/UnityIAP(15348): In-app billing version 3 supported for com.xxxxxx.xxxxxxxxx
I/UnityIAP(15348): Subscriptions AVAILABLE.
I/UnityIAP(15348): VR supported.
I/UnityIAP(15348): onIabSetupFinished: 0
I/UnityIAP(15348): Requesting 1 products
I/UnityIAP(15348): QueryInventory: 1
I/UnityIAP(15348): invoking callback
I/UnityIAP(15348): Querying owned items, item type: inapp
I/UnityIAP(15348): Package name: com.xxxxx.xxxxxxxxxx
I/UnityIAP(15348): Calling getPurchases with continuation token: null
I/UnityIAP(15348): Owned items response: 0
I/UnityIAP(15348): Continuation token: null
I/UnityIAP(15348): Querying SKU details.
I/UnityIAP(15348): Querying owned items, item type: subs
I/UnityIAP(15348): Package name: com.xxxxxxxxx.xxxxxxxxxxx
I/UnityIAP(15348): Calling getPurchases with continuation token: null
I/UnityIAP(15348): Owned items response: 0
I/UnityIAP(15348): Continuation token: null
I/UnityIAP(15348): Querying SKU details.
I/UnityIAP(15348): onQueryInventoryFinished: true
I/UnityIAP(15348): Inventory refresh successful. (response: 0:OK)
W/Unity(15348): Unavailable product xxxxxxxxx -xxxxxxxxxxxxxx
W/Unity(15348): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
I/Unity(15348): Error NoProductsAvailable
IAP script:
public class IAPManager : MonoBehaviour, IStoreListener
{
private static IStoreController storeController;
private static IExtensionProvider storeExtensionProvider;
public static string productBonusCategory = "xxxxxxxxxxx";
// Use this for initialization
void Start()
{
if (storeController == null)
{
InitializePurchasing();
}
}
private void InitializePurchasing()
{
if (IsInitialized())
{
return;
}
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
builder.AddProduct(productBonusCategory, ProductType.NonConsumable);
UnityPurchasing.Initialize(this, builder);
}
private bool IsInitialized()
{
return storeController != null && storeExtensionProvider != null;
}
public void BuyBonusCategory()
{
BuyProductID(productBonusCategory);
}
private void BuyProductID(string productID)
{
if (IsInitialized())
{
Product product = storeController.products.WithID(productID);
if (product != null && product.availableToPurchase)
{
storeController.InitiatePurchase(product);
Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
}
else
{
Debug.Log("Purchasing Failed. Not aviable to purchase");
}
}
else
{
Debug.Log("Failed. Not initialized");
}
}
public void OnInitialized(IStoreController controller, IExtensionProvider provider)
{
storeController = controller;
storeExtensionProvider = provider;
Debug.Log("OnInitialize: PASS");
}
public void OnInitializeFailed(InitializationFailureReason error)
{
Debug.Log("Error " + error);
}
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs arguments)
{
if (String.Equals(arguments.purchasedProduct.definition.id, productBonusCategory, StringComparison.Ordinal))
{
Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", arguments.purchasedProduct.definition.id));
FirstGameManager.SetPurchaseValue();
}
else
{
Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", arguments.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));
}