gp-purchase-status-api.jd revision 33baa5ad7d8cdcc89ce4fbc3bc8cd537d5f5d639
1page.title=Purchase Status API 2page.tags=In-app Billing,Google Play,inapp billing,in app billing,iab,billing 3 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="#overview">Overview</a></li> 11 <li><a href="#using">Using the API</a></li> 12 <li><a href="#strategies">Verification Strategies</a></li> 13 <li><a href="#practices">Using the API Efficiently</a></li> 14 </ol> 15 <h2>See also</h2> 16 <ol> 17 <li><a href="https://developers.google.com/android-publisher/v1_1/">Google Play Android Developer API</a></li> 18 </ol> 19</div> 20</div> 21 22<p>Google Play provides an HTTP-based Purchase Status API that lets 23you remotely query the status of a specific in-app product or subscription, 24or cancel an active subscription. The API is designed to be used from your 25backend servers as a way of securely managing in-app products and 26subscriptions, as well as extending and integrating them with other services.</p> 27 28<h2 id="overview">Overview</h2> 29 30<p>With the Purchase Status API you can quickly retrieve the details of any 31purchase using a standard GET request. In the request you supply information 32about the purchase — app package name, purchase or subscription ID, 33and the purchase token. The server responds with a JSON object describing 34the associated purchase details, order status, developer payload, and other 35information.</p> 36 37<p>You can use the Purchase Status API in several ways, such as for reporting 38and reconciliation of individual orders and for verifying purchases and 39subscription expirations. You can also use the API to learn about cancelled 40orders and confirm whether in-app products have been consumed, including 41whether they were consumed before being cancelled.</p> 42 43<p>For subscriptions, in addition to querying for order status and expiration, 44you can use the Purchase Status API to remotely cancel a subscription. This is a 45convenient way to manage cancellations on behalf of customers, without 46requiring them to manage the cancellation themselves on their Android devices.</p> 47 48<p>If you plan to use the Purchase Status API, keep in mind that:</p> 49<ul><li>You can use the API to check the status of individual items only 50— bulk requests for order status are not supported at this time.</li> 51<li>You can query for the details of orders placed on or after 12 June 2013, 52but not for orders placed earlier.</li> 53<li>You can query purchases of any item type made with the In-app 54Billing v3 API, or purchases of managed items made with In-app Billing v1 and 55v2. You can not use the Purchase Status API to query purchases of unmanaged items 56made with In-app Billing v1 or v2.</li> 57</ul> 58 59<p>The Purchase Status API is part of the <a 60href="https://developers.google.com/android-publisher/v1_1/">Google Play Android 61Developer API v1.1</a>, available through the Google APIs console. The new version 62of the API supersedes the v1 API, which is deprecated. If you are using the v1 63API, please migrate your operations to the v1.1 API as soon as possible.</p> 64 65 66<h2 id="using">Using the API</h2> 67 68<p>To use the API, you must first register a project at the <a 69href="https://code.google.com/apis/console">Google APIs Console</a> and receive 70a Client ID and shared secret that your app will present when calling the 71API. All calls are authenticated with OAuth 2.0.</p> 72 73<p>Once your app is registered, you can access the API directly, using standard 74HTTP methods to retrieve and manipulate resources. The API is built on a RESTful 75design that uses HTTP and JSON. so any standard web stack can send requests and 76parse the responses. However, if you don’t want to send HTTP requests and parse 77responses manually, you can access the API using the Google APIs Client 78Libraries, which provide better language integration, improved security, 79and support for making calls that require user authorization.</p> 80 81<p>For more information about the API and how to access it through the Google 82APIs Client Libraries, see the documentation at:</p> 83 84<p style="margin-left:1.5em;"><a 85href="https://developers.google.com/android-publisher/v1_1/">https://developers. 86google.com/android-publisher/v1_1/</a></p> 87 88<h3 id="quota">Quota</h3> 89 90<p>Applications using the Google Play Android Developer API are limited to an 91initial courtesy usage quota of <strong>200,000 requests per day</strong> (per 92application). This should provide enough access for normal 93subscription-validation needs, assuming that you follow the recommendation in 94this section.</p> 95 96<p>If you need to request a higher limit for your application, please use the 97“Request more” link in the <a 98href="https://code.google.com/apis/console/#:quotas">Google APIs Console</a>. 99Also, please read the section below on design best practices for minimizing your 100use of the API.</p> 101 102<h3 id="auth">Authorization</h3> 103 104<p>Calls to the Google Play Android Developer API require authorization. Google 105uses the OAuth 2.0 protocol to allow authorized applications to access user 106data. To learn more, see <a 107href="https://developers.google.com/android-publisher/authorization">Authorization</a> 108in the Google Play Android Developer API documentation.</p> 109 110<h2 id="strategies">Purchase Verification Strategies</h2> 111 112<p>In a typical scenario, your app verifies the order status for new purchases 113to ensure that they are valid before granting access to the purchased content.</p> 114 115<p>To verify a purchase, the app passes the purchase token and other details up 116to your backend servers, which verifies them directly with Google Play using the 117Purchase Status API. For security reasons, the app should not normally attempt to verify 118the purchase itself using the Purchase Status API.</p> 119 120<p>If the backend server determines that the purchase is valid, it notifies the 121app and grants access to the content. For improved performance, the backend servers 122should store the purchase details and order status in a local database, updated at 123intervals or as-needed.</p> 124 125<p>Keep in mind that users will want the ability to use your app at any time, including 126when there may be no network connection available. Make sure that your approach to 127purchase verification accounts for the offline use-case.</p> 128 129<h2 id="practices">Using the API Efficiently</h2> 130 131<p>Access to the Google Play Android Developer API is regulated to help ensure a 132high-performance environment for all applications that use it. While you can 133request a higher daily quota for your application, we highly recommend that you 134minimize your access using the techniques below. </p> 135 136<ul> 137 <li><em>Query the Purchase Status API for new purchases only</em> — At 138 purchase, your app can pass the purchase token and other details to your backend 139 servers, which can use the Purchase Status API to verify the purchase.</li> 140 <li><em>Cache purchase details on your servers</em> — To the extent possible, 141 cache the purchase details for in-app products and subscriptions on your backend 142 servers. If your app contacts your backend servers at runtime to verify purchase 143 validity, your server can verify the purchase based on the cached details, to 144 minimize use of the Purchase Status API and to provide the fastest possible response 145 (and best experience) for the user.</li> 146 <li><em>Store subscription expiry on your servers</em> — Your servers should 147 use the Purchase Status API to query the expiration date for new subscription tokens, 148 then store the expiration date locally. This allows you to check the status of 149 subscriptions only at or after the expiration (see below).</li> 150 <li><em>Query for subscription status only at expiration</em> — Once your 151 server has retrieved the expiration date of subscription tokens, it should not query 152 the Google Play servers for the subscription status again until the subscription is 153 reaching or has passed the expiration date. Typically, your servers would run a batch 154 query each day to check the status of expiring subscriptions, then update the database. 155 Note that: 156 <ul> 157 <li>Your servers should not query all subscriptions every day.</li> 158 <li>Your servers should never query subscription status dynamically, based on 159 individual requests from your Android application.</li> 160 </ul> 161 </li> 162</ul> 163 164<p>By following those general guidelines, your implementation will offer the 165best possible performance for users and minimize use of the <a 166href="https://developers.google.com/android-publisher/v1_1/">Google Play Android 167Developer API</a>.</p> 168