Hello.
I don’t really know what to do and how to fix this. This is my first time implementing IAP, I used this tutorial
to set this up.
My Code:
manager:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Purchasing;
public class IAPManager : Singleton<IAPManager>, IStoreListener
{
private static IStoreController m_StoreController; // The Unity Purchasing system.
private static IExtensionProvider m_StoreExtensionProvider; // The store-specific Purchasing subsystems.
public string GetKey = "getkey";
public string No_ADS = "no_ads";
void Start()
{
if (m_StoreController == null)
{
InitializePurchasing();
}
}
public void InitializePurchasing()
{
if (IsInitialized())
{
return;
}
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
builder.AddProduct(GetKey, ProductType.Consumable);
builder.AddProduct(No_ADS, ProductType.NonConsumable);
UnityPurchasing.Initialize(this, builder);
}
public bool IsInitialized()
{
return m_StoreController != null && m_StoreExtensionProvider != null;
}
public void BuyKey()
{
BuyProductID(GetKey);
}
public void BuyNo_ADS()
{
BuyProductID(No_ADS);
}
public string GetProductPriceFromStore(string id)
{
if (m_StoreController != null && m_StoreController.products != null)
return m_StoreController.products.WithID(id).metadata.localizedPriceString;
else
return "";
}
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);
}
// Otherwise ...
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.");
}
}
//
// --- IStoreListener
//
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
// Purchasing has succeeded initializing. Collect our Purchasing references.
Debug.Log("OnInitialized: PASS");
// Overall Purchasing system, configured with products for this application.
m_StoreController = controller;
// Store specific subsystem, for accessing device-specific store features.
m_StoreExtensionProvider = extensions;
}
public void OnInitializeFailed(InitializationFailureReason error)
{
// Purchasing set-up has not succeeded. Check error for reason. Consider sharing this reason with the user.
Debug.Log("OnInitializeFailed InitializationFailureReason:" + error);
}
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
// A consumable product has been purchased by this user.
if (String.Equals(args.purchasedProduct.definition.id, GetKey, StringComparison.Ordinal))
{
Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
// The consumable item has been successfully purchased, add 100 coins to the player's in-game score.
GameManager.Instance.StoreGetKey();
}
// Or ... a non-consumable product has been purchased by this user.
else if (String.Equals(args.purchasedProduct.definition.id, No_ADS, StringComparison.Ordinal))
{
Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
GameManager.Instance.StoreNoAds();
}
// Or ... a subscription product has been purchased by this user.
// Or ... an unknown product has been purchased by this user. Fill in additional products here....
else
{
Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id));
}
// Return a flag indicating whether this product has completely been received, or if the application needs
// to be reminded of this purchase at next app launch. Use PurchaseProcessingResult.Pending when still
// saving purchased products to the cloud, and when that save is delayed.
return PurchaseProcessingResult.Complete;
}
public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
{
// A product purchase attempt did not succeed. Check failureReason for more detail. Consider sharing
// this reason with the user to guide their troubleshooting actions.
Debug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));
}
}
and here is script on store buttons:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class StoreButton : MonoBehaviour
{
public enum ItemType
{
GetKey,
NoAds
}
public ItemType itemType;
public TextMeshProUGUI priceText;
private string defaultText;
void Start()
{
defaultText = priceText.text;
StartCoroutine(LoadPriceRoutine());
}
public void ClickBuy()
{
switch (itemType)
{
case ItemType.GetKey:
IAPManager.Instance.BuyKey();
break;
case ItemType.NoAds:
IAPManager.Instance.BuyNo_ADS();
break;
}
}
private IEnumerator LoadPriceRoutine()
{
while (!IAPManager.Instance.IsInitialized())
yield return null;
string loadedPrice = "";
switch (itemType)
{
case ItemType.GetKey:
loadedPrice = IAPManager.Instance.GetProductPriceFromStore(IAPManager.Instance.GetKey);
break;
case ItemType.NoAds:
loadedPrice = IAPManager.Instance.GetProductPriceFromStore(IAPManager.Instance.No_ADS);
break;
}
priceText.text = defaultText + "" + loadedPrice;
}
}
- Product IDs match with those from script.
- I waited 24h
- first check on dev acc, than check on tester acc, both same results in logcat
- ofc everything works in editor
- unity dashboard see that there are IAP set on google dev console with correct names.(edit - dashboard have under Platform column “Windows editor” so I guess it’s not recognized.
- tested on real devices, 3 phones and 1 tablet
edit: - I added product ID’s to the Unity dashboard under Monetization - In-app purchases, I don’t know I should do it but it’s only idea I’ve got so far.
- Unity version - 2018.3.11f1
- UnityIAP ver 1.22.0
I don’t really know where to start and what can I do now.
Please help.
edit.
btw. why all knowleage base and tutorials screenshots comes from old version of google dev console? Is it really that hard to update them to the current look? I know, everything is “findable” but implementing everything in Google Console is already very confusing so making it even more not-clear isn’t help anyone.
5011136–490175–logcat.txt (5.65 KB)
