Preparing for in-app billing

When implementing in-app billing, there needs to be a selection of products or subscriptions available for the user to purchase.

Getting ready

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.

Note

Two accounts are required for testing because Google does not allow purchases to be made from the merchant account.

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.

How to do it...

Before we prepare the Play Store app listing, we need to prepare the app package for upload:

  1. We can either create a new, empty Xamarin.Android app project or use an existing project.
  2. We then need to add the billing permission to the app:
    [assembly: UsesPermission("com.android.vending.BILLING")]
  3. Finally, we need to build and sign the app package, ensuring that the package name and keystore is that of the final app. (Refer to Chapter 13, Publishing Apps)

Once we have our app package, we need to upload it to Google Play using the merchant account:

  1. We need to upload the package we just created to the Alpha channel. (Refer to Chapter 13, Publishing Apps).
  2. Then, we must ensure that we have added the developer/tester account to the uploaded package. (Refer to Chapter 13, Publishing Apps).
  3. Lastly, we must publish the app.

Once the app is uploaded, we start creating the products that we will be providing to the user:

  1. Select the In-app Products section in the console and click on the Add new product button at the top of the page.
  2. Next, select the Managed product button, enter a product ID, and click on Continue:
    How to do it...

    Adding a new product

  3. On the next page, we now enter the rest of the product details, such as the title, description, and price.
  4. Finally, at the top of the page, we click on the Save button, and then activate the product using the adjacent dropdown:
    How to do it...

    Save and activate the product

  5. Similar to the process of adding products to purchase, we can also add recurring subscriptions by selecting the Subscription option in the dialog:
    How to do it...

    Adding a new subscription

  6. On the next page, we complete the fields, just like we do with normal products, and with the additional billing and trial periods.

How it works...

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.

Note

Two accounts are required for testing as Google does not allow purchases to be made from the merchant account.

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.

Note

If the app is not available to be published, an empty app can be used as a placeholder.

If the com.android.vending.BILLING permission is not specified in the app, then products cannot be added to the app listing.

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.

Tip

Providing products that can be purchased repeatedly is achieved by consuming the product immediately after the purchase completes.

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.

Tip

Not all regions support in-app billing because some regions do not support Google Wallet.

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.

Tip

Because pricing cannot be changed for a subscription, a new subscription can be created and used in the app instead. Existing users will be charged according to the old price, and new users will be charged the new price.

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset