- Home /
In App Purchasing is NOT working!!!
I have tried the last two weeks to get this working using multiple plugins.
I am using Prime 31 as the pluging now and here is the rundown.
I have a sprite acting like a button, when someone presses this texture, I want the google payment screen to pop up (which it does) and when the payment succeeds, add 500 coins to the player pref?
Here is my code
using UnityEngine;
using System.Collections;
public class coins500 : MonoBehaviour {
static int coins01;
static int bought;
void OnEnable(){
IABAndroidManager.purchaseSucceededEvent += purchaseSucceededEvent;
}
// Use this for initialization
void Start () {
var key = "etc";
IABAndroid.init( key );
IABAndroid.startCheckBillingAvailableRequest();
}
void purchaseSucceededEvent( string productId )
{
coins01 = 500 + PlayerPrefs.GetInt ("Coins");
PlayerPrefs.SetInt ("Coins", + coins01);
PlayerPrefs.Save ();
}
void OnMouseDown () {
IABAndroid.purchaseProduct ("android.test.purchased");
}
}
}
It wont give the player the 500 coins when the purchase works? what im I missing???
Signed you apk with the matching Hash you registered on Google Developer Console?
Yeah, I just didnt post it here but on my end I have the key where its supposed to be.
The payment screen pops up and can "pretend" pay for it, but somehow its not giving the player the 500 coins?
Answer by psycocrusher · Nov 27, 2014 at 04:54 AM
You need to specify a product id:
void purchaseSucceededEvent( string productId ){
if(productId == "YourProductID"){
coins01 = 500 + PlayerPrefs.GetInt ("Coins");
PlayerPrefs.SetInt ("Coins", + coins01);
PlayerPrefs.Save ();
}
}
That fixed it and the fact that you need to publish your store page on Google Developer Console.
A word of caution:
You should not store your in-app purchased products information in PlayerPrefs as they are not at all secure. User can easily change this data. Try to use some other method like binary files with encryption to make it a little more secure.
Adding that if-statement would not fix the problem. It would just restrict it to the purchased item (if it was working).
Answer by Eck · Nov 27, 2014 at 02:35 PM
It looks like the answer was publishing the store page on Google Developer Console.
Next time, you can attach a debugger or throw in some Debug.Log messages to see what's going on. If you would have put some log messages in purchaseSucceededEvent, you probably would have seen that you never got those messages because the purchase never succeeded.
Your answer
Follow this Question
Related Questions
Can't understand OpenIAB skus 0 Answers
ingameshop tutorial c# 1 Answer
i need a script to remove ads by with an in app purchase subscrition 0 Answers
Can't import IAP store package 0 Answers