summaryrefslogtreecommitdiffstats
path: root/docs/html/google/play/billing/billing_reference.jd
blob: da9178d27a00b5a8465340041d5b9f2ccd202f39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
page.title=In-app Billing Reference
parent.title=In-app Billing
parent.link=index.html
@jd:body

<div id="qv-wrapper">
<div id="qv">
  <h2>In this document</h2>
  <ol>
    <li><a href="#billing-codes">Server Response Codes</a></li>
    <li><a href="#billing-interface">API Reference</a>
    <ol>
      <li><a href="#getSkuDetails">getSkuDetails()</a></li>
      <li><a href="#getBuyIntent">getBuyIntent()</a></li>
      <li><a href="#getPurchases">getPurchases()</a></li>
    </ol>
    </li>
  </ol>
  <h2>Downloads</h2>
  <ol>
    <li><a href="{@docRoot}google/play/billing/billing_integrate.html#billing-download">Sample
    Application (V3)</a></li>
  </ol>
  <h2>See also</h2>
  <ol>
    <li><a href="{@docRoot}google/play/billing/api.html">In-app Billing Version 3</a></li>
    <li><a href="{@docRoot}training/in-app-billing/index.html">Selling In-app Products</a></li>
  </ol>
</div>
</div>
<p>This documentation provides technical reference information for using the In-app Billing Version 3 API. </p>

<h2 id="billing-codes">Server Response Codes</h2>
<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>

<p class="table-caption" id="response-codes-table">
<strong>Table 1.</strong> Summary of response codes for In-app Billing Version 3 API calls.</p>
<table>
  <tr>
    <th scope="col">Response Code</th>
    <th scope="col">Value</th>
    <th scope="col">Description</th>
  </tr>
  <tr>
    <td>{@code BILLING_RESPONSE_RESULT_OK}</td>
    <td>0</td>
    <td>Success</td>
  </tr>
  <tr>
    <td>{@code BILLING_RESPONSE_RESULT_USER_CANCELED}</td>
    <td>1</td>
    <td>User pressed back or canceled a dialog</td>
  </tr>
  <tr>
    <td>{@code BILLING_RESPONSE_RESULT_SERVICE_UNAVAILABLE}</td>
    <td>2</td>
    <td>Network connection is down</td>
  </tr>
  <tr>
    <td>{@code BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE}</td>
    <td>3</td>
    <td>Billing API version is not supported for the type requested</td>
  </tr>
  <tr>
    <td>{@code BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE}</td>
    <td>4</td>
    <td>Requested product is not available for purchase</td>
  </tr>
  <tr>
    <td>{@code BILLING_RESPONSE_RESULT_DEVELOPER_ERROR}</td>
    <td>5</td>
    <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>
  </tr>
  <tr>
    <td>{@code BILLING_RESPONSE_RESULT_ERROR}</td>
    <td>6</td>
    <td>Fatal error during the API action</td>
  </tr>
  <tr>
    <td>{@code BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED}</td>
    <td>7</td>
    <td>Failure to purchase since item is already owned</td>
  </tr>
  <tr>
    <td>{@code BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED}</td>
    <td>8</td>
    <td>Failure to consume since item is not owned</td>
  </tr>
</table>

<h2 id="billing-interface">API Reference</h2>
<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>

<h3 id="getSkuDetails">The getSkuDetails() method</h3>
<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>

<p class="table-caption" id="product-details-table">
<strong>Table 2.</strong> Description of JSON fields with product item details returned from a {@code getSkuDetails} request.</p>
<table>
  <tr>
    <th scope="col">Key</th>
    <th scope="col">Description</th>
  </tr>
  <tr>
    <td>{@code productId}</td>
    <td>The product ID for the product.</td>
  </tr>
  <tr>
    <td>{@code type}</td>
    <td>Value must be “inapp” for an in-app product or "subs" for
subscriptions.</td>
  </tr>
  <tr>
    <td>{@code price}</td>
    <td>Formatted price of the item, including its currency sign. The price
does not include tax.</td>
  </tr>
  <tr>
    <td>{@code price_amount_micros}</td>
    <td>Price in micro-units, where 1,000,000 micro-units equal one unit of the
    currency. For example, if {@code price} is {@code "€7.99"}, {@code
    price_amount_micros} is {@code "7990000"}.</td>
  </tr>
  <tr>
    <td>{@code price_currency_code}</td>
    <td><a href="http://en.wikipedia.org/wiki/ISO_4217#Active_codes">ISO 4217
    currency code</a> for {@code price}. For example, if {@code price} is
    specified in British pounds sterling, {@code price_currency_code} is {@code
    "GBP"}.</td>
  </tr>
  <tr>
    <td>{@code title}</td>
    <td>Title of the product.</td>
  </tr>
  <tr>
    <td>{@code description}</td>
    <td>Description of the product.</td>
  </tr>
</table>
</p>

<h3 id="getBuyIntent">The getBuyIntent() method</h3>
<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>

<p class="table-caption" id="purchase-pendingintent-response-table">
<strong>Table 3.</strong>  Response data from an In-app Billing Version 3 purchase request.</p>
<table>
  <tr>
    <th scope="col">Key</th>
    <th scope="col">Description</th>
  </tr>
  <tr>
    <td>{@code RESPONSE_CODE}</td>
    <td>0 if the purchase was success, error otherwise.</td>
  </tr>
  <tr>
    <td>{@code INAPP_PURCHASE_DATA}</td>
    <td>
       A String in JSON format that contains details about the purchase order. See table 4 for a description of the JSON fields.
    </td>
  </tr>
  <tr>
    <td>{@code INAPP_DATA_SIGNATURE}</td>
    <td>String containing the signature of the purchase data that was signed 
with the private key of the developer. The data signature uses the 
RSASSA-PKCS1-v1_5 scheme.</td>
  </tr>
</table>
</p>

<p>Table 4 describes the JSON fields that are returned in the response data for a purchase order.</p>
<p class="table-caption" id="purchase-data-table">
<strong>Table 4.</strong>  Descriptions of the JSON fields for {@code INAPP_PURCHASE_DATA}.</p>
<table>
  <tr>
    <th scope="col">Field</th>
    <th scope="col">Description</th>
  </tr>
  <tr>
    <td>{@code orderId}</td>
    <td>A unique order identifier for the transaction. This corresponds to the Google Wallet Order ID.</td>
  </tr>
  <tr>
    <td>{@code packageName}</td>
    <td>The application package from which the purchase originated.</td>
  </tr>
  <tr>
    <td>{@code productId}</td>
    <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 Developer Console.</td>
  </tr>
  <tr>
    <td>{@code purchaseTime}</td>
    <td>The time the product was purchased, in milliseconds since the epoch (Jan 1, 1970).</td>
  </tr>
  <tr>
    <td>{@code purchaseState}</td>
    <td>The purchase state of the order. Possible values are 0 (purchased), 1 (canceled), or 2 (refunded).</td>
  </tr>
  <tr>
    <td>{@code developerPayload}</td>
    <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>
  </tr>
  <tr>
    <td>{@code purchaseToken}</td>
    <td>A token that uniquely identifies a purchase for a given item and user
    pair. This token may be up to 1,000 characters long.
    Pass this entire token to other methods, such as when you consume the
    purchase (as described in
<a href="{@docRoot}training/in-app-billing/purchase-iab-products.html#Consume">Consume
    a Purchase</a>). Do not abbreviate or truncate this token.</td>
  </tr>
</table>
</p>

<h3 id="getPurchases">The getPurchases() method</h3>
<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>
<p class="table-caption" id="getpurchases-response-table">
<strong>Table 5.</strong> Response data from a {@code getPurchases} request.</p>
<table>
  <tr>
    <th scope="col">Key</th>
    <th scope="col">Description</th>
  </tr>
  <tr>
    <td>{@code RESPONSE_CODE}</td>
    <td>0 if the request was successful, error otherwise.</td>
  </tr>
  <tr>
    <td>{@code INAPP_PURCHASE_ITEM_LIST}</td>
    <td>{@code StringArrayList} containing the list of productIds of purchases from this app.</td>
  </tr>
  <tr>
    <td>{@code INAPP_PURCHASE_DATA_LIST}</td>
    <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>
  </tr>
  <tr>
    <td>{@code INAPP_DATA_SIGNATURE_LIST}</td>
    <td>{@code StringArrayList} containing the signatures of purchases from this app.</td>
  </tr>
  <tr>
    <td>{@code INAPP_CONTINUATION_TOKEN}</td>
    <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>
  </tr>
</table>
</p>