I have a game I made with a button that allows players to unlock the next level for a dollar. I published this to Android and everything worked great, but something is not working with my in app purchase on itunes. I followed this tutorial:
https://unity3d.com/learn/tutorials/topics/analytics/integrating-unity-iap-your-game
I’m running Unity 5.4.3 and Xcode 8. On itunes connect, I have an in-app purchase with the product ID “next_level”, which you will see in my code below.
I only have one consumable, so I trimmed out a bunch of stuff I didn’t feel I needed. I know the line that is failing to happen is this one, but I don’t know why:
Productproduct=m_StoreController.products.WithID(productId);
For some reason my app can’t find the product on the store or can’t communicate with the store at all. Here’s the relevant parts of my code. If anyone can spot something I’m missing, I would greatly appreciate any assistance.
public class purchaser : MonoBehaviour, IStoreListener
{
private static IStoreController m_StoreController;
private static IExtensionProvider m_StoreExtensionProvider;
public static string cube_roll_consumable = “next_level”;
public void InitializePurchasing()
{
if (IsInitialized())
{
return;
}
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
builder.AddProduct(cube_roll_consumable, ProductType.Consumable);
UnityPurchasing.Initialize(this, builder);
}
private bool IsInitialized()
{
return m_StoreController != null && m_StoreExtensionProvider != null;
}
public void BuyConsumable()
{
BuyProductID(cube_roll_consumable);
}
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, cube_roll_consumable, StringComparison.Ordinal))
{
Debug.Log(string.Format(“ProcessPurchase: PASS. Product: ‘{0}’”, args.purchasedProduct.definition.id));
PlayerPrefs.SetInt(“Current Level”, SceneManager.GetActiveScene().buildIndex + 2);
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 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));
}
void Start()
{
if (m_StoreController == null)
{
InitializePurchasing();
}
}
}
Thanks in advance.