How To Sell Digital Content from your Applications Via Google InApp Billing
Google Play provides you with inapp billing services to enable you to sell digital content from within your app. This service can be used to sell a wide range of content that includes downloadable content such as media files or photos, virtual content such as game levels or potions, premium services and features, and more.
In-app Billing can be used for products like:
- Managed In app products : Managed Products enables you to sell content, services or features to users from within your app one or more times with no time interval.
- Subscriptions, (recurring, automated billing) : This is a recurring process and you can cell products services and features within your app with monthy or annual billing. Subscriptions can be for almost any type of digital content and the app could be of any type – even a game.
The good part is that your application does not have to directly process any financial transactions when you use in-app billing service – Google Play handles all the checkout details. The checkout service used at the backend is the same that is used for application purchases. This provides users with a familiar purchase flow.
For implementing in-app billing, there is no special account or registration required. Any application that you publish on Google Play can be used. A Google Play Developer Console account and a Google Wallet Merchant account will however be required.
Google InApp Billing Version 3:
Google InApp Billing Version 3 API supports managed in-app products and subscriptions. This makes integration of in-app billing in your applications easy. This version comes with new features with improved synchronous purchase flow, APIs to let you track the ownership of goods and also enables local caching of in-app purchase data.
Let’s take a look at the purchase flow with the version 3 API:
Your app sends a isBillingSupported request to Google Play to check version compatibility of your in-app billing API. getPurchases request is sent to know users Inapp purchases. If request is successful, Google Play returns bundle that contains a list of product IDs of the purchased items, a list of the individual purchase details, and a list of the signatures for the purchases. You can request getskudetails if you want to show users all the products configured in the developer console. You can even initiate the purchase for an app if it is not owned by the user. In order to start a purchase request, send a getBuyIntent request. This request should contain the product id and other parameters. You should record the product ID when you create a new in-app product in the Developer Console.
Consuming In-App Products
Google play records all successful purchases of in-app products by users. Once an in-app product is purchased by a user, it is said to be “owned”. In-App products in the “owned” state cannot be then purchased from Google Play. The product is available only when you send a consumption request to Google. This reverts the app to an “unowned” state. This process discards all the purchase data.
Basic sequence for consumption request:
- Requesting getPurchases to get list of products owned by user.
- If we want user to make payment already owned products We should call consumePurchase request for that product.
- Returns SUCCESS/FAILURE
In-App products – Consumable and Non-Consumable
This decision is left to you – you can select whether your product should be treated as non-consumable or consumable. Here’s how they are different:
These items are permanently associated with the user’s Google Account once purchased.
With consumable items, you can implement consumption and can be made available for multiple items.
Provisioning of your in-app product means dispensing the benefits or effects of the purchased item in your application. This means that you must send a consumption request to Google Play and receive a response for success that indicates that the consumption was recorded before you provision a consumable product.
Here’s how you manage consumable purchases in your application:
Basic flow for purchase of consumable products:
- getBuyIntent call launches a purchase flow.
- If the purchase is completed successfully, you get a response Bundle from Google Play.
- Consume the purchase with a consume Purchase call.
- Google Play sends a response code if the consumption was successfully completed.
- If yes, you can then provision the product in your application.
After that’s done, whenever a user starts up or logs on to your application, and if he has any outstanding consumable in-app products, make sure that you consume and provision them. Here’s the recommended app startup flow if you implement consumable in-app products:
- Query the pre owned in-app products with the getPurchases request.
- In case there are any consumable in-app products, call the consumePurchase.
- Ensure that you get a response code from Google Play for successful completion of consumption.
- After successful consumption, provision the product in your app.
Google Play client caches the in app billing information locally this information can be queried by using Version 3 API. You can use the getPurchases call to get this information more frequently. Version 3 APIs process this request first through cache instead of network connection. This greatly speeds up the response time.
Reserved product IDs for testing static In-app Billing responses:
- android.test.purchased: An in-app billing request with this product ID generates a result from Google Play similar to a successfully purchased item. This typically includes a JSOM string with fake information for purchase.
- android.test.canceled:In-app billing request with this product ID results in Google Play responding as thought the purchase was cancelled. This generally occurs when there is an error in the order process such as an invalid credit card or user’s order being cancelled before charging.
ded: When an in-App billing request is made with this ID, Google Play generates a result as thought the purchase was refunded. Note that refunds cannot be initiated via Google Play. They must be initiated by you as a merchant.
- android.test.item_unavailable:With this product ID, Google Play responds as though the item that is being purchased is not in the list of products on your application’s product list.
Setting up Test purchases:
With this, you can test your in-app billing implementation by making actual purchases.
- Upload your signed APK application as a draft application to the Developer Console.
- Add items to the application’s product list. (Product Ids needs to used in code)
- Get Public key
- Install signed apk application on testing Android-powered device.
- Add Email Accounts from which device your testing as test accounts.
- Verify that your device is running a supported version of the Google Play application or the MyApps application.
- Make in-app purchases in your application.
After testing application with real transaction you can publish application.