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="#billing-testing-static">Testing in-app purchases with static responses</a></li>
     11     <li><a href="#billing-testing-real">Testing in-app purchases using your own product IDs</a></li>
     12 
     13   </ol>
     14   <h2>Downloads</h2>
     15   <ol>
     16     <li><a href="{@docRoot}guide/google/play/billing/billing_integrate.html#billing-download">Sample
     17     Application</a></li>
     18   </ol>
     19   <h2>See also</h2>
     20   <ol>
     21     <li><a href="{@docRoot}guide/google/play/billing/billing_overview.html">Overview of In-app
     22     Billing</a></li>
     23     <li><a href="{@docRoot}guide/google/play/billing/billing_integrate.html">Implementing In-app
     24     Billing</a></li>
     25     <li><a href="{@docRoot}guide/google/play/billing/billing_best_practices.html">Security and
     26     Design</a></li>
     27     <li><a href="{@docRoot}guide/google/play/billing/billing_admin.html">Administering In-app
     28     Billing</a></li>
     29     <li><a href="{@docRoot}guide/google/play/billing/billing_reference.html">In-app Billing
     30     Reference</a></li>
     31   </ol>
     32 </div>
     33 </div>
     34 
     35 <p>The Google Play publisher site provides several tools that help you test your in-app billing
     36 implementation before it is published. You can use these tools to create test accounts and purchase
     37 special reserved items that send static billing responses to your application.</p>
     38 
     39 <p>To test in-app billing in an application you must install the application on an Android-powered
     40 device. You cannot use the Android emulator to test in-app billing.  The device you use for testing
     41 must run a standard version of the Android 1.6 or later platform (API level 4 or higher), and have
     42 the most current version of the Google Play application installed. If a device is not running the
     43 most current Google Play application, your application won't be able to send in-app billing
     44 requests to Google Play. For general information about how to set up a device for use in
     45 developing Android applications, see <a href="{@docRoot}tools/device.html">Using Hardware
     46 Devices</a>.</p>
     47 
     48 <p>The following section shows you how to set up and use the in-app billing test tools.</p>
     49 
     50 <h2 id="billing-testing-static">Testing in-app purchases with static responses</h2>
     51 
     52 <p>We recommend that you first test your in-app billing implementation using static responses from
     53 Google Play. This enables you to verify that your application is handling the primary Google
     54 Play responses correctly and that your application is able to verify signatures correctly.</p>
     55 
     56 <p>To test your implementation with static responses, you make an in-app billing request using a
     57 special item that has a reserved product ID. Each reserved product ID returns a specific static
     58 response from Google Play. No money is transferred when you make in-app billing requests with the
     59 reserved product IDs. Also, you cannot specify the form of payment when you make a billing request
     60 with a reserved product ID. Figure 1 shows the checkout flow for the reserved item that has the
     61 product ID android.test.purchased.</p>
     62 
     63 <img src="{@docRoot}images/billing_test_flow.png" height="381" id="figure1" />
     64 <p class="img-caption">
     65   <strong>Figure 1.</strong> Wallet flow for the special reserved item android.test.purchased.
     66 </p>
     67 
     68 <p>You do not need to list the reserved products in your application's product list. Google Play
     69 already knows about the reserved product IDs. Also, you do not need to upload your application to
     70 the publisher site to perform static response tests with the reserved product IDs. You can simply
     71 install your application on a device, log into the device, and make billing requests using the
     72 reserved product IDs.</p>
     73 
     74 <p>There are four reserved product IDs for testing static in-app billing responses:</p>
     75 
     76 <ul>
     77   <li><strong>android.test.purchased</strong>
     78     <p>When you make an in-app billing request with this product ID, Google Play responds as
     79     though you successfully purchased an item. The response includes a JSON string, which contains
     80     fake purchase information (for example, a fake order ID). In some cases, the JSON string is
     81     signed and the response includes the signature so you can test your signature verification
     82     implementation using these responses.</p>
     83   </li>
     84   <li><strong>android.test.canceled</strong>
     85     <p>When you make an in-app billing request with this product ID Google Play responds as
     86     though the purchase was canceled. This can occur when an error is encountered in the order
     87     process, such as an invalid credit card, or when you cancel a user's order before it is
     88     charged.</p>
     89   </li>
     90   <li><strong>android.test.refunded</strong>
     91     <p>When you make an in-app billing request with this product ID, Google Play responds as
     92     though the purchase was refunded. Refunds cannot be initiated through Google Play's in-app
     93     billing service. Refunds must be initiated by you (the merchant). After you process a refund
     94     request through your Google Wallet account, a refund message is sent to your application by
     95     Google Play. This occurs only when Google Play gets notification from Google Wallet that
     96     a refund has been made. For more information about refunds, see <a
     97     href="{@docRoot}guide/google/play/billing/billing_overview.html#billing-action-notify">Handling
     98     IN_APP_NOTIFY messages</a> and <a
     99     href="http://www.google.com/support/androidmarket/bin/answer.py?answer=1153485">In-app Billing
    100     Pricing</a>.</p>
    101   </li>
    102   <li><strong>android.test.item_unavailable</strong>
    103     <p>When you make an in-app billing request with this product ID, Google Play responds as
    104     though the item being purchased was not listed in your application's product list.</p>
    105   </li>
    106 </ul>
    107 
    108 <p>In some cases, the reserved items may return signed static responses, which lets you test
    109 signature verification in your application. To test signature verification with the special reserved
    110 product IDs, you may need to set up <a
    111 href="{@docRoot}guide/google/play/billing/billing_admin.html#billing-testing-setup">test accounts</a> or
    112 upload your application as a unpublished draft application. Table 1 shows you the conditions under
    113 which static responses are signed.</p>
    114 
    115 <p class="table-caption" id="static-responses-table"><strong>Table 1.</strong>
    116 Conditions under which static responses are signed.</p>
    117 
    118 <table>
    119 <tr>
    120 <th>Application ever been published?</th>
    121 <th>Draft application uploaded and unpublished?</th>
    122 <th>User who is running the application</th>
    123 <th>Static response signature</th>
    124 </tr>
    125 
    126 <tr>
    127 <td>No</td>
    128 <td>No</td>
    129 <td>Any</td>
    130 <td>Unsigned</td>
    131 </tr>
    132 
    133 <tr>
    134 <td>No</td>
    135 <td>No</td>
    136 <td>Developer</td>
    137 <td>Signed</td>
    138 </tr>
    139 
    140 <tr>
    141 <td>Yes</td>
    142 <td>No</td>
    143 <td>Any</td>
    144 <td>Unsigned</td>
    145 </tr>
    146 
    147 <tr>
    148 <td>Yes</td>
    149 <td>No</td>
    150 <td>Developer</td>
    151 <td>Signed</td>
    152 </tr>
    153 
    154 <tr>
    155 <td>Yes</td>
    156 <td>No</td>
    157 <td>Test account</td>
    158 <td>Signed</td>
    159 </tr>
    160 
    161 <tr>
    162 <td>Yes</td>
    163 <td>Yes</td>
    164 <td>Any</td>
    165 <td>Signed</td>
    166 </tr>
    167 
    168 </table>
    169 
    170 <p>To make an in-app billing request with a reserved product ID, you simply construct a normal
    171 <code>REQUEST_PURCHASE</code> request, but instead of using a real product ID from your
    172 application's product list you use one of the reserved product IDs.</p>
    173 
    174 <p>To test your application using the reserved product IDs, follow these steps:</p>
    175 
    176 <ol>
    177   <li><strong>Install your application on an Android-powered device.</strong>
    178     <p>You cannot use the emulator to test in-app billing; you must install your application on a
    179     device to test in-app billing.</p>
    180     <p>To learn how to install an application on a device, see <a
    181     href="{@docRoot}tools/building/building-cmdline.html#RunningOnDevice">Running on a
    182     device</a>.</p>
    183   </li>
    184   <li><strong>Sign in to your device with your developer account.</strong>
    185     <p>You do not need to use a test account if you are testing only with the reserved product
    186     IDs.</p>
    187   </li>
    188   <li><strong>Verify that your device is running a supported version of the Google Play
    189   application or the MyApps application.</strong>
    190     <p>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of
    191     the MyApps application. If your device is running any other version of Android, in-app billing
    192     requires version 2.3.4 (or higher) of the Google Play application. To learn how to check the
    193     version of the Google Play application, see <a
    194     href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Google
    195     Play</a>.</p>
    196   </li>
    197   <li><strong>Run your application and purchase the reserved product IDs.</strong></li>
    198 </ol>
    199 
    200 <p class="note"><strong>Note</strong>: Making in-app billing requests with the reserved product IDs
    201 overrides the usual Google Play production system. When you send an in-app billing request for a
    202 reserved product ID, the quality of service will not be comparable to the production
    203 environment.</p>
    204 
    205 <h2 id="billing-testing-real">Testing In-app Purchases Using Your Own Product IDs</h2>
    206 
    207 <p>After you finish your static response testing, and you verify that signature verification is
    208 working in your application, you can test your in-app billing implementation by making actual in-app
    209 purchases. Testing real in-app purchases enables you to test the end-to-end in-app billing
    210 experience, including the actual responses from Google Play and the actual checkout flow that
    211 users will experience in your application.</p>
    212 
    213 <p class="note"><strong>Note</strong>: You do not need to publish your application to do end-to-end
    214 testing. You only need to upload your application as a draft application to perform end-to-end
    215 testing.</p>
    216 
    217 <p>To test your in-app billing implementation with actual in-app purchases, you will need to
    218 register at least one test account on the Google Play publisher site. You cannot use your
    219 developer account to test the complete in-app purchase process because Google Wallet does not let
    220 you buy items from yourself. If you have not set up test accounts before, see <a
    221 href="{@docRoot}guide/google/play/billing/billing_admin.html#billing-testing-setup">Setting up test
    222 accounts</a>.</p>
    223 
    224 <p>Also, a test account can purchase an item in your product list only if the item is published. The
    225 application does not need to be published, but the item does need to be published.</p>
    226 
    227 <p>When you use a test account to purchase items, the test account is billed through Google Wallet
    228 and your Google Wallet Merchant account receives a payout for the purchase. Therefore, you may
    229 want to refund purchases that are made with test accounts, otherwise the purchases will show up as
    230 actual payouts to your merchant account.</p>
    231 
    232 <p>To test your in-app billing implementation with actual purchases, follow these steps:</p>
    233 
    234 <ol>
    235   <li><strong>Upload your application as a draft application to the publisher site.</strong>
    236     <p>You do not need to publish your application to perform end-to-end testing with real product
    237     IDs; you only need to upload your application as a draft application. However, you must sign
    238     your application with your release key before you upload it as a draft application. Also, the
    239     version number of the uploaded application must match the version number of the application you
    240     load to your device for testing. To learn how to upload an application to Google Play, see
    241     <a href="http://market.android.com/support/bin/answer.py?answer=113469">Uploading
    242     applications</a>.</p>
    243   </li>
    244   <li><strong>Add items to the application's product list.</strong>
    245     <p>Make sure that you publish the items (the application can remain unpublished). See <a
    246     href="{@docRoot}guide/google/play/billing/billing_admin.html#billing-catalog">Creating a product
    247     list</a> to learn how to do this.</p>
    248   </li>
    249   <li><strong>Install your application on an Android-powered device.</strong>
    250     <p>You cannot use the emulator to test in-app billing; you must install your application on a
    251     device to test in-app billing.</p>
    252     <p>To learn how to install an application on a device, see <a
    253     href="{@docRoot}tools/building/building-cmdline.html#RunningOnDevice">Running on a
    254     device</a>.</p>
    255   </li>
    256  <li><strong>Make one of your test accounts the primary account on your device.</strong>
    257     <p>To perform end-to-end testing of in-app billing, the primary account on your device must be
    258     one of the <a
    259     href="{@docRoot}guide/google/play/billing/billing_admin.html#billing-testing-setup">test accounts</a>
    260     that you registered on the Google Play site. If the primary account on your device is not a
    261     test account, you must do a factory reset of the device and then sign in with one of your test
    262     accounts. To perform a factory reset, do the following:</p>
    263     <ol>
    264       <li>Open Settings on your device.</li>
    265       <li>Touch <strong>Privacy</strong>.</li>
    266       <li>Touch <strong>Factory data reset</strong>.</li>
    267       <li>Touch <strong>Reset phone</strong>.</li>
    268       <li>After the phone resets, be sure to sign in with one of your test accounts during the
    269       device setup process.</li>
    270     </ol>
    271   </li>
    272   <li><strong>Verify that your device is running a supported version of the Google Play
    273   application or the MyApps application.</strong>
    274     <p>If your device is running Android 3.0, in-app billing requires version 5.0.12 (or higher) of
    275     the MyApps application. If your device is running any other version of Android, in-app billing
    276     requires version 2.3.4 (or higher) of the Google Play application. To learn how to check the
    277     version of the Google Play application, see <a
    278     href="http://market.android.com/support/bin/answer.py?answer=190860">Updating Google
    279     Play</a>.</p>
    280   </li>
    281   <li><strong>Make in-app purchases in your application.</strong></li>
    282 </ol>
    283 
    284 <p class="note"><strong>Note:</strong> The only way to change the primary account on a device is to
    285 do a factory reset, making sure you log on with your primary account first.</p>
    286 
    287 <p>When you are finished testing your in-app billing implementation, you are ready to
    288 publish your application on Google Play. You can follow the normal steps for <a
    289 href="{@docRoot}tools/publishing/preparing.html">preparing</a>, <a
    290 href="{@docRoot}tools/publishing/app-signing.html">signing</a>, and <a
    291 href="{@docRoot}distribute/googleplay/publish/preparing.html">publishing on Google Play</a>.
    292 </p>
    293 
    294