When implementing in-app billing, there needs to be a selection of products or subscriptions available for the user to purchase.
Before we can develop and implement in-app billing, we will require two Google accounts. One will be the merchant account, which will publish the app to the Play Store and provide the products. The other will be used for development and testing of purchases.
The merchant account should be registered as a Google developer (http://play.google.com/apps/publish) and linked to Google Wallet (http://www.google.com/wallet/merchants.html). The other account only needs to be a Google account.
Before we prepare the Play Store app listing, we need to prepare the app package for upload:
[assembly: UsesPermission("com.android.vending.BILLING")]
Once we have our app package, we need to upload it to Google Play using the merchant account:
Once the app is uploaded, we start creating the products that we will be providing to the user:
Google has a few requirements before in-app billing can be implemented. The first is that the app be published to one of the channels on the merchant account. Then, the developer and the testers can use their own accounts to test the app.
The app must be signed and must include the com.android.vending.BILLING
permission. This permission is required so that the app can communicate with Google Play Services.
Once the app is uploaded and published, we can start adding the various products that are going to be available to the app. Adding products is easy and is done from the In-app Products section on the console. When adding new products, we can choose from either a managed product or a subscription.
Managed products are items that can be bought once and optionally consumed, so they can be repurchased. Subscriptions are recurring products that are periodically repurchased. In terms of a racing game, a nonconsumable product could be a new car, a consumable product could be fuel, and a subscription could be a club membership.
Both products and subscriptions require a product ID, which cannot be changed or reused. This ID is used when purchasing the item as well as when searching for items to buy. Although similar, both have various details that are used differently.
A product has a title, description, and a price, all of which can be localized to the user's region. Not all regions support in-app billing, so this must be considered if one of those regions is the target market.
Subscriptions also have a title and description but they differ in how the pricing works. In addition to a price, they have a billing, trial, and grace period. The billing period is how often the user will be charged for the product. This can range from a week to a year, as well as a custom seasonal date range.
The trial period is useful for providing the user with the subscription for a short period before charging the user. The user can then use the subscription for free and can cancel at any time within that period to avoid any charges. The user is charged only after the trial period is over. If the user cancels the subscription, then it expires immediately even though there may be days remaining in the trial period.
Grace periods are slightly different; they come into effect if there are problems with the user's payment method. This allows us to provide a short period before Google automatically cancels the subscription due to nonpayment.