The Google Play 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 Google Play application installed. If a device is not running the most current Google Play application, your application won't be able to send in-app billing requests to Google Play. 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 Google Play. This enables you to verify that your application is handling the primary Google Play 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 Google Play. 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.
You do not need to list the reserved products in your application's product list. Google Play 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, Google Play 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 Google Play 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, Google Play responds as though the purchase was refunded. Refunds cannot be initiated through Google Play's in-app billing service. Refunds must be initiated by you (the merchant). After you process a refund request through your Google Wallet account, a refund message is sent to your application by Google Play. This occurs only when Google Play gets notification from Google Wallet 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, Google Play 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.
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:
- 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.
- 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.
- Verify that your device is running a supported version of the Google Play
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 Google Play application. To learn how to check the version of the Google Play application, see Updating Google Play.
- Run your application and purchase the reserved product IDs.
Note: Making in-app billing requests with the reserved product IDs overrides the usual Google Play 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 Google Play 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 Google Play publisher site. You cannot use your developer account to test the complete in-app purchase process because Google Wallet 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 Wallet and your Google Wallet 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:
- 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 Google Play, see Uploading applications.
- 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.
- 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.
- 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 Google Play 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:
- Open Settings on your device.
- Touch Privacy.
- Touch Factory data reset.
- Touch Reset phone.
- After the phone resets, be sure to sign in with one of your test accounts during the device setup process.
- Verify that your device is running a supported version of the Google Play
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 Google Play application. To learn how to check the version of the Google Play application, see Updating Google Play.
- 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 Google Play. You can follow the normal steps for preparing, signing, and publishing on Google Play.