blob: 8a49433714301639c2c1cd084408b55200c02106 [file] [log] [blame]
Scott Main50e990c2012-06-21 17:14:39 -07001page.title=Testing In-app Billing
2parent.title=In-app Billing
3parent.link=index.html
4@jd:body
5
6<div id="qv-wrapper">
7<div id="qv">
8 <h2>In this document</h2>
9 <ol>
Dirk Doughertyc80197d2013-05-14 19:14:11 -070010 <li><a href="#testing-purchases">Testing In-app Purchases</a></li>
Andrew Solovayaee20f92014-05-29 15:26:58 -070011 <li><a href="#billing-testing-static">Testing with Static Responses</a></li>
Dirk Doughertyc80197d2013-05-14 19:14:11 -070012 <li><a href="#billing-testing-real">Setting Up for Test Purchases</a></li>
Andrew Solovayaee20f92014-05-29 15:26:58 -070013 <li><a href="#draft_apps">Draft Apps are No Longer Supported</a></li>
Scott Main50e990c2012-06-21 17:14:39 -070014 </ol>
15 <h2>See also</h2>
16 <ol>
Dirk Dougherty2b286bb2012-11-29 17:25:09 -080017 <li><a href="{@docRoot}google/play/billing/billing_overview.html">Overview of In-app
Scott Main50e990c2012-06-21 17:14:39 -070018 Billing</a></li>
Quddus Chong768dba62012-12-08 17:06:30 -080019 <ol>
Scott Main50e990c2012-06-21 17:14:39 -070020</div>
21</div>
22
Dirk Doughertyaca4a772012-09-04 18:09:08 -070023<p>The Google Play Developer Console provides several tools that help you test your In-app Billing
Dirk Doughertyc80197d2013-05-14 19:14:11 -070024implementation:</p>
25
26<ul>
27<li>Test purchases, which let test account users make real purchase your published in-app items,
28but without any actual charges to the user accounts.</li>
29<li>Static billing responses from Google Play, for testing in early development</p>
30</ul>
Scott Main50e990c2012-06-21 17:14:39 -070031
Quddus Chong768dba62012-12-08 17:06:30 -080032<p>To test In-app Billing in an application you must install the application on an Android-powered
33device. You cannot use the Android emulator to test In-app Billing. The device you use for testing
Scott Main50e990c2012-06-21 17:14:39 -070034must run a standard version of the Android 1.6 or later platform (API level 4 or higher), and have
35the most current version of the Google Play application installed. If a device is not running the
Quddus Chong768dba62012-12-08 17:06:30 -080036most current Google Play application, your application won't be able to send In-app Billing
Scott Main50e990c2012-06-21 17:14:39 -070037requests to Google Play. For general information about how to set up a device for use in
38developing Android applications, see <a href="{@docRoot}tools/device.html">Using Hardware
39Devices</a>.</p>
40
Dirk Doughertyc80197d2013-05-14 19:14:11 -070041<h2 id="testing-purchases">Testing In-app Purchases</h2>
Scott Main50e990c2012-06-21 17:14:39 -070042
Dirk Doughertyc80197d2013-05-14 19:14:11 -070043<p>When your In-app Billing implementation is ready, you can test purchasing of your in-app SKUs in two ways:</p>
44
45<ul>
46<li><strong>Test purchases</strong>, which let your selected license test users
47purchase your in-app products before the app is published, but without any
48resulting charges to the user, and </li>
49<li><strong>Real purchases</strong>, which let regular users make real purchases
50of your in-app products with actual charges to the user’s payment instruments.
51In this case, you can use Google Play’s alpha and beta release groups to manage
52the users who can make “live” purchases using your implementation. </li>
53</ul>
54
55<p>The sections below provide more detail about how to use these approaches for
56testing and validation. </p>
57
58<h3 id="test-purchases">Test Purchases (In-app Billing Sandbox)</h3>
59
60<p>Test purchases offer a secure, convenient way to enable larger-scale testing
61of your In-app Billing implementation during development or in preparation for
62launch. They let authorized user accounts make purchases of your in-app products
63through Google Play while the app is still unpublished, without incurring any
64actual charges to the user accounts.</p>
65
66<p>Once authorized with testing access, those users can side-load your app and
67test the full merchandising, purchase, and fulfillment flow for your products.
68Test purchases are real orders and Google Play processes them in the same way as
69other orders. When purchases are complete, Google Play prevents the orders from
70going to financial processing, ensuring that there are no actual charges to user
71accounts, and automatically canceling the completed orders after 14 days. </p>
72
73<h4 id="setup">Setting up test purchases</h4>
74
75<p>It’s easy to set up test purchases&mdash;any user account can be chosen to be
76a test account, and any user of a test account can make test purchases with any
77available payment method (even though there’s no charge to the payment
78method).</p>
79
80<p>First, upload and publish in-app products that you want testers to be able to
81purchase. You can upload and publish in-app products in the Developer Console.
82Note that you can upload and publish your in-app items before you publish the
Andrew Solovayaee20f92014-05-29 15:26:58 -070083APK itself.</p>
Dirk Doughertyc80197d2013-05-14 19:14:11 -070084
quddusc9c1f7192014-01-02 11:39:02 -080085<p>Next, create license test accounts for authorized users. In the Developer
Dirk Doughertyc80197d2013-05-14 19:14:11 -070086Console, go to <strong>Settings</strong> &gt; <strong>Account details</strong>,
87then in the License Testing section, add the addresses to <strong>Gmail accounts
quddusc9c1f7192014-01-02 11:39:02 -080088with testing access</strong> field. For more information, see <a
Dirk Doughertyc80197d2013-05-14 19:14:11 -070089href="#billing-testing-test">Setting Up for Test Purchases</a>.</p>
90
91<p>Once you’ve added the users as license tester accounts and saved the change,
92within 15 minutes those users can begin making test purchases of your in-app
93products. You can then distribute your app to your testers and provide a means
94of getting feedback. </p>
95
96<p class="note"><strong>Note</strong>: To make test purchases, the license test
97account must be on the user’s Android device. If the device has more than one
98account, the purchase will be made with the account that downloaded the app. If
99none of the accounts has downloaded the app, the purchase is made with the first
100account.Users can confirm the account that is making a purchase by expanding the
101purchase dialog.</p>
102
103<h4 id="tp-account">Test purchases and developer account</h4>
104<p>Authorized license test accounts are associated with your developer account
105in Google Play, rather than with a specific APK or package name. Identifying an
106account as a test account enables it to purchase any of your in-app products
107without being charged. </p>
108
109<h4 id="purchase-flow">Details of purchase flow</h4>
110<p>During a test purchase, users can test the actual merchandising, purchase,
111and fulfillment flow in your app. During purchase, the inapp item is displayed
112as a normal item with an actual price. However, Google Play marks test purchases
113with a notice across the center of the purchase dialog, for easy identification.
114</p>
115
116<h4 id="cancelling">Cancelling completed test purchases</h4>
117<p>Google Play accumulates completed test purchases for each user but does not
118pass them on to financial processing. Over time, it automatically clears out
119the purchases by cancelling them. </p>
120
121<p>In some cases, you might want to manually cancel a test purchase to continue
122testing. For cancelling purchases, you have these options:</p>
123
124<ul>
125<li>Wait for the transactions to expire&mdash;Google Play clears completed test
126purchases 14 days after their purchase date. </li>
127<li>Cancel purchases manually&mdash;you can go to the Google Wallet Merchant
128Center, look up the transaction, and then cancel it. You can find transactions
129by looking up their order numbers.</li>
130</ul>
131
132<h4 id="requirements">Requirements for using test purchases</h4>
133<p>If you plan to use test purchases, please note the requirements and limitations below: </p>
134<ul>
135<li>Test purchases is only supported for license test accounts when the app is using the In-app Billing v3 API.</li>
136<li>Test purchases are only supported for in-app products, not for in-app subscriptions.</li>
137</ul>
138
139<h3 id="transations">Testing with real transactions</h3>
140<p>As you prepare to launch an app that uses In-app Billing, you can make use of
141Google Play alpha/beta release options to do validation and load testing on your
142implementation before distributing the app to all of your users. </p>
143
144<p>With alpha/beta test groups, real users (chosen by you) can install your app
145from Google Play and test your in-app products. They can make real purchases
146that result in actual charges to their accounts, using any of their normal
147payment methods in Google Play to make purchases. Note that if you include test
148license accounts in your alpha and beta distribution groups, those users will
149only be able to make test purchases. </p>
150
151
Andrew Solovayaee20f92014-05-29 15:26:58 -0700152<h2 id="billing-testing-static">Testing with Static Responses</h2>
Scott Main50e990c2012-06-21 17:14:39 -0700153
Quddus Chong768dba62012-12-08 17:06:30 -0800154<p>We recommend that you first test your In-app Billing implementation using static responses from
Scott Main50e990c2012-06-21 17:14:39 -0700155Google Play. This enables you to verify that your application is handling the primary Google
Andrew Solovayaee20f92014-05-29 15:26:58 -0700156Play responses correctly and that your application is able to verify signatures correctly. You can do this
157even if the app hasn't been published yet.</p>
Scott Main50e990c2012-06-21 17:14:39 -0700158
Quddus Chong768dba62012-12-08 17:06:30 -0800159<p>To test your implementation with static responses, you make an In-app Billing request using a
Scott Main50e990c2012-06-21 17:14:39 -0700160special item that has a reserved product ID. Each reserved product ID returns a specific static
Quddus Chong768dba62012-12-08 17:06:30 -0800161response from Google Play. No money is transferred when you make In-app Billing requests with the
Scott Main50e990c2012-06-21 17:14:39 -0700162reserved product IDs. Also, you cannot specify the form of payment when you make a billing request
163with a reserved product ID. Figure 1 shows the checkout flow for the reserved item that has the
164product ID android.test.purchased.</p>
165
166<img src="{@docRoot}images/billing_test_flow.png" height="381" id="figure1" />
167<p class="img-caption">
Dirk Doughertyb973b3a2012-12-04 17:55:18 -0800168 <strong>Figure 1.</strong>Wallet flow for the special reserved item android.test.purchased.
Scott Main50e990c2012-06-21 17:14:39 -0700169</p>
170
171<p>You do not need to list the reserved products in your application's product list. Google Play
172already knows about the reserved product IDs. Also, you do not need to upload your application to
Dirk Doughertyaca4a772012-09-04 18:09:08 -0700173the Developer Console to perform static response tests with the reserved product IDs. You can simply
Scott Main50e990c2012-06-21 17:14:39 -0700174install your application on a device, log into the device, and make billing requests using the
175reserved product IDs.</p>
176
Andrew Solovayaee20f92014-05-29 15:26:58 -0700177<p class="note"><strong>Note:</strong> Previously you could test an app by
178uploading an unpublished "draft" version. This functionality is no longer
179supported. However, you can test your app with static responses even before you
180upload it to the Google Play store. For more information, see <a
181href="#draft_apps">Draft Apps are No Longer Supported</a>.
182
Quddus Chong768dba62012-12-08 17:06:30 -0800183<p>There are four reserved product IDs for testing static In-app Billing responses:</p>
Scott Main50e990c2012-06-21 17:14:39 -0700184
185<ul>
186 <li><strong>android.test.purchased</strong>
Quddus Chong768dba62012-12-08 17:06:30 -0800187 <p>When you make an In-app Billing request with this product ID, Google Play responds as
Scott Main50e990c2012-06-21 17:14:39 -0700188 though you successfully purchased an item. The response includes a JSON string, which contains
189 fake purchase information (for example, a fake order ID). In some cases, the JSON string is
190 signed and the response includes the signature so you can test your signature verification
191 implementation using these responses.</p>
192 </li>
193 <li><strong>android.test.canceled</strong>
Quddus Chong768dba62012-12-08 17:06:30 -0800194 <p>When you make an In-app Billing request with this product ID Google Play responds as
Scott Main50e990c2012-06-21 17:14:39 -0700195 though the purchase was canceled. This can occur when an error is encountered in the order
196 process, such as an invalid credit card, or when you cancel a user's order before it is
197 charged.</p>
198 </li>
199 <li><strong>android.test.refunded</strong>
Quddus Chong768dba62012-12-08 17:06:30 -0800200 <p>When you make an In-app Billing request with this product ID, Google Play responds as
Scott Main50e990c2012-06-21 17:14:39 -0700201 though the purchase was refunded. Refunds cannot be initiated through Google Play's in-app
202 billing service. Refunds must be initiated by you (the merchant). After you process a refund
Dirk Dougherty974af932013-04-22 13:03:11 -0700203 request through your Google Wallet merchant account, a refund message is sent to your application by
204 Google Play. This occurs only when Google Play gets notification from Google Wallet that
Quddus Chong768dba62012-12-08 17:06:30 -0800205 a refund has been made. For more information about refunds, see <a href="{@docRoot}google/play/billing/v2/api.html#billing-action-notify">Handling
206IN_APP_NOTIFY messages</a> and <a href="http://support.google.com/googleplay/android-developer/bin/answer.py?hl=en&answer=1153485">In-app Billing
207Pricing</a>.</p>
Scott Main50e990c2012-06-21 17:14:39 -0700208 </li>
209 <li><strong>android.test.item_unavailable</strong>
Quddus Chong768dba62012-12-08 17:06:30 -0800210 <p>When you make an In-app Billing request with this product ID, Google Play responds as
Scott Main50e990c2012-06-21 17:14:39 -0700211 though the item being purchased was not listed in your application's product list.</p>
212 </li>
213</ul>
214
Andrew Solovayaee20f92014-05-29 15:26:58 -0700215<p>In some cases, the reserved items may return signed static responses, which
216lets you test signature verification in your application. The reserved items
217only return signed responses if the user running the application has a <a
218href="{@docRoot}distribute/googleplay/start.html">developer</a> or <a
219href="{@docRoot}google/play/billing/billing_admin.html#billing-testing-setup">test
220account.</a>
Scott Main50e990c2012-06-21 17:14:39 -0700221
Quddus Chong768dba62012-12-08 17:06:30 -0800222<p>To make an In-app Billing request with a reserved product ID, you simply construct a normal
Scott Main50e990c2012-06-21 17:14:39 -0700223<code>REQUEST_PURCHASE</code> request, but instead of using a real product ID from your
224application's product list you use one of the reserved product IDs.</p>
225
226<p>To test your application using the reserved product IDs, follow these steps:</p>
227
228<ol>
229 <li><strong>Install your application on an Android-powered device.</strong>
Quddus Chong768dba62012-12-08 17:06:30 -0800230 <p>You cannot use the emulator to test In-app Billing; you must install your application on a
231 device to test In-app Billing.</p>
Scott Main50e990c2012-06-21 17:14:39 -0700232 <p>To learn how to install an application on a device, see <a
233 href="{@docRoot}tools/building/building-cmdline.html#RunningOnDevice">Running on a
234 device</a>.</p>
235 </li>
236 <li><strong>Sign in to your device with your developer account.</strong>
237 <p>You do not need to use a test account if you are testing only with the reserved product
238 IDs.</p>
239 </li>
240 <li><strong>Verify that your device is running a supported version of the Google Play
241 application or the MyApps application.</strong>
Quddus Chong768dba62012-12-08 17:06:30 -0800242 <p>If your device is running Android 3.0, In-app Billing requires version 5.0.12 (or higher) of
243 the MyApps application. If your device is running any other version of Android, In-app Billing
Scott Main50e990c2012-06-21 17:14:39 -0700244 requires version 2.3.4 (or higher) of the Google Play application. To learn how to check the
245 version of the Google Play application, see <a
246 href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Google
247 Play</a>.</p>
248 </li>
249 <li><strong>Run your application and purchase the reserved product IDs.</strong></li>
250</ol>
251
Quddus Chong768dba62012-12-08 17:06:30 -0800252<p class="note"><strong>Note</strong>: Making In-app Billing requests with the reserved product IDs
253overrides the usual Google Play production system. When you send an In-app Billing request for a
Scott Main50e990c2012-06-21 17:14:39 -0700254reserved product ID, the quality of service will not be comparable to the production
255environment.</p>
256
Dirk Doughertyc80197d2013-05-14 19:14:11 -0700257<h2 id="billing-testing-test">Setting Up for Test Purchases</h2>
Scott Main50e990c2012-06-21 17:14:39 -0700258
259<p>After you finish your static response testing, and you verify that signature verification is
Quddus Chong768dba62012-12-08 17:06:30 -0800260working in your application, you can test your In-app Billing implementation by making actual in-app
261purchases. Testing real in-app purchases enables you to test the end-to-end In-app Billing
Dirk Doughertyc80197d2013-05-14 19:14:11 -0700262experience, including the actual purchases from Google Play and the actual checkout flow that
Scott Main50e990c2012-06-21 17:14:39 -0700263users will experience in your application.</p>
264
Andrew Solovayaee20f92014-05-29 15:26:58 -0700265<p class="note"><strong>Note:</strong> You can do end-to-end testing of your app
266 by publishing it to an <a
267 href="{@docRoot}distribute/googleplay/developer-console.html#alpha-beta">alpha
268 distribution channel</a>. This allows you to publish the app to the Google
269 Play store, but limit its availability to just the testers you designate. </p>
Scott Main50e990c2012-06-21 17:14:39 -0700270
Quddus Chong768dba62012-12-08 17:06:30 -0800271<p>To test your In-app Billing implementation with actual in-app purchases, you will need to
Dirk Doughertyaca4a772012-09-04 18:09:08 -0700272register at least one test account on the Google Play Developer Console. You cannot use your
Dirk Dougherty974af932013-04-22 13:03:11 -0700273developer account to test the complete in-app purchase process because Google Wallet does not let
Scott Main50e990c2012-06-21 17:14:39 -0700274you buy items from yourself. If you have not set up test accounts before, see <a
Dirk Dougherty2b286bb2012-11-29 17:25:09 -0800275href="{@docRoot}google/play/billing/billing_admin.html#billing-testing-setup">Setting up test
Scott Main50e990c2012-06-21 17:14:39 -0700276accounts</a>.</p>
277
278<p>Also, a test account can purchase an item in your product list only if the item is published. The
279application does not need to be published, but the item does need to be published.</p>
280
Quddus Chong768dba62012-12-08 17:06:30 -0800281<p>To test your In-app Billing implementation with actual purchases, follow these steps:</p>
Scott Main50e990c2012-06-21 17:14:39 -0700282
283<ol>
Andrew Solovayaee20f92014-05-29 15:26:58 -0700284 <li><strong>Upload your application to the <a
285 href="{@docRoot}distribute/googleplay/developer-console.html#alpha-beta">alpha
286 distribution channel</a> with the Developer Console.</strong>
287
288 <p class="note"><strong>Note:</strong> Previously you could test an app by
289 uploading an unpublished "draft" version. This functionality is no longer
290 supported; instead, you must publish it to the alpha or beta distribution
291 channel. For more information, see <a href="#draft_apps">Draft Apps are No
292 Longer Supported</a>.
293
Scott Main50e990c2012-06-21 17:14:39 -0700294 </li>
295 <li><strong>Add items to the application's product list.</strong>
296 <p>Make sure that you publish the items (the application can remain unpublished). See <a
Dirk Dougherty2b286bb2012-11-29 17:25:09 -0800297 href="{@docRoot}google/play/billing/billing_admin.html#billing-catalog">Creating a product
Scott Main50e990c2012-06-21 17:14:39 -0700298 list</a> to learn how to do this.</p>
299 </li>
300 <li><strong>Install your application on an Android-powered device.</strong>
Quddus Chong768dba62012-12-08 17:06:30 -0800301 <p>You cannot use the emulator to test In-app Billing; you must install your application on a
302 device to test In-app Billing.</p>
Scott Main50e990c2012-06-21 17:14:39 -0700303 <p>To learn how to install an application on a device, see <a
304 href="{@docRoot}tools/building/building-cmdline.html#RunningOnDevice">Running on a
305 device</a>.</p>
306 </li>
Scott Main50e990c2012-06-21 17:14:39 -0700307 <li><strong>Verify that your device is running a supported version of the Google Play
308 application or the MyApps application.</strong>
Quddus Chong768dba62012-12-08 17:06:30 -0800309 <p>If your device is running Android 3.0, In-app Billing requires version 5.0.12 (or higher) of
310 the MyApps application. If your device is running any other version of Android, In-app Billing
Scott Main50e990c2012-06-21 17:14:39 -0700311 requires version 2.3.4 (or higher) of the Google Play application. To learn how to check the
312 version of the Google Play application, see <a
313 href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Google
314 Play</a>.</p>
315 </li>
316 <li><strong>Make in-app purchases in your application.</strong></li>
317</ol>
318
319<p class="note"><strong>Note:</strong> The only way to change the primary account on a device is to
320do a factory reset, making sure you log on with your primary account first.</p>
321
Quddus Chong768dba62012-12-08 17:06:30 -0800322<p>When you are finished testing your In-app Billing implementation, you are ready to
Scott Main50e990c2012-06-21 17:14:39 -0700323publish your application on Google Play. You can follow the normal steps for <a
324href="{@docRoot}tools/publishing/preparing.html">preparing</a>, <a
325href="{@docRoot}tools/publishing/app-signing.html">signing</a>, and <a
Dirk Dougherty3506ac82014-02-21 11:15:52 -0800326href="{@docRoot}distribute/tools/launch-checklist.html">publishing on Google Play</a>.
Scott Main50e990c2012-06-21 17:14:39 -0700327</p>
328
Andrew Solovayaee20f92014-05-29 15:26:58 -0700329<h2 id="draft_apps">Draft Apps are No Longer Supported</h2>
330
331<p>Previously, you could publish a "draft" version of your app for testing. This
332functionality is no longer supported. Instead, there are two ways you can test
333how a pre-release app functions on the Google Play store:</p>
334
335<ul>
336
337 <li>You can publish an app to the <a
338 href="{@docRoot}distribute/googleplay/developer-console.html#alpha-beta">alpha
339 or beta distribution channels</a>. This makes the app available on the Google
340 Play store, but only to the testers you put on a "whitelist".</li>
341
342 <li>In a few cases, you can test Google Play functionality with an unpublished
343 app. For example, you can test an unpublished app's in-app billing support by
344 using <a
345 href="{@docRoot}google/play/billing/billing_testing.html#billing-testing-static">static
346 responses</a>, special reserved product IDs that always return a specific
347 result (like "purchased" or "refunded").</li>
348
349</ul>