How can i implement in-app purchases in my application?
I want to disable ads if the user paid me.
I spend a lot of hours to figure how it works by looking for tutorials.
I saw all the lectures on youtube about that.
I read on google developer site:http://developer.android.com/google/play/billing/billing_admin.html
I saw some example codes.
So,
I understood the concept
I know how:
1. create new product.
2. create a test account for testing.
3. publish my application to beta/alpha.
So,my question is:
What should I do in code?How to manage it correctly?
If user paid money for removing the ads how the application know if to show him the ads or not?Do i need to save the data locally manage it with SharedPreference or i getting the status about his purchases automatically? What will happen if the user replace his device?Google remember his account and his purchases?
I really need a basic example :(.
Like few methods that make "buy()" and "isOwned()" for checking if the current user has paid ..
Help me please
First of all implement In-app purchase in your application, you can follow this link.
When user purchased any item successfully, success status will be sent from google.
After purchasing successfully, store some flag value in SharedPreferences, SQLiteDatabase or in your server database through webservices.
Now whenever you are showing ads in your application, check flag value you have stored.
1. if flag shows that user have purchased item, don't show ads.
2. if flag value shows that user did not purchase anything show your ads.
Google remember his account and his purches?
Google will fetch all purchases from user's email id. You can restore purchase from the user, so whenever user uninstalls your app and you dont want user to purchase your item again, give them option of restore. Restore will give their product back and also give you success status.
Related
I am developing an app with android in-app subscription purchase with a self login procedure, basically which means multiple user can use single device to access app. Everything works fine as long as i use a single user in my app, but as i logout and login another user and try to do a subscription purchase it either tells me you already have this subscription or changes my subscription to new requested subscription.
This happens because previous user had a subscription which is reflecting in this user, as subscriptions/purchases are associated with the primary play store account.
So How can i manage this situation with multiple user each with a same or different subscription on a single device? Is it possible ?
Thanks in advance for help.
Please note that i am asking this question, in process of understanding a better way to implement and handle in-app billing in my application.
I just implemented in-app billing V3 successfully to my app. Now my question is, should i store the transaction details, in Database or on Server? If yes, why?
Let me explain my scenario a bit. In my app i have a premium upgrade, that users can buy to unlock certain features. Now, when a user purchases the upgrade, Google Play handles the transaction and lets me know whether the purchase was successful or not. So, if the purchase is successful, i will unlock the features for that user, and store in preferences, whether the purchase is successful or not.
When the application launches, i check(every time), whether the product is purchased or not, and update my application based on that. What happens if the device is not connected to internet? I will go with what the preferences have in currently.
What are the downsides of this approach? When will it fail? and how is storing data on Server help me in better implementation?
I have working app that sells in-app products (InApp billing v3).
Recently I've made an update for this app and made a terrible mistake there: I consumed some of purchases I didn't want to consume.
I issued an update and users updated the app and then wrote me they have no purchased access. (As I found later, I consumed wrong items).
So I have some questions now:
Is there a way to restore consumed purchases or I should return payments to my users?
Is there a way to find out how many and which purchases were consumed?
If returning payments, is there a way to find out if user still has the product or is it consumed with out changing the app (through google services)?
Thanks.
According to what I have understood from your question, It seems like you want to purchase product only once.
What I wished to ask: is there a way to request information about consumed products like about owned products.
you can get response or it's information in any type(Managed Product, Unmanaged Product, Subscription) in the onActivityResult method() check my below link.
In-app billing-v3 error in activity result
but I would not prefer you to manage it customly as you told for one time purchase product(not consumable product). You should go with the Manage product.
Managed In-app Products:
Managed in-app products are items that have their ownership
information tracked and managed by Google Play. When a user purchases
a managed in-app item, Google Play stores the purchase information for
each item on a per-user basis. This enables you to later query Google
Play at any time to restore the state of the items a specific user has
purchased. This information is persistent on the Google Play servers
even if the user uninstalls the application or if they change devices.
for more information about product type
you can query any time you want and you will get the product information, and even you don't need to manage if user has already purchase this product or not.
Is there a way to restore cnsumed purchases or I should return payments to my users?
Better option is you should give the payments back to the user and for the next time check the whole app once using dummy product "android.test.purchased" and update your app.
Is there a wat to find out how many and which purchases were consumed?
You have to check in the Google wallet because all transaction should be handle by the it, check if it gives you product type or not. Using your google developer console credential you can signed into google wallet.
If returning payments is there a way to find out if user stil has the product or is it consumed with out changing the app (through google services)?
as per above answer you have to check in google wallet, according to my knowledge they are provide us all of information about product type with user detail.
Let me know if I have not properly understood your question.
Hope it will solve your problem.
I use consumable purchases (user may buy one item many times, in my app it convert to digital good) and need ability to restore purchases in future.
I think, there is only way to do this is save user email on server side and when I need to restore purchases, I request user autorization thru Google Play Services, send email to server and restore all data.
It is possible to get user email by which the user makes a purchase after purchase flow?
Or, it may be, there is another method for restoring consumable purchases?
Authorization in the application is not desirable, even though it would solve all problems!
It is possible to get user email by which the user makes a purchase after purchase flow?
When a user purchases an in-app item, Google Wallet assigns the transaction a unique and permanent order number. Google Play provides that order number to you at the conclusion of the purchase flow, as the value of the orderId field of the PURCHASE_STATE_CHANGED intent.
In your app, you can use the order number as a general-purpose identifier for the in-app purchase transaction. After the purchase, you can use the order number as a means of tracking the transaction in reconciliation reports and for customer support.
see Working With Order Numbers for more information
My suggestion would be to link the user to the orderId.
I'm going to guess a few follow up questions you may have:
How to link the user to the orderId?
Probably a simple login / authentication. You could use their Google Account (every Android user has one) - see Android Account Manager. This is a nice approach since your application does not have to handle any passwords - yay!
I want the same user on another phone to get those purchases/user data...
Not really possible without a login - see above (or something to uniquely identify that user) that syncs user data from the cloud to the new/other device.
Or, it may be, there is another method for restoring consumable purchases?
You cannot restore a consumed purchase with Google IAP. Double check whether you want to be using non-consumable purchases instead :)
additional source: IAP v3 API documentation.
Is it possible to see what is available for purchase with the google in app purchase v3.
I have looked everywhere and I cannot get a hint of how to check if an item you want is available for purchase or not (e.g. I want to have a product in the app at a later time, and I check if I have added it to inapp purchases yet or not, without uploading a new app with those updates or a new database with those updates.
Is this possible, is there a way to query which items are available for purchase?
Not completely.
If you have the SKU code of your product, you can query its details using getSkuDetails(). However, you will need a list of the codes beforehand.