IAP failing on google play, is this because the app is in beta?
This may be something as simple as because the App is unpublished on google plays side and I've only uploaded a Beta version and therefore fails. BUT, if I publish it and it's not that, my plan to take over the world and make bazillions fails and no one will be able to buy anything and I'll end up as poor as now :)
Just to make things easier here's my entire purchaser script, the only thing I'm doing it clicking a button on the scene which calls a corresponding BuykProductIDConsumable99p() function on a button :
The returned Error is :
BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase
The code is :
using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Purchasing;
//DerivingthePurchaserclassfromIStoreListenerenablesittoreceivemessagesfromUnityPurchasing. public class Purchaser : MonoBehaviour, IStoreListener { private static IStoreController m_StoreController; //ReferencetothePurchasingsystem. private static IExtensionProvider m_StoreExtensionProvider; //Referencetostore-specificPurchasingsubsystems.
//Productidentifiersforallproductscapableofbeingpurchased:"convenience"generalidentifiersforusewithPurchasing,andtheirstore-specificidentifiercounterparts //forusewithandoutsideofUnityPurchasing.Definestore-specificidentifiersalsooneachplatform'spublisherdashboard(iTunesConnect,GooglePlayDeveloperConsole,etc.)
private static string kProductIDConsumable = "consumable"; //Generalhandlefortheconsumableproduct. private static string kProductIDNonConsumable = "nonconsumable"; //Generalhandleforthenon-consumableproduct. private static string kProductIDSubscription = "subscription"; //Generalhandleforthesubscriptionproduct.
private static string kProductNameAppleConsumable = "com.unity3d.test.services.purchasing.consumable"; //AppleAppStoreidentifierfortheconsumableproduct. private static string kProductNameAppleNonConsumable = "com.unity3d.test.services.purchasing.nonconsumable"; //AppleAppStoreidentifierforthenon-consumableproduct. private static string kProductNameAppleSubscription = "com.unity3d.test.services.purchasing.subscription"; //AppleAppStoreidentifierforthesubscriptionproduct.
private static string kProductNameGooglePlayConsumable = "com.unity3d.test.services.purchasing.consumable"; //GooglePlayStoreidentifierfortheconsumableproduct. private static string kProductNameGooglePlayNonConsumable = "com.unity3d.test.services.purchasing.nonconsumable"; //GooglePlayStoreidentifierforthenon-consumableproduct. private static string kProductNameGooglePlaySubscription = "com.unity3d.test.services.purchasing.subscription"; //GooglePlayStoreidentifierforthesubscriptionproduct.
private static string kProductIDConsumable99p = "ninetynine"; private static string kProductIDConsumable199 = "oneninetynine"; private static string kProductIDConsumable499 = "fourninetynine"; private static string kProductIDConsumable899 = "eightninetynine"; private static string kProductIDConsumable1499 = "fourteenninetynine";
private static string kProductNameGooglePlay99 = "com.myappname.twothousandbundle"; private static string kProductNameGooglePlay199 = "com.myappname.oneninetynine"; //Changed for forum post private static string kProductNameGooglePlay499 = "com.myappname.fourninetynine"; private static string kProductNameGooglePlay899 = "com.myappname.eightninetynine"; private static string kProductNameGooglePlay1499 = "com.myappname.onehundredk";
void Start() { //Ifwehaven'tsetuptheUnityPurchasing reference if (m_StoreController == null) { //Begintoconfigureourconnectionto Purchasing InitializePurchasing(); } }
public void InitializePurchasing() { //IfwehavealreadyconnectedtoPurchasing... if (IsInitialized()) { //...wearedonehere. return; }
//Createabuilder,firstpassinginasuiteofUnityprovidedstores. var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
regionProducts Added
builder.AddProduct( kProductIDConsumable99p, ProductType.Consumable, new IDs() { //{kProductNameGooglePlay99,AppleAppStore.Name}, {kProductNameGooglePlay99, GooglePlay.Name}, } );//Buy99p bundle
builder.AddProduct( kProductNameGooglePlay199, ProductType.Consumable, new IDs() { //{kProductNameGooglePlay199,AppleAppStore.Name}, {kProductNameGooglePlay199, GooglePlay.Name}, } );//Buy1.99 bundle
builder.AddProduct( kProductIDConsumable499, ProductType.Consumable, new IDs() { //{kProductNameGooglePlay499,AppleAppStore.Name}, {kProductNameGooglePlay499, GooglePlay.Name}, } );//Buy4.99 bundle
builder.AddProduct( kProductIDConsumable899, ProductType.Consumable, new IDs() { //{kProductNameGooglePlay899,AppleAppStore.Name}, {kProductNameGooglePlay899, GooglePlay.Name}, } );//buy8.99
builder.AddProduct( kProductIDConsumable1499, ProductType.Consumable, new IDs() { //{kProductNameGooglePlay1499,AppleAppStore.Name}, {kProductNameGooglePlay1499, GooglePlay.Name}, } );//Buy14.99
endregion
//Addaproducttosell/restorebywayofitsidentifier,associatingthegeneralidentifierwithitsstore-specificidentifiers. builder.AddProduct(kProductIDConsumable, ProductType.Consumable, new IDs(){{ kProductNameAppleConsumable, AppleAppStore.Name },{ kProductNameGooglePlayConsumable, GooglePlay.Name },});//Continueaddingthenon-consumableproduct. builder.AddProduct(kProductIDNonConsumable, ProductType.NonConsumable, new IDs(){{ kProductNameAppleNonConsumable, AppleAppStore.Name },{ kProductNameGooglePlayNonConsumable, GooglePlay.Name },});//Andfinishaddingthesubscriptionproduct. builder.AddProduct(kProductIDSubscription, ProductType.Subscription, new IDs(){{ kProductNameAppleSubscription, AppleAppStore.Name },{ kProductNameGooglePlaySubscription, GooglePlay.Name },});//Kickofftheremainderoftheset-upwithanasynchrounouscall,passingtheconfigurationandthisclass'instance.ExpectaresponseeitherinOnInitializedorOnInitializeFailed. UnityPurchasing.Initialize(this, builder); }
private bool IsInitialized() { //OnlysayweareinitializedifboththePurchasingreferencesareset. return m_StoreController != null && m_StoreExtensionProvider != null; }
public void BuyConsumable() { //Buytheconsumableproductusingitsgeneralidentifier.ExpectaresponseeitherthroughProcessPurchaseorOnPurchaseFailedasynchronously. BuyProductID(kProductIDConsumable); }
public void BuykProductIDConsumable99p() { //Buytheconsumableproductusingitsgeneralidentifier.ExpectaresponseeitherthroughProcessPurchaseorOnPurchaseFailedasynchronously. BuyProductID(kProductNameGooglePlay99); //BuyProductID(kProductNameGooglePlay99); } public void BuykProductIDConsumable199() { //Buytheconsumableproductusingitsgeneralidentifier.ExpectaresponseeitherthroughProcessPurchaseorOnPurchaseFailedasynchronously. BuyProductID(kProductNameGooglePlay199); //BuyProductID(kProductNameGooglePlay199); }
public void BuykProductIDConsumable499() { //Buytheconsumableproductusingitsgeneralidentifier.ExpectaresponseeitherthroughProcessPurchaseorOnPurchaseFailedasynchronously. BuyProductID(kProductNameGooglePlay499); //BuyProductID(kProductNameGooglePlay499); }
public void BuykProductIDConsumable899() { //Buytheconsumableproductusingitsgeneralidentifier.ExpectaresponseeitherthroughProcessPurchaseorOnPurchaseFailedasynchronously. BuyProductID(kProductNameGooglePlay899); //BuyProductID(kProductNameGooglePlay899); }
public void BuykProductIDConsumable1499() { //Buytheconsumableproductusingitsgeneralidentifier.ExpectaresponseeitherthroughProcessPurchaseorOnPurchaseFailedasynchronously. BuyProductID(kProductNameGooglePlay1499); //BuyProductID(kProductNameGooglePlay1499); }
public void BuyNonConsumable() { //Buythenon-consumableproductusingitsgeneralidentifier.ExpectaresponseeitherthroughProcessPurchaseorOnPurchaseFailedasynchronously. BuyProductID(kProductIDNonConsumable); }
public void BuySubscription() { //Buythesubscriptionproductusingitsthegeneralidentifier.ExpectaresponseeitherthroughProcessPurchaseorOnPurchaseFailedasynchronously. BuyProductID(kProductIDSubscription); }
void BuyProductID(string productId) { //Ifthestoresthrowanunexpectedexception,usetry..catchtoprotectmylogichere. try { //IfPurchasinghasbeeninitialized... if (IsInitialized()) { //...lookuptheProductreferencewiththegeneralproductidentifierandthePurchasingsystem'sproductscollection. Product product = m_StoreController.products.WithID(productId);
//Ifthelookupfoundaproductforthisdevice'sstoreandthatproductisreadytobesold... if (product != null && product.availableToPurchase) { Debug.Log (string.Format("Purchasingproductasychronously:'{0}'", product.definition.id));//...buytheproduct.ExpectaresponseeitherthroughProcessPurchaseorOnPurchaseFailedasynchronously. m_StoreController.InitiatePurchase(product); } //Otherwise... else { //...reporttheproductlook-upfailuresituation Debug.Log ("BuyProductID:FAIL.Notpurchasingproduct,eitherisnotfoundorisnotavailableforpurchase"); } } //Otherwise... else { //...reportthefactPurchasinghasnotsucceededinitializingyet.Considerwaitinglongerorretryinginitiailization. Debug.Log("BuyProductIDFAIL.Notinitialized."); } } //Completetheunexpectedexceptionhandling... catch (Exception e) { //...byreportinganyunexpectedexceptionforlaterdiagnosis. Debug.Log ("BuyProductID:FAIL.Exceptionduringpurchase." + e); } }
//Restorepurchasespreviouslymadebythiscustomer.Someplatformsautomaticallyrestorepurchases.ApplecurrentlyrequiresexplicitpurchaserestorationforIAP. public void RestorePurchases() { //IfPurchasinghasnotyetbeensetup... if (!IsInitialized()) { //...reportthesituationandstoprestoring.Considereitherwaitinglonger,orretryinginitialization. Debug.Log("RestorePurchasesFAIL.Notinitialized."); return; }
//IfwearerunningonanAppledevice... if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.OSXPlayer) { //...beginrestoring purchases Debug.Log("RestorePurchasesstarted...");
//FetchtheApplestore-specificsubsystem. var apple = m_StoreExtensionProvider.GetExtension(); //Begintheasynchronousprocessofrestoringpurchases.ExpectaconfirmationresponseintheActionbelow,andProcessPurchaseiftherearepreviouslypurchasedproductstorestore. apple.RestoreTransactions((result) => { //Thefirstphaseofrestoration.IfnomoreresponsesarereceivedonProcessPurchasethennopurchasesareavailabletoberestored. Debug.Log("RestorePurchasescontinuing:" + result + ".Ifnofurthermessages,nopurchasesavailabletorestore."); }); } //Otherwise... else { //WearenotrunningonanAppledevice.Noworkisnecessarytorestorepurchases. Debug.Log("RestorePurchasesFAIL.Notsupportedonthisplatform.Current=" + Application.platform); } }
// //--- IStoreListener //
public void OnInitialized(IStoreController controller, IExtensionProvider extensions) { //Purchasinghassucceededinitializing.CollectourPurchasingreferences. Debug.Log("OnInitialized:pASS");
//OverallPurchasingsystem,configuredwithproductsforthisapplication. m_StoreController = controller; //Storespecificsubsystem,foraccessingdevice-specificstorefeatures. m_StoreExtensionProvider = extensions; }
public void OnInitializeFailed(InitializationFailureReason error) { //Purchasingset-uphasnotsucceeded.Checkerrorforreason.Considersharingthisreasonwiththeuser. Debug.Log("OnInitializeFailedInitializationFailureReason:" + error); }
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) { //Aconsumableproducthasbeenpurchasedbythisuser. if (String.Equals(args.purchasedProduct.definition.id, kProductIDConsumable, StringComparison.Ordinal)) { Debug.Log(string.Format("ProcessPurchase:pASS.Product:'{0}'", args.purchasedProduct.definition.id));//Iftheconsumableitemhasbeensuccessfullypurchased,add100coinstotheplayer'sin-gamescore. //ScoreManager.score+=100; }
//Or...anon-consumableproducthasbeenpurchasedbythisuser. else if (String.Equals(args.purchasedProduct.definition.id, kProductIDNonConsumable, StringComparison.Ordinal)) { Debug.Log(string.Format("ProcessPurchase:pASS.Product:'{0}'", args.purchasedProduct.definition.id));}//Or...asubscriptionproducthasbeenpurchasedbythisuser. else if (String.Equals(args.purchasedProduct.definition.id, kProductIDSubscription, StringComparison.Ordinal)) { Debug.Log(string.Format("ProcessPurchase:pASS.Product:'{0}'", args.purchasedProduct.definition.id));}//Or...anunknownproducthasbeenpurchasedbythisuser.Fillinadditionalproductshere. else { Debug.Log(string.Format("ProcessPurchase:FAIL.Unrecognizedproduct:'{0}'", args.purchasedProduct.definition.id));}//Returnaflagindicatingwitherthisproducthascompletelybeenreceived,oriftheapplicationneedstoberemindedofthispurchaseatnextapplaunch.Isusefulwhensavingpurchasedproductstothecloud,andwhenthatsaveisdelayed. return PurchaseProcessingResult.Complete; }
public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason) { //Aproductpurchaseattemptdidnotsucceed.CheckfailureReasonformoredetail.Considersharingthisreasonwiththeuser. Debug.Log(string.Format("OnPurchaseFailed:FAIL.Product:'{0}',PurchaseFailureReason:{1}",product.definition.storeSpecificId, failureReason));} }
Please let me know which Noobish mistake I've made :)
Cheers
Diego
Update :
I changed the google play iap package name / created a new one, and ins$$anonymous$$d of na$$anonymous$$g it the consumable name 99p for example, I added the full com.myappname.ninetynine as the bundle name.
This changed the error message, it found my url link : Win Purchasing product asychronously: 'com.myappname.ninetynine'
It then says this : ProcessPurchase: FAIL. Unrecognized product: 'com.myappname.ninetynine'
I'll update again if I figure it out before someone replies.