- Home /
trying to get in app purchases to work?
Hey everyone, anything I'm missing, I tried to do In app purchases for my game, I've set up my products in google play and everything is named the same, these are the messages i get in the unity editor but on android even if my game is published state you press the buttons and nothing happens but they work and unlock my content in the editor.
on my Android device, nothing happens buttons just flash when their clicked to the buttons are working and set up. (In editor they work and give my the goodies)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Purchasing;
using System;
using UnityEngine.Networking;
public class UnityStoreFront : MonoBehaviour , IStoreListener
{
private static IStoreController m_StoreController; // The Unity Purchasing system.
private static IExtensionProvider m_StoreExtensionProvider; // The store-specific Purchasing subsystems.
public static string ProductGems01 = "01_gems";
public static string ProductGems02 = "02_gems";
public static string ProductMegaGems = "01_mega_gems";
public static string ProductTitanium01 = "01_titanium";
public static string kProductIDNonConsumable = "nonconsumable";
public static string kProductIDSubscription = "subscription";
// Apple App Store-specific product identifier for the subscription product.
private static string kProductNameAppleSubscription = "com.unity3d.subscription.new";
private static string kProductNameGooglePlaySubscription = "com.unity3d.subscription.original";
public GameObject Account;
public AccountScript AccountScriptCS;
public GameObject ThankYouForSupportingObj;
void Start()
{
Account = GameObject.FindGameObjectWithTag("Account");
AccountScriptCS = Account.GetComponent<AccountScript>();
// If we haven't set up the Unity Purchasing reference
if (m_StoreController == null)
{
// Begin to configure our connection to Purchasing
InitializePurchasing();
}
}
public void InitializePurchasing()
{
if (IsInitialized())
{
// ... we are done here.
return;
}
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
builder.AddProduct(ProductGems01, ProductType.Consumable);
builder.AddProduct(ProductGems02, ProductType.Consumable);
builder.AddProduct(ProductTitanium01, ProductType.Consumable);
UnityPurchasing.Initialize(this, builder);
}
private bool IsInitialized()
{
// Only say we are initialized if both the Purchasing references are set.
return m_StoreController != null && m_StoreExtensionProvider != null;
}
public void Button_Unlock_Gems_01()
{
BuyProductID(ProductGems01);
}
public void Button_Unlock_Gems_02()
{
BuyProductID(ProductGems02);
}
public void Button_Unlock_Titanium_01()
{
BuyProductID(ProductTitanium01);
}
void BuyProductID(string productId)
{
// If Purchasing has been initialized ...
if (IsInitialized())
{
// ... look up the Product reference with the general product identifier and the Purchasing
// system's products collection.
Product product = m_StoreController.products.WithID(productId);
// If the look up found a product for this device's store and that product is ready to be sold ...
if (product != null && product.availableToPurchase)
{
Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
// ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed
// asynchronously.
m_StoreController.InitiatePurchase(product);
}
// Otherwise ...
else
{
// ... report the product look-up failure situation
Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
}
}
// Otherwise ...
else
{
// ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or
// retrying initiailization.
Debug.Log("BuyProductID FAIL. Not initialized.");
}
}
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, ProductGems01, StringComparison.Ordinal))
{
Debug.Log("You unlocked Gmes Good Times Gems 1");
AccountScriptCS.Gold += 10000;
AccountScriptCS.SaveMyGame();
ThankYouForSupportingObj.SetActive(true);
}
// Or ... a non-consumable product has been purchased by this user.
else if (String.Equals(args.purchasedProduct.definition.id, ProductGems02, StringComparison.Ordinal))
{
Debug.Log("You unlocked Gmes Good Times Gems 2");
AccountScriptCS.Gold += 220000;
AccountScriptCS.SaveMyGame();
ThankYouForSupportingObj.SetActive(true);
}
// Or ... a subscription product has been purchased by this user.
else if (String.Equals(args.purchasedProduct.definition.id, ProductTitanium01, StringComparison.Ordinal))
{
Debug.Log("You unlocked Gmes Good Times Titanium");
AccountScriptCS.Silver += 220000;
AccountScriptCS.SaveMyGame();
ThankYouForSupportingObj.SetActive(true);
}
else if (String.Equals(args.purchasedProduct.definition.id, ProductMegaGems, StringComparison.Ordinal))
{
Debug.Log("You unlocked Gmes Good Times Titanium");
AccountScriptCS.Gold += 990000;
AccountScriptCS.SaveMyGame();
ThankYouForSupportingObj.SetActive(true);
}
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));
}
}
Answer by zak666 · Jun 09, 2021 at 02:32 AM
Love it how no one in the unity community will help you with in app purchases for some reason.
App is published and everything
Your answer
![](https://koobas.hobune.stream/wayback/20220613034710im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
OpenIAB PurchaseProduct() not responding 0 Answers
Permissions added to Android Manifest, but Google Play not registering the change? 0 Answers
Unity IAP Issue - Android 1 Answer
Implement direct carrier billing in unity android for samsung galaxy store. 0 Answers
Can't Able to Add In-App Products at Google Play Console 0 Answers