I folloed this tutorial to implement in-app in my application:
http://blog.blundell-apps.com/simple-inapp-billing-payment/
The user can now purchase my item (com.myitem) with in-app system. After that, I set in a Shared Preference that the user has been purchased the item.
The problem is if the user uninstalla and reinstall the app.
So the question is: how can I check if the user has been already purchased the item?
I know that I should use restore BillingHelper.restoreTransactionInformation(...) on RESTORE_TRANSACTION...but where, and how?
I checked Dungeon example, but it seems to hard and complex to unterstand. There's a simple way to do that?
Thank you
Using RESTORE_TRANSACTION is the only way if you use managed purchases. If you use unmanagaed purchases, you can store the purchase state on your own server, but that is hardly simpler. There is nothing complex about RESTORE_TRANSACTIONS: you just fire the command and you get notified with transaction information that is in the exact same format as what you get when you first purchase an item. You should process it in the exact same way, and chances are you already have the code for that in your app. Testing this is somewhat harder, because it doesn't really work with test accounts, and you need a live app. Go over the official documentation again to understand how it works.
Related
I know that they are possible since I implemented consumable purchases and they work but:
If I upload a new version of the app or re install it the consumable purchases are gone. Does not matter if for iOS or android. I used the device ID but that is not reliable and does indeed change in some scenarios
I would like to offer inapp purchases (consumable) and keep track how many a user has. Ideally over multiple devices but for sure for multiple installations (meaning they keep them after updates or reinstalls)
Is this even possible without some kind of login? Is it possible to implement subscriptions without this problem? I use revenuecat if that matters but asking more generally
In case of consumable in app purchase it is definitely lost and cannot be recovered across devices without saving them for the relevant user. You may have to create your own saving and recovery system if you wish to make it available across devices.. maybe you can take a look at non consumable products or subscription
Good afternoon
Theoreticaly Possibly, but there are several ways that you need to use all together in order for everything to work correctly.
For example - It is necessary to store the user_id in the keyChain, then the saved id will not change when reinstalling (this only applies to iOS). It is also necessary to get information from the Receipt for different users (with different devices) but having one check and merge them. Therefore, it is desirable to have 2 ids for the user user_id and device_id. You need to receive and process webhooks from Apple/Google to understand the current status of a particular product. Doing this on the client is not the most pleasant experience. Some of this is generally impossible to do only on the client side.
Better use the ready-made solution Apphud, RC ...
If you have a free time and a team of backend developers, then you can implement all this yourself.
Look at the internal implementation of the services above (the code is open) how they work with Receipts and ids. You will understand that without the usage of unique identifiers you will encounter a lot of problem cases.
I am looking to restrict access to a new widget I have added to one of my Android apps, so that it is available as an In-App purchase.
Is there a way to check to see if the widget as been purchased and if not the stop the user from being able to use it?
I can easily query items in Activity classes but in the AppWidgetProvider I am struggling to get there.
If it is possible, could you provide either a link or some sample code to nudge me in the right direction.
Okay, since there was no help I managed to find a work around myself ;)
Incase anyone else wants to know :-
When the In-app product is purchased I add a unique identifier to the shared preferences and recall it when it tries to create the widget.
I'm trying to implement in-app billing, where the only thing my app sells is a monthly subscription. I've gone pretty much copied the Dungeons example that Android provides and it works, but it seems overly complicated for the one thing I have to sell (and I know I shouldn't be copying it anyway).
The Dungeons example has a PurchaseDatabase class that keeps track of all of the user's purchases. Since there is only one purchase in my app, rather than having a database, it seems like it would make more sense to just have something like a SharedPreference/boolean "isPurchased" and update/check for that when I start up the app... Now I don't really know much about security, but that just seems to ring warning bells and would probably be very hackable.
So, how should I store/restore this one piece of data? What do I need to save and keep track of, anyway?
Edit: Found this In-app billing. How to store information that user has paid? . It would seem that I should use a SharedPreference, but this question still stands: do I just save a boolean "isPurchased" or should I keep track of orderId, developerPayload, etc?
If you just save a flag in shared preferences, any user with a rooted device can flip the flag at will and be 'subscribed' without paying. So you should at least do some obfuscation. Here's a sample way to do it. Additionally, there is an API to check for subscription state, so you should check periodically to make sure the subscription is valid.
I've seen this question: Android - how to check if in app purchase has already been done?
It is not very clear to me however. I am using the AndroidBillingLibrary, mentioned in the answer, and I have a couple of questions.
When using restoreTransactions(), does that mean that at that point the purchases are stored on the device itself? Couldn't that be manipulated somehow?
And what if I buy an item on an other device, how does the first device know this? Do I need to restore again?
Thanks in advance
For the first question, every purchase is managed with an ID, thus only managed items work with restoreTransactions(). Also, restoreTransactions() does not work for reserved Product IDs. Thus it is still safe.
Ideally you should call restoreTransactions() every time the app runs. The Key thing is that all transactions are paired with the device/user ID (not sure how Google handles authentication on their server side but I assume it is using a combination of your Google account as well as the phones that the Google account is paired to).
So, if someone were to modify the transaction file, it will get invalidated when it is compared to the logfile on Google's side.
Hope this clarifies things :)
I'm searching for a tutorial or an explanation on how to remove advertisement in my application with in-app purchase?
I will put some ads with ad-mob in my app but I also want, that the user can disable the ads when he pays a little donation. Do you know a site or tutorial where I can find a step-by-step explanation how to do this?
Or do I need to publish 2 versions of my app? One with ads and one without ads for paying?
Don't use the SharedPreferences method because if the user flushes the app data or uninstalls/reinstalls your app their ad-free status will be lost.
A couple of ideas:
If your app has any kind of web based login or authorization, you can flag the user as having bought the ad free version by updating the web database's customer data and then disable ads in code following login and verification. This has the added benefit of following the user to new devices.
Use one of the several ways to get a unique device id, and store that in a web server database. On startup, query the DB to see if the device is ad-free. See Android Unique Device ID. This will only work for that particular device though.
The two apps approach is simple enough to get the job done too. :)
This presentation seems to explain an example and includes a link to source code at github:
http://gotocon.com/dl/2011/GeekNights/Tjen_penge_p%C3%A5_Android_ARH.pdf .
It stores the purchased upgrade at a sharedpreference.
However, I'm still looking for a more secure and robust solution that works out the use-case explained here:
http://vlingo-en.custhelp.com/app/answers/detail/a_id/1785/~/moving-in-app-purchase-(ad-removal)-to-new-android-phone/p/180