- Home Startseite ホーム 主页 首頁
- SDK
- Dev Guide Handbuch Guía Guide Guida 開発ガイド 开发人员指南 開發指南
- Reference Referenz Referencia Référence Riferimento リファレンス 参考 參考資料
- Resources
- Videos ビデオ
- Blog ブログ 博客 網誌

Android.com

In-app Billing >

# Testing In-app Billing

## In this document

1. Testing in-app purchases with static responses
2. Testing in-app purchases using your own product IDs

## Downloads

1. Sample Application

## See also

1. Overview of In-app Billing
2. Implementing In-app Billing
3. Security and Design
4. Administering In-app Billing
5. In-app Billing Reference

The Android Market publisher site provides several tools that help you test your in-app billing implementation before it is published. You can use these tools to create test accounts and purchase special reserved items that send static billing responses to your application.

To test in-app billing in an application you must install the application on an Android-powered device. You cannot use the Android emulator to test in-app billing. The device you use for testing must run a standard version of the Android 1.6 or later platform (API level 4 or higher), and have the most current version of the Android Market application installed. If a device is not running the most current Android Market application, your application won't be able to send in-app billing requests to Android Market. For general information about how to set up a device for use in developing Android applications, see Using Hardware Devices.

The following section shows you how to set up and use the in-app billing test tools.

## Testing in-app purchases with static responses

We recommend that you first test your in-app billing implementation using static responses from Android Market. This enables you to verify that your application is handling the primary Android Market responses correctly and that your application is able to verify signatures correctly.

To test your implementation with static responses, you make an in-app billing request using a special item that has a reserved product ID. Each reserved product ID returns a specific static response from Android Market. No money is transferred when you make in-app billing requests with the reserved product IDs. Also, you cannot specify the form of payment when you make a billing request with a reserved product ID. Figure 1 shows the checkout flow for the reserved item that has the product ID android.test.purchased.

Figure 1. Checkout flow for the special reserved item android.test.purchased.

You do not need to list the reserved products in your application's product list. Android Market already knows about the reserved product IDs. Also, you do not need to upload your application to the publisher site to perform static response tests with the reserved product IDs. You can simply install your application on a device, log into the device, and make billing requests using the reserved product IDs.

There are four reserved product IDs for testing static in-app billing responses:

- android.test.purchased

  When you make an in-app billing request with this product ID, Android Market responds as though you successfully purchased an item. The response includes a JSON string, which contains fake purchase information (for example, a fake order ID). In some cases, the JSON string is signed and the response includes the signature so you can test your signature verification implementation using these responses.

- android.test.canceled

  When you make an in-app billing request with this product ID Android Market responds as though the purchase was canceled. This can occur when an error is encountered in the order process, such as an invalid credit card, or when you cancel a user's order before it is charged.

- android.test.refunded

  When you make an in-app billing request with this product ID, Android Market responds as though the purchase was refunded. Refunds cannot be initiated through Android Market's in-app billing service. Refunds must be initiated by you (the merchant). After you process a refund request through your Google Checkout account, a refund message is sent to your application by Android Market. This occurs only when Android Market gets notification from Google Checkout that a refund has been made. For more information about refunds, see Handling IN_APP_NOTIFY messages and In-app Billing Pricing.

- android.test.item_unavailable

  When you make an in-app billing request with this product ID, Android Market responds as though the item being purchased was not listed in your application's product list.

In some cases, the reserved items may return signed static responses, which lets you test signature verification in your application. To test signature verification with the special reserved product IDs, you may need to set up test accounts or upload your application as a unpublished draft application. Table 1 shows you the conditions under which static responses are signed.

Table 1. Conditions under which static responses are signed.

Application ever been published? | Draft application uploaded and unpublished? | User who is running the application | Static response signature
--- | --- | --- | ---
No | No | Any | Unsigned
No | No | Developer | Signed
Yes | No | Any | Unsigned
Yes | No | Developer | Signed
Yes | No | Test account | Signed
Yes | Yes | Any | Signed

To make an in-app billing request with a reserved product ID, you simply construct a normal `REQUEST_PURCHASE` request, but instead of using a real product ID from your application's product list you use one of the reserved product IDs.

To test your application using the reserved product IDs, follow these steps:

1. Install your application on an Android-powered device.

   You cannot use the emulator to test in-app billing; you must install your application on a device to test in-app billing.

   To learn how to install an application on a device, see Running on a device.

2. Sign in to your device with your developer account.

   You do not need to use a test account if you are testing only with the reserved product IDs.

3. Verify that your device is running a supported version of the Android Market application or the MyApps application.

   If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of the MyApps application. If your device is running any other version of Android, in-app billing requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the version of the Android Market application, see Updating Android Market.

4. Run your application and purchase the reserved product IDs.

Note: Making in-app billing requests with the reserved product IDs overrides the usual Android Market production system. When you send an in-app billing request for a reserved product ID, the quality of service will not be comparable to the production environment.

## Testing In-app Purchases Using Your Own Product IDs

After you finish your static response testing, and you verify that signature verification is working in your application, you can test your in-app billing implementation by making actual in-app purchases. Testing real in-app purchases enables you to test the end-to-end in-app billing experience, including the actual responses from Android Market and the actual checkout flow that users will experience in your application.

Note: You do not need to publish your application to do end-to-end testing. You only need to upload your application as a draft application to perform end-to-end testing.

To test your in-app billing implementation with actual in-app purchases, you will need to register at least one test account on the Android Market publisher site. You cannot use your developer account to test the complete in-app purchase process because Google Checkout does not let you buy items from yourself. If you have not set up test accounts before, see Setting up test accounts.

Also, a test account can purchase an item in your product list only if the item is published. The application does not need to be published, but the item does need to be published.

When you use a test account to purchase items, the test account is billed through Google Checkout and your Google Checkout Merchant account receives a payout for the purchase. Therefore, you may want to refund purchases that are made with test accounts, otherwise the purchases will show up as actual payouts to your merchant account.

To test your in-app billing implementation with actual purchases, follow these steps:

1. Upload your application as a draft application to the publisher site.

   You do not need to publish your application to perform end-to-end testing with real product IDs; you only need to upload your application as a draft application. However, you must sign your application with your release key before you upload it as a draft application. Also, the version number of the uploaded application must match the version number of the application you load to your device for testing. To learn how to upload an application to Android Market, see Uploading applications.

2. Add items to the application's product list.

   Make sure that you publish the items (the application can remain unpublished). See Creating a product list to learn how to do this.

3. Install your application on an Android-powered device.

   You cannot use the emulator to test in-app billing; you must install your application on a device to test in-app billing.

   To learn how to install an application on a device, see Running on a device.

4. Make one of your test accounts the primary account on your device.

   To perform end-to-end testing of in-app billing, the primary account on your device must be one of the test accounts that you registered on the Android Market site. If the primary account on your device is not a test account, you must do a factory reset of the device and then sign in with one of your test accounts. To perform a factory reset, do the following:

   1. Open Settings on your device.
   2. Touch Privacy.
   3. Touch Factory data reset.
   4. Touch Reset phone.
   5. After the phone resets, be sure to sign in with one of your test accounts during the device setup process.
5. Verify that your device is running a supported version of the Android Market application or the MyApps application.

   If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of the MyApps application. If your device is running any other version of Android, in-app billing requires version 2.3.4 (or higher) of the Android Market application. To learn how to check the version of the Android Market application, see Updating Android Market.

6. Make in-app purchases in your application.

Note: The only way to change the primary account on a device is to do a factory reset, making sure you log on with your primary account first.

When you are finished testing your in-app billing implementation, you are ready to publish your application on Android Market. You can follow the normal steps for preparing, signing, and publishing your application.

↑ Go to top

← Back to In-app Billing