so I'm writing an android app with a special in-app currency. You can buy this currency in packets of 1, 5, 10 etc through in-app billing. Here is how I implemented it:
Use managed products (When the app starts, I use IabHelper to query for purchased products)
As soon as the purchase completes, consume the purchase
My question is, what if step 3 fails? If the connection gets cut off or something, the purchase token will never get to my server. In that case, users will have paid for currency but their account won't get it. When my app starts again, and 1a runs, it won't find the purchase and it won't re-consume it either.
Is this reasoning correct? If so, do I need to store purchase tokens on the android side? Then, if something fails, I keep retrying until it works? It seems kind of messy... I was also thinking of making a "My purchases page" where you could see all your purchases, and then click them to redeem it if step 3 failed for some reason.
A successful purchase also generates a purchase token, which is a unique identifier that represents the user and the product ID for the in-app product they purchased.
Google Play's billing system is a service that enables you to sell digital products and content in your Android app. You can use Google Play's billing system to sell a one-time product or subscriptions on a recurring basis.
In-app Billing is a Google Play service that provides checkout processing for in-app purchases. To use the service, your application sends a billing request for a specific in-app product.
You should keep purchaseToken
on your backend. There are two reasons to do so:
The scenario to consume a purchase should look like this:
purchaseToken
Once you've received successful response from your backend, you should consume the item on Android side. If you've already added the virtual currency on your backend (without consuming the item) you should also return successful response so the item will be consumed without increasing user balance.
Keep in mind that it's very easy to repeat the same purchase even if it's already been consumed so purchaseToken
must be validated every time on your backend. If it already exists in your DB just do not increase the virtual currency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With