Home | History | Annotate | Download | only in billing
      1 page.title=Testing In-app Billing
      2 parent.title=In-app Billing
      3 parent.link=index.html
      4 @jd:body
      5 
      6 <div id="qv-wrapper">
      7 <div id="qv">
      8   <h2>In this document</h2>
      9   <ol>
     10     <li><a href="#testing-purchases">Testing In-app Purchases</a></li>
     11         <li><a href="#billing-testing-static">Testing with static responses</a></li>
     12     <li><a href="#billing-testing-real">Setting Up for Test Purchases</a></li>
     13   </ol>
     14   <h2>See also</h2>
     15   <ol>
     16     <li><a href="{@docRoot}google/play/billing/billing_overview.html">Overview of In-app
     17     Billing</a></li>
     18   <ol>
     19 </div>
     20 </div>
     21 
     22 <p>The Google Play Developer Console provides several tools that help you test your In-app Billing
     23 implementation:</p>
     24 
     25 <ul>
     26 <li>Test purchases, which let test account users make real purchase your published in-app items,
     27 but without any actual charges to the user accounts.</li>
     28 <li>Static billing responses from Google Play, for testing in early development</p>
     29 </ul>
     30 
     31 <p>To test In-app Billing in an application you must install the application on an Android-powered
     32 device. You cannot use the Android emulator to test In-app Billing.  The device you use for testing
     33 must run a standard version of the Android 1.6 or later platform (API level 4 or higher), and have
     34 the most current version of the Google Play application installed. If a device is not running the
     35 most current Google Play application, your application won't be able to send In-app Billing
     36 requests to Google Play. For general information about how to set up a device for use in
     37 developing Android applications, see <a href="{@docRoot}tools/device.html">Using Hardware
     38 Devices</a>.</p>
     39 
     40 <h2 id="testing-purchases">Testing In-app Purchases</h2>
     41 
     42 <p>When your In-app Billing implementation is ready, you can test purchasing of your in-app SKUs in two ways:</p>
     43 
     44 <ul>
     45 <li><strong>Test purchases</strong>, which let your selected license test users
     46 purchase your in-app products before the app is published, but without any
     47 resulting charges to the user, and </li>
     48 <li><strong>Real purchases</strong>, which let regular users make real purchases
     49 of your in-app products with actual charges to the users payment instruments.
     50 In this case, you can use Google Plays alpha and beta release groups to manage
     51 the users who can make live purchases using your implementation.  </li>
     52 </ul>
     53 
     54 <p>The sections below provide more detail about how to use these approaches for
     55 testing and validation. </p>
     56 
     57 <h3 id="test-purchases">Test Purchases (In-app Billing Sandbox)</h3>
     58 
     59 <p>Test purchases offer a secure, convenient way to enable larger-scale testing
     60 of your In-app Billing implementation during development or in preparation for
     61 launch. They let authorized user accounts make purchases of your in-app products
     62 through Google Play while the app is still unpublished, without incurring any
     63 actual charges to the user accounts.</p>
     64 
     65 <p>Once authorized with testing access, those users can side-load your app and
     66 test the full merchandising, purchase, and fulfillment flow for your products.
     67 Test purchases are real orders and Google Play processes them in the same way as
     68 other orders. When purchases are complete, Google Play prevents the orders from
     69 going to financial processing, ensuring that there are no actual charges to user
     70 accounts, and automatically canceling the completed orders after 14 days. </p>
     71 
     72 <h4 id="setup">Setting up test purchases</h4>
     73 
     74 <p>Its easy to set up test purchases&mdash;any user account can be chosen to be
     75 a test account, and any user of a test account can make test purchases with any
     76 available payment method (even though theres no charge to the payment
     77 method).</p>
     78 
     79 <p>First, upload and publish in-app products that you want testers to be able to
     80 purchase. You can upload and publish in-app products in the Developer Console. 
     81 Note that you can upload and publish your in-app items before you publish the
     82 APK itself. For example, you can publish your in-app items while your APK is
     83 still a draft. </p>
     84 
     85 <p>Next, create license test accounts for authorized users.  In the Developer
     86 Console, go to <strong>Settings</strong> &gt; <strong>Account details</strong>,
     87 then in the License Testing section, add the addresses to <strong>Gmail accounts
     88 with testing status</strong>. For more information, see <a
     89 href="#billing-testing-test">Setting Up for Test Purchases</a>.</p>
     90 
     91 <p>Once youve added the users as license tester accounts and saved the change,
     92 within 15 minutes those users can begin making test purchases of your in-app
     93 products. You can then distribute your app to your testers and provide a means
     94 of getting feedback. </p>
     95 
     96 <p class="note"><strong>Note</strong>: To make test purchases, the license test
     97 account must be on the users Android device. If the device has more than one
     98 account, the purchase will be made with the account that downloaded the app. If
     99 none of the accounts has downloaded the app, the purchase is made with the first
    100 account.Users can confirm the account that is making a purchase by expanding the
    101 purchase 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
    105 in Google Play, rather than with a specific APK or package name. Identifying an
    106 account as a test account enables it to purchase any of your in-app products
    107 without 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,
    111 and fulfillment flow in your app.  During purchase, the inapp item is displayed
    112 as a normal item with an actual price. However, Google Play marks test purchases
    113 with 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
    118 pass them on  to financial processing. Over time, it automatically clears out
    119 the purchases by cancelling them. </p>
    120 
    121 <p>In some cases, you might want to manually cancel a test purchase to continue
    122 testing. 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
    126 purchases 14 days after their purchase date. </li>
    127 <li>Cancel purchases manually&mdash;you can go to the Google Wallet Merchant
    128 Center, look up the transaction, and then cancel it. You can find transactions
    129 by 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
    141 Google Play alpha/beta release options to do validation and load testing on your
    142 implementation 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
    145 from Google Play and test your in-app products. They can make real purchases
    146 that result in actual charges to their accounts, using any of their normal
    147 payment methods in Google Play to make purchases. Note that if you include test
    148 license accounts in your alpha and beta distribution groups, those users will
    149 only be able to make test purchases. </p>
    150 
    151 
    152 <h2 id="billing-testing-static">Testing with static responses</h2>
    153 
    154 <p>We recommend that you first test your In-app Billing implementation using static responses from
    155 Google Play. This enables you to verify that your application is handling the primary Google
    156 Play responses correctly and that your application is able to verify signatures correctly.</p>
    157 
    158 <p>To test your implementation with static responses, you make an In-app Billing request using a
    159 special item that has a reserved product ID. Each reserved product ID returns a specific static
    160 response from Google Play. No money is transferred when you make In-app Billing requests with the
    161 reserved product IDs. Also, you cannot specify the form of payment when you make a billing request
    162 with a reserved product ID. Figure 1 shows the checkout flow for the reserved item that has the
    163 product ID android.test.purchased.</p>
    164 
    165 <img src="{@docRoot}images/billing_test_flow.png" height="381" id="figure1" />
    166 <p class="img-caption">
    167   <strong>Figure 1.</strong>Wallet flow for the special reserved item android.test.purchased.
    168 </p>
    169 
    170 <p>You do not need to list the reserved products in your application's product list. Google Play
    171 already knows about the reserved product IDs. Also, you do not need to upload your application to
    172 the Developer Console to perform static response tests with the reserved product IDs. You can simply
    173 install your application on a device, log into the device, and make billing requests using the
    174 reserved product IDs.</p>
    175 
    176 <p>There are four reserved product IDs for testing static In-app Billing responses:</p>
    177 
    178 <ul>
    179   <li><strong>android.test.purchased</strong>
    180     <p>When you make an In-app Billing request with this product ID, Google Play responds as
    181     though you successfully purchased an item. The response includes a JSON string, which contains
    182     fake purchase information (for example, a fake order ID). In some cases, the JSON string is
    183     signed and the response includes the signature so you can test your signature verification
    184     implementation using these responses.</p>
    185   </li>
    186   <li><strong>android.test.canceled</strong>
    187     <p>When you make an In-app Billing request with this product ID Google Play responds as
    188     though the purchase was canceled. This can occur when an error is encountered in the order
    189     process, such as an invalid credit card, or when you cancel a user's order before it is
    190     charged.</p>
    191   </li>
    192   <li><strong>android.test.refunded</strong>
    193     <p>When you make an In-app Billing request with this product ID, Google Play responds as
    194     though the purchase was refunded. Refunds cannot be initiated through Google Play's in-app
    195     billing service. Refunds must be initiated by you (the merchant). After you process a refund
    196     request through your Google Wallet merchant account, a refund message is sent to your application by
    197     Google Play. This occurs only when Google Play gets notification from Google Wallet that
    198     a refund has been made. For more information about refunds, see <a href="{@docRoot}google/play/billing/v2/api.html#billing-action-notify">Handling
    199 IN_APP_NOTIFY messages</a> and <a href="http://support.google.com/googleplay/android-developer/bin/answer.py?hl=en&answer=1153485">In-app Billing
    200 Pricing</a>.</p>
    201   </li>
    202   <li><strong>android.test.item_unavailable</strong>
    203     <p>When you make an In-app Billing request with this product ID, Google Play responds as
    204     though the item being purchased was not listed in your application's product list.</p>
    205   </li>
    206 </ul>
    207 
    208 <p>In some cases, the reserved items may return signed static responses, which lets you test
    209 signature verification in your application. To test signature verification with the special reserved
    210 product IDs, you may need to set up <a
    211 href="{@docRoot}google/play/billing/billing_admin.html#billing-testing-setup">test accounts</a> or
    212 upload your application as a unpublished draft application. Table 1 shows you the conditions under
    213 which static responses are signed.</p>
    214 
    215 <p class="table-caption" id="static-responses-table"><strong>Table 1.</strong>
    216 Conditions under which static responses are signed.</p>
    217 
    218 <table>
    219 <tr>
    220 <th>Application ever been published?</th>
    221 <th>Draft application uploaded and unpublished?</th>
    222 <th>User who is running the application</th>
    223 <th>Static response signature</th>
    224 </tr>
    225 
    226 <tr>
    227 <td>No</td>
    228 <td>No</td>
    229 <td>Any</td>
    230 <td>Unsigned</td>
    231 </tr>
    232 
    233 <tr>
    234 <td>No</td>
    235 <td>No</td>
    236 <td>Developer</td>
    237 <td>Signed</td>
    238 </tr>
    239 
    240 <tr>
    241 <td>Yes</td>
    242 <td>No</td>
    243 <td>Any</td>
    244 <td>Unsigned</td>
    245 </tr>
    246 
    247 <tr>
    248 <td>Yes</td>
    249 <td>No</td>
    250 <td>Developer</td>
    251 <td>Signed</td>
    252 </tr>
    253 
    254 <tr>
    255 <td>Yes</td>
    256 <td>No</td>
    257 <td>Test account</td>
    258 <td>Signed</td>
    259 </tr>
    260 
    261 <tr>
    262 <td>Yes</td>
    263 <td>Yes</td>
    264 <td>Any</td>
    265 <td>Signed</td>
    266 </tr>
    267 
    268 </table>
    269 
    270 <p>To make an In-app Billing request with a reserved product ID, you simply construct a normal
    271 <code>REQUEST_PURCHASE</code> request, but instead of using a real product ID from your
    272 application's product list you use one of the reserved product IDs.</p>
    273 
    274 <p>To test your application using the reserved product IDs, follow these steps:</p>
    275 
    276 <ol>
    277   <li><strong>Install your application on an Android-powered device.</strong>
    278     <p>You cannot use the emulator to test In-app Billing; you must install your application on a
    279     device to test In-app Billing.</p>
    280     <p>To learn how to install an application on a device, see <a
    281     href="{@docRoot}tools/building/building-cmdline.html#RunningOnDevice">Running on a
    282     device</a>.</p>
    283   </li>
    284   <li><strong>Sign in to your device with your developer account.</strong>
    285     <p>You do not need to use a test account if you are testing only with the reserved product
    286     IDs.</p>
    287   </li>
    288   <li><strong>Verify that your device is running a supported version of the Google Play
    289   application or the MyApps application.</strong>
    290     <p>If your device is running Android 3.0, In-app Billing requires version 5.0.12 (or higher) of
    291     the MyApps application. If your device is running any other version of Android, In-app Billing
    292     requires version 2.3.4 (or higher) of the Google Play application. To learn how to check the
    293     version of the Google Play application, see <a
    294     href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Google
    295     Play</a>.</p>
    296   </li>
    297   <li><strong>Run your application and purchase the reserved product IDs.</strong></li>
    298 </ol>
    299 
    300 <p class="note"><strong>Note</strong>: Making In-app Billing requests with the reserved product IDs
    301 overrides the usual Google Play production system. When you send an In-app Billing request for a
    302 reserved product ID, the quality of service will not be comparable to the production
    303 environment.</p>
    304 
    305 <h2 id="billing-testing-test">Setting Up for Test Purchases</h2>
    306 
    307 <p>After you finish your static response testing, and you verify that signature verification is
    308 working in your application, you can test your In-app Billing implementation by making actual in-app
    309 purchases. Testing real in-app purchases enables you to test the end-to-end In-app Billing
    310 experience, including the actual purchases from Google Play and the actual checkout flow that
    311 users will experience in your application.</p>
    312 
    313 <p class="note"><strong>Note</strong>: You do not need to publish your application to do end-to-end
    314 testing. You only need to upload your application as a draft application to perform end-to-end
    315 testing.</p>
    316 
    317 <p>To test your In-app Billing implementation with actual in-app purchases, you will need to
    318 register at least one test account on the Google Play Developer Console. You cannot use your
    319 developer account to test the complete in-app purchase process because Google Wallet does not let
    320 you buy items from yourself. If you have not set up test accounts before, see <a
    321 href="{@docRoot}google/play/billing/billing_admin.html#billing-testing-setup">Setting up test
    322 accounts</a>.</p>
    323 
    324 <p>Also, a test account can purchase an item in your product list only if the item is published. The
    325 application does not need to be published, but the item does need to be published.</p>
    326 
    327 <p>To test your In-app Billing implementation with actual purchases, follow these steps:</p>
    328 
    329 <ol>
    330   <li><strong>Upload your application as a draft application to the Developer Console.</strong>
    331     <p>You do not need to publish your application to perform end-to-end testing with real product
    332     IDs; you only need to upload your application as a draft application. However, you must sign
    333     your application with your release key before you upload it as a draft application. Also, the
    334     version number of the uploaded application must match the version number of the application you
    335     load to your device for testing. To learn how to upload an application to Google Play, see
    336     <a href="http://support.google.com/googleplay/android-developer/bin/answer.py?hl=en&answer=113469">Uploading
    337     applications</a>.</p>
    338   </li>
    339   <li><strong>Add items to the application's product list.</strong>
    340     <p>Make sure that you publish the items (the application can remain unpublished). See <a
    341     href="{@docRoot}google/play/billing/billing_admin.html#billing-catalog">Creating a product
    342     list</a> to learn how to do this.</p>
    343   </li>
    344   <li><strong>Install your application on an Android-powered device.</strong>
    345     <p>You cannot use the emulator to test In-app Billing; you must install your application on a
    346     device to test In-app Billing.</p>
    347     <p>To learn how to install an application on a device, see <a
    348     href="{@docRoot}tools/building/building-cmdline.html#RunningOnDevice">Running on a
    349     device</a>.</p>
    350   </li>
    351   <li><strong>Verify that your device is running a supported version of the Google Play
    352   application or the MyApps application.</strong>
    353     <p>If your device is running Android 3.0, In-app Billing requires version 5.0.12 (or higher) of
    354     the MyApps application. If your device is running any other version of Android, In-app Billing
    355     requires version 2.3.4 (or higher) of the Google Play application. To learn how to check the
    356     version of the Google Play application, see <a
    357     href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Google
    358     Play</a>.</p>
    359   </li>
    360   <li><strong>Make in-app purchases in your application.</strong></li>
    361 </ol>
    362 
    363 <p class="note"><strong>Note:</strong> The only way to change the primary account on a device is to
    364 do a factory reset, making sure you log on with your primary account first.</p>
    365 
    366 <p>When you are finished testing your In-app Billing implementation, you are ready to
    367 publish your application on Google Play. You can follow the normal steps for <a
    368 href="{@docRoot}tools/publishing/preparing.html">preparing</a>, <a
    369 href="{@docRoot}tools/publishing/app-signing.html">signing</a>, and <a
    370 href="{@docRoot}distribute/googleplay/publish/preparing.html">publishing on Google Play</a>.
    371 </p>
    372 
    373