billing_reference.jd revision 768dba6d8cd6ad56fb6d4e7e30b3260e0d5e0ffd
1page.title=In-app Billing Reference <span style="font-size:16px;">(IAB Version 3)</span>
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>
10    <li><a href="#billing-codes">Server Response Codes</a></li>
11    <li><a href="#billing-interface">API Reference</a>
12    <ol>
13      <li><a href="#getSkuDetails">getSkuDetails()</a></li>
14      <li><a href="#getBuyIntent">getBuyIntent()</a></li>
15      <li><a href="#getPurchases">getPurchases()</a></li>
16    </ol>
17    </li>
18  </ol>
19  <h2>Downloads</h2>
20  <ol>
21    <li><a href="{@docRoot}google/play/billing/billing_integrate.html#billing-download">Sample
22    Application (V3)</a></li>
23  </ol>
24  <h2>See also</h2>
25  <ol>
26    <li><a href="{@docRoot}google/play/billing/api.html">In-app Billing Version 3</a></li>
27    <li><a href="{@docRoot}training/in-app-billing/index.html">Selling In-app Products</a></li>
28  </ol>
29</div>
30</div>
31<p>This documentation provides technical reference information for using the In-app Billing Version 3 API. </p>
32
33<h2 id="billing-codes">Server Response Codes</h2>
34<p>The following table lists all of the server response codes that are sent from Google Play to your application. Google Play sends the response code synchronously as an integer mapped to the {@code RESPONSE_CODE} key in the response {@code Bundle}. Your application must handle all of these response codes.</p>
35
36<p class="table-caption" id="response-codes-table">
37<strong>Table 1.</strong> Summary of response codes for In-app Billing Version 3 API calls.</p>
38<table>
39  <tr>
40    <th scope="col">Response Code</th>
41    <th scope="col">Value</th>
42    <th scope="col">Description</th>
43  </tr>
44  <tr>
45    <td>{@code BILLING_RESPONSE_RESULT_OK}</td>
46    <td>0</td>
47    <td>Success</td>
48  </tr>
49  <tr>
50    <td>{@code BILLING_RESPONSE_RESULT_USER_CANCELED}</td>
51    <td>1</td>
52    <td>User pressed back or canceled a dialog</td>
53  </tr>
54  <tr>
55    <td>{@code BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE}</td>
56    <td>3</td>
57    <td>Billing API version is not supported for the type requested</td>
58  </tr>
59  <tr>
60    <td>{@code BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE}</td>
61    <td>4</td>
62    <td>Requested product is not available for purchase</td>
63  </tr>
64  <tr>
65    <td>{@code BILLING_RESPONSE_RESULT_DEVELOPER_ERROR}</td>
66    <td>5</td>
67    <td>Invalid arguments provided to the API. This error can also indicate that the application was not correctly signed or properly set up for In-app Billing in Google Play, or does not have the necessary permissions in its manifest</td>
68  </tr>
69  <tr>
70    <td>{@code BILLING_RESPONSE_RESULT_ERROR}</td>
71    <td>6</td>
72    <td>Fatal error during the API action</td>
73  </tr>
74  <tr>
75    <td>{@code BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED}</td>
76    <td>7</td>
77    <td>Failure to purchase since item is already owned</td>
78  </tr>
79  <tr>
80    <td>{@code BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED}</td>
81    <td>8</td>
82    <td>Failure to consume since item is not owned</td>
83  </tr>
84</table>
85
86<h2 id="billing-interface">API Reference</h2>
87<p>The In-app Billing Version 3 API is defined in the {@code IInAppBillingService.aidl} file, which is included with the Version 3 <a href="{@docRoot}training/in-app-billing/preparing-iab-app.html#GetSample">sample application</a>.</p>
88
89<h3 id="getSkuDetails">The getSkuDetails() method</h3>
90<p>This method returns product details for a list of product IDs. In the response {@code Bundle} sent by Google Play, the query results are stored in a String {@code ArrayList} mapped to the {@code DETAILS_LIST} key. Each String in the details list contains product details for a single product in JSON format. The fields in the JSON string with the product details are summarized in table 2.</p>
91
92<p class="table-caption" id="product-details-table">
93<strong>Table 2.</strong> Description of JSON fields with product item details returned from a {@code getSkuDetails} request.</p>
94<table>
95  <tr>
96    <th scope="col">Key</th>
97    <th scope="col">Description</th>
98  </tr>
99  <tr>
100    <td>{@code productId}</td>
101    <td>The product ID for the product.</td>
102  </tr>
103  <tr>
104    <td>{@code type}</td>
105    <td>Value must be “inapp” for an in-app purchase type.</td>
106  </tr>
107  <tr>
108    <td>{@code price}</td>
109    <td>Formatted price of the item, including its currency sign. The price does not include tax.</td>
110  </tr>
111  <tr>
112    <td>{@code title}</td>
113    <td>Title of the product.</td>
114  </tr>
115  <tr>
116    <td>{@code description}</td>
117    <td>Description of the product.</td>
118  </tr>
119</table>
120</p>
121
122<h3 id="getBuyIntent">The getBuyIntent() method</h3>
123<p>This method returns a response code integer mapped to the {@code RESPONSE_CODE} key, and a {@code PendingIntent} to launch the puchase flow for the in-app item mapped to the {@code BUY_INTENT} key. When it receives the {@code PendingIntent}, Google Play sends a response {@code Intent} with the data for that purchase order.  The data that is returned in the response {@code Intent} is summarized in table 3.</p>
124
125<p class="table-caption" id="purchase-pendingintent-response-table">
126<strong>Table 3.</strong>  Response data from an In-app Billing Version 3 purchase request.</p>
127<table>
128  <tr>
129    <th scope="col">Key</th>
130    <th scope="col">Description</th>
131  </tr>
132  <tr>
133    <td>{@code RESPONSE_CODE}</td>
134    <td>0 if the purchase was success, error otherwise.</td>
135  </tr>
136  <tr>
137    <td>{@code INAPP_PURCHASE_DATA}</td>
138    <td>
139       A String in JSON format that contains details about the purchase order. See table 4 for a description of the JSON fields.
140    </td>
141  </tr>
142  <tr>
143    <td>{@code INAPP_DATA_SIGNATURE}</td>
144    <td>String containing the signature of the purchase data that was signed with the private key of the developer.</td>
145  </tr>
146</table>
147</p>
148
149<p>Table 4 describes the JSON fields that are returned in the response data for a purchase order.</p>
150<p class="table-caption" id="purchase-data-table">
151<strong>Table 4.</strong>  Descriptions of the JSON fields for {@code INAPP_PURCHASE_DATA}.</p>
152<table>
153  <tr>
154    <th scope="col">Field</th>
155    <th scope="col">Description</th>
156  </tr>
157  <tr>
158    <td>{@code orderId}</td>
159    <td>A unique order identifier for the transaction. This corresponds to the Google Wallet Order ID.</td>
160  </tr>
161  <tr>
162    <td>{@code packageName}</td>
163    <td>The application package from which the purchase originated.</td>
164  </tr>
165  <tr>
166    <td>{@code productId}</td>
167    <td>The item's product identifier. Every item has a product ID, which you must specify in the application's product list on the Google Play publisher site.</td>
168  </tr>
169  <tr>
170    <td>{@code purchaseTime}</td>
171    <td>The time the product was purchased, in milliseconds since the epoch (Jan 1, 1970).</td>
172  </tr>
173  <tr>
174    <td>{@code purchaseState}</td>
175    <td>The purchase state of the order. Possible values are 0 (purchased), 1 (canceled), or 2 (refunded).</td>
176  </tr>
177  <tr>
178    <td>{@code developerPayload}</td>
179    <td>A developer-specified string that contains supplemental information about an order. You can specify a value for this field when you make a {@code getBuyIntent} request.</td>
180  </tr>
181  <tr>
182    <td>{@code purchaseToken}</td>
183    <td>A token that uniquely identifies a purchase for a given item and user pair. </td>
184  </tr>
185</table>
186</p>
187
188<h3 id="getPurchases">The getPurchases() method</h3>
189<p>This method returns the current un-consumed products owned by the user. Table 5 lists the response data that is returned in the {@code Bundle}.</p>
190<p class="table-caption" id="getpurchases-response-table">
191<strong>Table 5.</strong> Response data from a {@code getPurchases} request.</p>
192<table>
193  <tr>
194    <th scope="col">Key</th>
195    <th scope="col">Description</th>
196  </tr>
197  <tr>
198    <td>{@code RESPONSE_CODE}</td>
199    <td>0 if the request was successful, error otherwise.</td>
200  </tr>
201  <tr>
202    <td>{@code INAPP_PURCHASE_ITEM_LIST}</td>
203    <td>{@code StringArrayList} containing the list of productIds of purchases from this app.</td>
204  </tr>
205  <tr>
206    <td>{@code INAPP_PURCHASE_DATA_LIST}</td>
207    <td>{@code StringArrayList} containing the details for purchases from this app. See table 4 for the list of detail information stored in each {@code INAPP_PURCHASE_DATA} item in the list.</td>
208  </tr>
209  <tr>
210    <td>{@code INAPP_DATA_SIGNATURE_LIST}</td>
211    <td>{@code StringArrayList} containing the signatures of purchases from this app.</td>
212  </tr>
213  <tr>
214    <td>{@code INAPP_CONTINUATION_TOKEN}</td>
215    <td>String containing a continuation token to retrieve the next set of in-app products owned by the user. This is only set by the Google Play service if the number of products owned by the user is very large. When a continuation token is present in the response, you must make another call to {@code getPurchases} and pass in the continuation token that you received. The subsequent {@code getPurchases} call returns more purchases and possibly another continuation token.</td>
216  </tr>
217</table>
218</p>
219
220