Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Android / Need help with in app purchase setup

Author
Message
TDavid
11
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 20th Jun 2014 22:06
Hi.

It's me again. Having trouble. Again. With in app billing this time. When I trigger the purchase, the play store purchase overlay appears and returns an error "unable to find the item you're trying to buy" (in my langage).

In the google dev console, I have an in-app product set up. It's called "Remove ads (gamepremium)" set as a manageable product and its status is "active".

My app is configured as a beta version and the google account of my test device is in the testers list. Note that the app is "ready to be published" but it is not published yet.

In agk v1.021 tier 1, here's my setup code


Then, the purchasing code itself :


That's it. I can't figure out why it doesn't work. Could someone tell me what I did wrong ?

By the way, if I restart the app after a failed purchase and try to purchase again, the app forces close. If I clear data I can't try again but the problem comes back.
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 21st Jun 2014 06:50
This doesn't matter to your problem, but
inAppPurchaseSetTitle("com.myname.myapp")
Is visible to the end-user, maybe only on iOS now, but usually you put your actual app name in there. It is the title of the IAP window.

Also, a note - when your app launches it takes a few seconds for
getinapppurchaseavailable(0) to return anything, so you might want to move it to a main loop for the first run of the app and for, maybe 30 seconds.

Finally, on to your issue, your code looks OK, did you get your base64 key from the google dev console (Services and APIs) and enter it into AGKHelper.java? Also as of a couple weeks ago, Google is requiring that the apps be published for IAP to work. Just upload it as a beta and publish it to beta and you should be good to go (or alpha if you so choose). I've also never been certain, but I think you need to download it from the play store to make IAP work for testing. I'm not 100% on that though.

TDavid
11
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 21st Jun 2014 10:59 Edited at: 21st Jun 2014 12:13
Thanks again Naphier. I don't think I would have gone very far without your help. Or not as fast anyway.

At first I had the actual name of my app in inAppPurchaseSetTitle but since it didn't work, I put the package name in hopes it would work.

I had completely forgotten about the base64 key. I think that was the biggest issue. That's fixed now, thanks.

edit: everything seems to be in order now. Thanks again.
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 21st Jun 2014 23:24
oh took me a while to reply... yes it always returns something. I'm not sure if it is always 0 or 1, there may, just may be a -1 in there, I'd have to look at the java code to be more certain.

My code to restore purchases on android is (psuedo)
start_time# = timer()
if getFileExists("player.dat") = 0
first_run = 1
endif


//main loop
do
if first_run = 1 and timer() - start_time# < 60
if getInappPurchaseAvailable(no_ads_iap_index) = 1
gADS_OFF = 1
//write this data to a file player.dat
endif
endif
loop

TDavid
11
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 25th Jun 2014 14:40
I wrote the same first_run code except I run it for 30 seconds.

At the moment I uninstall and reinstall it every day to test the in app process and it crashes quite often when I launch the purchase query (which I copied from the online help example) :



Here is how I had it crash today :

When I launched the app, the signal icon was a white "3G" with up and down arrows. I suspect internet doesn't work when the signal icon is white, nevertheless getinternetstate() returned 1.

I waited 30 seconds for the purchase to be restored but it didn't (the "buy" button transforms into a "rate" button when it does).

I clicked the "buy" button and I got a google message saying the item had already been purchased. I followed the instructions and pressed back to go back to my app.

Normally, getInAppPurchaseAvailable(0) should have returned 1 during the failed purchase process, and "game_bought" set to 1. However, it wasn't. The "buy" button didn't turn into a "rate" button. When I clicked again on the "buy" button, the app crashed complaining about a nullpointer in IAPactivity.java line 20.
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 25th Jun 2014 19:35
Weird. From what I can tell the only thing that could possibly be null in the java files is the reference to the java activity.
Did you do the IAPSetup() and add products before this code?

Quote: "Normally, getInAppPurchaseAvailable(0) should have returned 1 during the failed..."

no it wouldn't. It would return 0.

If you post your logCat output during this error it might have more clues.

TDavid
11
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 26th Jun 2014 13:22
Yes, I put the IAPSetup near the top of my program. When I try to purchase it works a expected.

I think getInAppPurchaseAvailable(0) should return 1 because the play store states that the app has already been purchased, shouldn't it ?

How do I get a logcat in eclipse ? Right now I just build the apk and install it on my device.
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 26th Jun 2014 19:11
To get LogCat go to Window / Show View / Other and select LogCat
if it's not there then you might have to go the the Android SDK manager and install it.
You'll need to have your device connected to you PC in USB debugging mode. You'll need to google that for your specific device.
Once you do that plug the device in and use the Run option from Eclipse to run the app directly to the device. You'll see all o fthe debug output in the logcat window (usually down in the tabs with Problems/Console/etc)

You said getInAppPurchase(0) should return 1 during the failed process. I thought you were meaning it should return 1 if it was failing. You mean you expected it to return 1 but the process fails.

In Shape Time there's actually a few seconds between IAP setup and checking for restoring purchases because of loading assets. Maybe try adding a bit of a delay in there before starting up the restoration procedure?

TDavid
11
Years of Service
User Offline
Joined: 7th Feb 2013
Location:
Posted: 26th Jun 2014 21:12
About getInAppPurchase(0), when I clicked on the "buy" button I got a message stating the item had already been purchased. That's why I assumed it should have returned 1. But it didn't.

Awesome idea about the delay, as always with your advices. I'll implement it right away.
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 26th Jun 2014 21:14
Ah I see. that makes more sense now. Yes, I agree it should return a 1 in that case. I thought it did... annoying that it doesn't!

Login to post a reply

Server time is: 2024-02-25 04:08:53
Your offset time is: 2024-02-25 04:08:53