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.

AppGameKit Classic Chat / In app purchasing for Android

Author
Message
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 11th Feb 2013 20:46
Hi all.

Just a quick query - I've been told that the last beta has all commands fully functional for android, including in app purchasing. However when I went to play around with this tonight to see if I could figure it out, the play store where you upload the app advised that the billing api had been upgraded and that a license (really very ridiculously long code) was now allocated to each uploaded app, which then needs integrated into the app in order for purchases to be made.

Has anyone had any luck with android based purchasing?
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 13th Feb 2013 18:13
This needs a lot of documentation since changing the packageID in Android has become a bit complicated with all the third party additions (facebook, In App Purchase, etc). I shall make a note of doing this for the final 108 release.

The license key they talk about should be copied into the Security.java file, look for the base64EncodedPublicKey variable.
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Feb 2013 20:21
Hi Paul,

Right, I've found it in the java file, so I'm going to have a play around with it tonight to see if I can get anywhere over the next few days.

If I have any luck then I'll try and maybe post some kind of guide here if it might help - I've no objection to trying to help if I can.

Otherwise, I'll wait for the final v108 with the documentation (hoping that's not too far away!).

Cheers.
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 14th Feb 2013 19:13
Not wanting to send you in blindly I had a lot of trouble testing the IAP for Android:
-The APK must be signed and uploaded to the Google Play console and remain unpublished.
-The In App Purchase products must be marked as published in their little section
-You must use the same signed APK on the device you are testing with and be signed in with a testing email added to the Google Play developer account.
-It takes about 6 hours (roughly) for the signed APK you uploaded to become active and for IAP to start working in test mode. Before that you will get errors trying to purchase items.
-It costs real money to buy real items with a test email, you can use a test item "android.test.purchased" to check the response.
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 14th Feb 2013 23:38 Edited at: 14th Feb 2013 23:41
@ Paul,

Tell me about it - for the first time google are making Apple look sensible! Lol. I particularly like that you have to upload an IAP active app to activate the IAP section, but then you have to name the purchases for that app and the app must then call them by these specific ID's, so that app inherently cannot work until it's updated because you can;t set the ID's before uploadeding the app! Because that's not a pain in the backside google!!!

However I got most of that without a hitch - I signed and uploaded the app, it's live on the market, the purchases are set and ready to go, my email is in as a tester, and the android test purchase is coming back without error. However I do have two problems so far, one you can probably help with, the other isn't yours. Firstly, the purchases are failing saying "item not found" when I use the syntax
, however apparently this is an issue when it's your account and you have to do this from another account as you can't buy from yourself? Perhaps this is down to the fact I have the app live and not as a draft though, so I will try that. I also have a googlemail account and not a gmail account, which apparently also causes issues in draft apps according to the BB's. Is that the correct syntax however?

The issue you probably can help with though, is when I call
the purchase routine starts normally, however the rest of the code in the background continues to run. I can check for the presence of an activated product for managed IAP's, however the IAP I have set up are not managed - i.e. they are reusable, generic purchases (if you saw my showcase entry, you'll understand why this is). So the query I have is, and please bare with me, they apparently need to have a "consumed container" returned after purchase action is complete and the app has done what it needs to do (increase game coins, communicate with a server or whatever) so that googleplay knows it can be purchased again? Is this currently supported in android, and if so is it automatic? There doesn't seem to be a way to actually confirm from google that the user made the purchase and didn't press back before completion for this kind of purchase, going by the command set? If it can't it's not a problem, I just need to set up lots of managed purchases (set one up yesterday and am about to play with it now), but my server software manages purchases to ensure multiple device support, so I don't really need managed purchases.

Thanks for the help so far, once I get everything going (and I'm pretty sure I'm basically there) I'll share what I've learned.
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 15th Feb 2013 00:14
Quote: "apparently this is an issue when it's your account and you have to do this from another account as you can't buy from yourself?"


Correct, you must use an email that you add as a test email, not the email that owns the account to test real items.

Quote: "inapppurchaseaddproductid("com.company.appname.idnameofinapppurchase")"

You just do


Quote: "I can check for the presence of an activated product for managed IAP's, however the IAP I have set up are not managed"

You check for both in the same way. The difference is that Google will not let users purchase managed items more than once whilst unmanaged items can be purchased again and again. The process we use for checking either is

if ok = 1 then the item was purchased and you should take appropriate action. For unmanaged items it is highly recommended that you then notify a server to remember the purchase (for example when purchasing coins the number of coins the user has is stored online) as uninstalling the app would remove all record of it.
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 15th Feb 2013 00:59
Ah, that's perfect, I'll give that a bash. Alas, in eclipse I made the apparently fatal flaw of not realizing your keystore had to be kept, and saved the .apk with the same name over the top erasing it. So, as I'm unable to update the apk anymore, I'm starting all over again.

Hopefully, I'll update tomorrow once it's all live again.
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 25th Mar 2013 18:01 Edited at: 25th Mar 2013 18:03
I have a question about this process. How can we restore purchases on Android or check to see if a managed product has been purchased upon launch?

After purchasing a managed product with a test account and rerunning the app, I can't seem to ever get a '1' returned for GetInAppPurchaseAvailable(id) so none of the unlocked features are activated. When I click to unlock again, I get the notice "You already own this item." However, AppGameKit doesn't seem to differentiate that message from a cancel action and, even after this notice, GetInAppPurchaseAvailable(id) still returns 0. It'd be great if this could double as a restore feature so we would know they already own it (via the response from Google) and could unlock the features as needed.

Also, what if they aren't connected to the Internet when they launch the app after purchasing a product, is there any way to check GetInAppPurchaseAvailable(id) without being online once they have already purchased it previously?

I know that one solution is to store a value locally indicating they have unlocked the app, but if they uninstall or switch devices this value won't be transferred and Google will still need to be queried.
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 25th Mar 2013 20:09
@xCept,

I've already had this discussion with Paul, the in app purchasing for Android doesn't work in the last release, there's a bug that was apparently fixed and it's going to work in the next release.....whenever that is!
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 25th Mar 2013 20:17
Bummer That's one of the last lingering issues before I can put out a small app or two.
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 26th Mar 2013 12:29
Yeah, me too but I think they are working on sorting a final release with decent documentation. Or another project of their own. Lol.

The code still works though, you just can't tell if the purchase was cancelled. I would guess this will be rare, maybe add a software "are you sure you want to continue" warning before calling the code? I doubt then many would cancel. My project is linked to a server I coded so it handles what has been purchased, so I can verify later and manually remove cancelled purchases, and don't use managed purchases anyway, so that's an option you could look at maybe?
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 26th Mar 2013 17:05
@Santman, but it seems that I am unable to ever get GetInAppPurchaseAvailable(id) to equal 1 after the initial purchase if they close the app or launch it on a different device. Whether they cancel or hit OK when Google informs them they already own the product, AppGameKit returns 0 for this.

How do you manage to track users on the server--do you have a full account system in place that requires them to register first with their email address?
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 26th Mar 2013 19:45
Yes, I have a server coded through AppGameKit that runs on a desktop and that handles everything. Users create an account with a username, email and password, then the server tracks everything including purchases.

Have you tried the new beta that just came out? Does that not work for purchases either? I'm just installing and setting up everything now.
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 26th Mar 2013 20:00
I'm trying to avoid the necessity of user registration at this point. In 1089, I can successfully purchase in-app products on Android. However, I cannot seem to restore purchases or verify them upon relaunch of the app. If they've already purchased the upgrade and attempt again, Google alerts them that they already own it. However, when returned to the AppGameKit app there is no way to determine this and GetInAppPurchaseAvailable() always returns 0.
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 26th Mar 2013 20:54
Currently there isn't a way to restore purchases on Android with AGK. But for managed products when users try to buy them again they will succeed without charging the user.
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 26th Mar 2013 20:55
Are you setting it up correctly? Paul has responded to the main thread for the new beta saying the functions are accurate, so I will publish mine again and have a bash at the code to see if it's working for me, at which point I said I'd do a guide (he already sent me a code example as a basis to using it).
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 26th Mar 2013 21:18
Quote: "Currently there isn't a way to restore purchases on Android with AGK. But for managed products when users try to buy them again they will succeed without charging the user. "


Paul, in my managed in-app tests I have been unable to "unlock" the premium features if they purchased it previously and then attempt to purchase it again.

The notice is displayed "You already own this item" but then the AppGameKit app resumes and GetInAppPurchaseAvailable(0) still seems to return 0 instead of 1. This is the problem that I'm not sure how to get around.

Here is my code, having previously defined the first product (id = 0) and title, and ran InAppPurchaseSetup().



Am I doing something wrong or how would you suggest restoring purchases if I cannot get a return value of 1?
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 26th Mar 2013 21:40 Edited at: 27th Mar 2013 15:56
I'll see if I can replicate the issue, although it will take a while as Google take ages to recognise the new binary being uploaded.

Edit: It turns out that my suggestion no longer works as Google have rewritten their In App Billing API (version 3), I shall bring AppGameKit up to date with that version for the next beta.
Santman
13
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 27th Mar 2013 22:00 Edited at: 27th Mar 2013 22:50
Hi Paul,

I can confirm, I've rebuilt my app with the new beta and although the original problem I was having - the app not stopping while the purchase went through - a new one has surfaced. If the user cancels the purchase it's going back to it's main code no problem, but when I complete the purchase it crashes the app. I've then later got no way at all of telling if the purchase was successful. The code in full is as follows:



Don't think I'm missing anything, but the app just literally froze after the payment was authorised, and the app gave an old style message (black bar that faded out after a few seconds) saying my content would be available soon???

The item is a non managed purchase. When trying a managed purchase google quite correctly kicked me back saying i'd purchase it, but once again the app seemed unable to know that it effectively had permission to download it.

I plan to use unmanaged apps anyway so that's not so much an issue, but not sure why it crashed when I did purchase the app???

EDIT: sorry, maybe I should point out, if I use the back key to cancel the purchase, I get the message. When completing the purchase it hangs before the message so I'm assuming either on the
line or during the while:endwhile loop that it's failing to register and exit that. Not too sure which, I'll try playing with the loop and see.

EDIT: Ok, last edit. I've done some playing around and it is def the while:endwhile loop that's causing the problem in my code snippet. I added another message after the purchase code so it looks like this:


And it still hangs on a successful purchase. One odd thing though, the second message in my code displays first, then the one before that saying it's returned from the purchasing code after it?

I removed the while:endwhile loop altogether then both messages popped up just before the purchasing routine began, so that is clearly where it's dying when making a purchase is successful.

Hope this maybe helps you in some way...this is the very last hurdle to my app being ready for distribution now!

Login to post a reply

Server time is: 2024-11-24 09:57:39
Your offset time is: 2024-11-24 09:57:39